use super::{stocked, typed};
use crate::test_support::window::painted;
use crate::ui::{Aim, Model, Stand};
fn engine(name: &str) -> Stand {
Stand::Engine(name.to_owned())
}
fn begins() -> [Option<Stand>; 2] {
let own = "(this box's own engine)".to_owned();
let home = Aim {
channel: own.clone(),
address: "home".to_owned(),
};
[Some(Stand::Begin(home)), Some(Stand::Found(own))]
}
#[test]
fn the_arrows_walk_the_engine_rows_and_the_open_engine_s_walls() {
let mut model = Model {
aim: None,
switching: true,
..stocked()
};
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing,
Some(engine("(this box's own engine)")),
"a list nobody has entered opens at its first row, which is an engine"
);
assert_eq!(model.aim, None, "and standing there selects nothing");
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.aim.as_ref().map(|aim| aim.address.clone()),
Some("home".to_owned()),
"the open engine's wall is the next stop, and landing on it aims it"
);
assert_eq!(model.standing, None, "an aim is where the cursor is");
for begin in begins() {
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(model.standing, begin, "the begins stand last under it");
}
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing,
Some(engine("elsewhere")),
"and the closed engine's own row is next, never its walls"
);
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing,
Some(engine("elsewhere")),
"the end saturates rather than wrapping"
);
typed(&mut model, &[egui::Key::ArrowUp, egui::Key::ArrowUp]);
assert_eq!(model.standing, begins()[0]);
}
#[test]
fn enter_on_the_row_the_walk_stands_on_opens_that_engine() {
let mut model = Model {
aim: None,
switching: true,
..stocked()
};
typed(
&mut model,
&[
egui::Key::ArrowDown,
egui::Key::ArrowDown,
egui::Key::ArrowDown,
egui::Key::ArrowDown,
egui::Key::ArrowDown,
egui::Key::Enter,
],
);
assert_eq!(model.engines.open.as_deref(), Some("elsewhere"));
assert_eq!(
model.aim.as_ref().map(|aim| aim.address.clone()),
Some("elsewhere".to_owned()),
"opening aims the engine's first addressable wall"
);
}
#[test]
fn the_walk_runs_on_through_the_aimed_wall_s_conversations() {
let mut model = Model {
conversation: None,
switching: true,
..stocked()
};
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(model.conversation.as_deref(), Some("a"));
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(model.conversation.as_deref(), Some("b"));
for begin in begins() {
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(model.standing, begin);
}
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(model.standing, Some(engine("elsewhere")));
assert_eq!(
model.conversation.as_deref(),
Some("b"),
"standing on an engine selects nothing"
);
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing,
Some(engine("elsewhere")),
"the end saturates rather than wrapping"
);
}
#[test]
fn the_arrows_walk_the_started_conversation_s_row_like_any_other() {
let mut model = Model {
conversation: Some("brisk-otter".to_owned()),
start: Some(crate::ui::model::Start {
address: "home".to_owned(),
goal: "port it".to_owned(),
phase: crate::ui::model::Phase::Started("brisk-otter".to_owned()),
spread: None,
}),
switching: true,
..stocked()
};
let shown = painted(&mut model);
assert!(shown.contains("brisk-otter"), "{shown}");
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.conversation.as_deref(),
Some("a"),
"one step down out of the pending row and into the list"
);
}
#[test]
fn enter_on_a_begin_the_walk_stands_on_fires_it() {
let at = |n: usize| {
let mut model = Model {
conversation: None,
switching: true,
..stocked()
};
typed(&mut model, &vec![egui::Key::ArrowDown; n + 2]);
assert_eq!(model.standing, begins()[n - 1]);
let shown = typed(&mut model, &[egui::Key::Enter]);
assert!(!model.switching, "the begin closes the switcher");
(model, shown)
};
let (begun, shown) = at(1);
assert_eq!(begun.conversation, None, "a start is no conversation");
assert_eq!(begun.standing, None, "an aim is where the cursor is");
assert!(shown.contains("home"), "{shown}");
let (founding, shown) = at(2);
assert_eq!(
founding.founding.as_deref(),
Some("(this box's own engine)")
);
assert_eq!(founding.standing, None);
assert!(shown.contains(crate::ui::composer::found::HINT), "{shown}");
}