use super::fixture::{World, world};
use super::screen::{Screen, press};
const SECOND: &str = "c-2";
fn walked_world() -> (World, Screen) {
let mut world = world();
std::fs::write(
world.model.state_root().join("cadence.yaml"),
"cadence:\n watcher:\n debounce_ms: 0\n",
)
.unwrap();
world.model.after_lernie_verb();
world.converge();
world.add_root(SECOND, "second-root");
let ws = world.ws.clone();
world.model.mark_dirty([ws]);
world.converge();
let screen = Screen::new();
screen.idle(&mut world);
(world, screen)
}
fn selected(world: &World) -> String {
world
.model
.focused_agent()
.map_or_else(|| "-".to_owned(), |a| a.agent_id.clone())
}
#[test]
fn a_roster_step_lands_the_composer_in_both_directions() {
for arrow in [egui::Key::ArrowDown, egui::Key::ArrowUp] {
let (mut world, screen) = walked_world();
screen.release(&mut world);
assert_eq!(
selected(&world),
"-",
"the walk starts with nothing selected"
);
assert!(
screen.frame(&mut world, vec![press(arrow, egui::Modifiers::NONE)]),
"{arrow:?} selected an agent, so the composer took the keyboard"
);
assert_ne!(selected(&world), "-", "and the step really did select one");
}
}
#[test]
fn the_walk_continues_on_the_combo_plane() {
let (mut world, screen) = walked_world();
screen.release(&mut world);
screen.frame(
&mut world,
vec![press(egui::Key::ArrowDown, egui::Modifiers::NONE)],
);
let first = selected(&world);
assert!(
screen.frame(
&mut world,
vec![press(egui::Key::ArrowDown, egui::Modifiers::NONE)]
),
"the box still holds the keyboard"
);
assert_eq!(
selected(&world),
first,
"a second bare ↓ is suppressed — the step spent its own plane"
);
assert!(
screen.frame(
&mut world,
vec![press(egui::Key::ArrowDown, egui::Modifiers::COMMAND)]
),
"and Ctrl+↓ leaves the keyboard where the next message gets typed"
);
assert_ne!(selected(&world), first, "having stepped the walk on");
}
#[test]
fn escape_still_releases_a_keyboard_selection_and_the_bare_plane_is_live() {
let (mut world, screen) = walked_world();
screen.release(&mut world);
screen.frame(
&mut world,
vec![press(egui::Key::ArrowDown, egui::Modifiers::NONE)],
);
let first = selected(&world);
screen.release(&mut world);
assert!(
!screen.idle(&mut world),
"and the release holds — nothing re-grabs the box a frame later"
);
assert!(
screen.frame(
&mut world,
vec![press(egui::Key::ArrowDown, egui::Modifiers::NONE)]
),
"the bare plane is live again, and its step lands the composer as before"
);
assert_ne!(selected(&world), first, "the bare ↓ stepped the walk");
}