use super::super::{HERE, Pane};
use crate::paint_probe::frame::{Window, press};
use crate::test_support::window::{seated, wall};
use crate::ui::{Chunk, Model, roster};
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:?}");
}
#[test]
fn a_tab_onto_a_wall_hands_the_arrows_to_the_roster_and_space_aims() {
let mut model = Model {
roster: vec![Chunk {
walls: vec![wall("first"), wall("second")],
..crate::test_support::window::own()
}],
focus: Pane::Conversations,
..seated()
};
let tabs = [egui::Key::Tab; 7];
let (rings, painted) = ringed(&mut model, &tabs);
assert_eq!(model.focus, Pane::Roster, "the arrows followed the Tab");
assert!(
painted
.lines()
.any(|line| line == format!("{HERE} {}", roster::HEADING)),
"the mark moved with it:\n{painted}"
);
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..7 {
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_onto_a_conversation_hands_the_arrows_to_the_list() {
let mut model = Model {
focus: Pane::Roster,
..seated()
};
let window = Window::new();
let mut landed = false;
for _ in 0..40 {
window.frame(vec![press(egui::Key::Tab)], |ctx| {
crate::ui::render(ctx, &mut model);
});
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, &mut model));
if model.focus == Pane::Conversations {
landed = true;
break;
}
}
assert!(landed, "a Tab reaches the conversation list");
}