use super::{stocked, typed};
use crate::test_support::window::{painted, seated};
use crate::ui::Model;
#[test]
fn sideways_does_nothing_while_both_columns_are_on_the_glass() {
let mut model = stocked();
let was = model.column;
typed(
&mut model,
&[
egui::Key::ArrowLeft,
egui::Key::ArrowRight,
egui::Key::ArrowLeft,
],
);
assert_eq!(model.column, was, "the column is the narrow shape's own");
assert_eq!(
model.conversation.as_deref(),
seated().conversation.as_deref(),
"and nothing was selected by a key that names no place"
);
}
#[test]
fn the_arrows_walk_the_engine_rows_and_the_open_engine_s_walls() {
let mut model = Model {
aim: None,
..stocked()
};
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing.as_deref(),
Some("(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");
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing.as_deref(),
Some("elsewhere"),
"and the closed engine's own row is next, never its walls"
);
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing.as_deref(),
Some("elsewhere"),
"the end saturates rather than wrapping"
);
typed(&mut model, &[egui::Key::ArrowUp]);
assert_eq!(
model.aim.as_ref().map(|aim| aim.address.clone()),
Some("home".to_owned())
);
}
#[test]
fn enter_on_the_row_the_walk_stands_on_opens_that_engine() {
let mut model = Model {
aim: None,
..stocked()
};
typed(
&mut model,
&[
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,
..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"));
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(model.standing.as_deref(), Some("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.as_deref(),
Some("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,
}),
..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"
);
}