use crate::paint_probe::frame::{Window, press};
use crate::test_support::window::{seated, wall};
use crate::ui::{Chunk, Model};
fn ringed(model: &mut Model, keys: &[egui::Key]) -> (Vec<egui::Rect>, String) {
let window = Window::new();
let mut body = |ctx: &egui::Context| crate::ui::render(ctx, model);
window.frame(Vec::new(), &mut body);
for key in keys {
window.frame(vec![press(*key)], &mut body);
}
let output = window.frame(Vec::new(), &mut body);
let rings = crate::paint_probe::strokes_of(&output)
.into_iter()
.filter(|(_, ink)| *ink == crate::ui::theme::BRAND)
.map(|(rect, _)| rect)
.collect();
(rings, crate::paint_probe::text_of(&output))
}
#[test]
fn the_first_tab_rings_one_thing_and_nothing_is_ringed_at_rest() {
let mut model = seated();
let (rings, _) = ringed(&mut model, &[]);
assert!(
rings.is_empty(),
"nothing holds the keyboard at rest: {rings:?}"
);
let (rings, _) = ringed(&mut model, &[egui::Key::Tab]);
assert_eq!(rings.len(), 1, "one thing holds the keyboard: {rings:?}");
}
fn two_walls() -> Model {
Model {
roster: vec![Chunk {
walls: vec![wall("first"), wall("second")],
..crate::test_support::window::own()
}],
..seated()
}
}
#[test]
fn a_tab_reaches_a_wall_s_row_and_space_on_it_aims() {
let mut model = two_walls();
let (rings, _) = ringed(&mut model, &[egui::Key::Tab; 9]);
assert_eq!(rings.len(), 1, "{rings:?}");
let window = Window::new();
let mut body = |ctx: &egui::Context| crate::ui::render(ctx, &mut model);
window.frame(Vec::new(), &mut body);
for _ in 0..9 {
window.frame(vec![press(egui::Key::Tab)], &mut body);
}
window.frame(vec![press(egui::Key::Space)], &mut body);
window.frame(Vec::new(), &mut body);
assert_eq!(
model.aim.as_ref().map(|aim| aim.address.as_str()),
Some("first"),
"Space on the ringed row aims it"
);
}
#[test]
fn a_tab_reaches_the_plus_and_space_on_it_begins_a_conversation() {
let mut model = two_walls();
model.standing = Some("a name no engine here has".to_owned());
let window = Window::new();
let mut body = |ctx: &egui::Context| crate::ui::render(ctx, &mut model);
window.frame(Vec::new(), &mut body);
for _ in 0..8 {
window.frame(vec![press(egui::Key::Tab)], &mut body);
}
window.frame(vec![press(egui::Key::Space)], &mut body);
window.frame(Vec::new(), &mut body);
assert_eq!(model.conversation, None, "the selection is cleared");
assert_eq!(
window.focused(),
Some(egui::Id::new(crate::ui::keys::BOX_ID)),
"and the caret is in the box that begins one"
);
}