use concinnity_core::ecs::World;
use crate::editor::behavior::panel::Status;
use crate::editor::hook::tests::fixtures::hook;
use crate::editor::notify;
use crate::editor::panels::registry::PanelKey;
use crate::editor::toast_overlay;
#[test]
fn toast_presses_claim_cards_and_fall_through_elsewhere() {
let mut h = hook(Vec::new());
let vp = [1280.0, 720.0];
let mut world = World::new();
assert!(!h.try_toast_press(vp[0] - 20.0, vp[1] - 20.0, vp, &mut world));
h.notifier
.error_with("cook failed", notify::Action::OpenConsole);
h.drive_toasts(&mut world, vp, true, [0.0, 0.0]);
assert!(!h.toasts_hidden, "a live toast draws");
let card_id = toast_overlay::ids().sprites[0];
assert!(h.compute_layers().contains_key(&card_id));
assert!(!h.try_toast_press(10.0, 10.0, vp, &mut world));
let r = toast_overlay::card_rect(vp, 0, 0);
assert!(h.try_toast_press(r[0] + 5.0, r[1] + 5.0, vp, &mut world));
assert!(
h.open[PanelKey::Console],
"the error's action opened the Console"
);
assert!(h.notifier.is_empty(), "the card dismissed");
}
#[test]
fn toast_drive_settles_hidden_when_the_queue_empties() {
let mut h = hook(Vec::new());
let vp = [1280.0, 720.0];
let mut world = World::new();
h.notifier.success("saved");
h.drive_toasts(&mut world, vp, true, [0.0, 0.0]);
assert!(!h.toasts_hidden);
h.notifier.click_card(0);
h.drive_toasts(&mut world, vp, true, [0.0, 0.0]);
assert!(h.toasts_hidden, "one hide pass after the stack empties");
let card_id = toast_overlay::ids().sprites[0];
assert!(!h.compute_layers().contains_key(&card_id));
}
#[test]
fn behavior_fault_toasts_only_on_a_new_fault() {
let mut h = hook(Vec::new());
h.behavior.status = Some(Status::message("a behavior needs a name"));
h.notify_behavior_fault(None);
assert!(!h.notifier.is_empty(), "a fresh fault toasts");
h.notifier.click_card(0);
let prev = h.behavior_fault_message();
h.notify_behavior_fault(prev);
assert!(h.notifier.is_empty(), "the same fault stays quiet");
h.notify_behavior_fault(Some("a different complaint".to_string()));
assert!(!h.notifier.is_empty(), "a changed fault toasts again");
}