use super::fixtures::{file, opened};
use super::{CLOSE, HEADING, KEPT};
use crate::paint_probe::frame::{Window, press};
use crate::test_support::window::seated;
use crate::ui::composer::start::{GOAL, START};
use crate::ui::{Aim, Model};
#[test]
fn escape_closes_the_enrollment_and_forgets_the_material() {
let mut model = opened();
file(&mut model);
let window = Window::new();
let mut body = |ctx: &egui::Context| crate::ui::render(ctx, &mut model);
assert!(
window.text(&mut body).contains(KEPT),
"the symbol is on the glass to begin with"
);
window.frame(vec![press(egui::Key::Escape)], &mut body);
let after = window.text(&mut body);
assert_eq!(model.enroll, None, "the material is gone with the pane");
assert!(!after.contains(KEPT), "{after}");
assert!(
!after.lines().any(|line| line == HEADING),
"the pane itself is off the glass — the roster's own `enroll a box…` control is not it:
{after}"
);
}
#[test]
fn escape_with_no_enrollment_is_still_the_notice_s_dismiss() {
let mut model = Model {
notice: Some(crate::ui::Notice::Refused("no".to_owned())),
..seated()
};
let window = Window::new();
window.frame(vec![press(egui::Key::Escape)], |ctx| {
crate::ui::render(ctx, &mut model);
});
assert_eq!(model.notice, None);
}
#[test]
fn the_arrows_walk_nothing_while_the_enrollment_stands() {
let mut model = opened();
let aimed = model.aim.clone();
let window = Window::new();
window.frame(vec![press(egui::Key::ArrowDown)], |ctx| {
crate::ui::render(ctx, &mut model);
});
assert_eq!(model.aim, aimed, "the roster was walked under the material");
assert!(model.enroll.is_some());
}
#[test]
fn the_composer_stands_down_while_an_enrollment_is_open() {
let mut aimed = Model {
aim: Some(Aim {
channel: "(this box's own engine)".to_owned(),
address: "home".to_owned(),
}),
conversation: None,
..seated()
};
let window = Window::new();
let warm = |model: &mut Model| {
window.text(|ctx| crate::ui::render(ctx, model));
window.text(|ctx| crate::ui::render(ctx, model))
};
let before = warm(&mut aimed);
for control in [START, GOAL] {
assert!(
before.contains(control),
"{control:?} is there to lose:\n{before}"
);
}
aimed.begin_enrollment();
let during = warm(&mut aimed);
for control in [START, GOAL] {
assert!(
!during.contains(control),
"{control:?} is live under the material:\n{during}"
);
}
assert!(
during.contains(CLOSE),
"the pane's own controls still stand:\n{during}"
);
}