use super::{stocked, typed};
use crate::test_support::window::painted;
use crate::ui::{Aim, Model, Stand};
fn server(name: &str) -> Stand {
Stand::Server(name.to_owned())
}
fn begins() -> [Option<Stand>; 2] {
let own = "(this box's own server)".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_server_rows_and_the_open_server_s_workspaces() {
let mut model = Model {
aim: None,
switching: true,
..stocked()
};
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing,
Some(server("(this box's own server)")),
"a list nobody has entered opens at its first row, which is a server"
);
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 server's workspace 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(server("elsewhere")),
"and the closed server's own row is next, never its workspaces"
);
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing,
Some(server("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_server() {
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.servers.open.as_deref(), Some("elsewhere"));
assert_eq!(
model.aim.as_ref().map(|aim| aim.address.clone()),
Some("elsewhere".to_owned()),
"opening aims the server's first addressable workspace"
);
}
#[test]
fn the_walk_runs_on_through_the_aimed_workspace_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(server("elsewhere")));
assert_eq!(
model.conversation.as_deref(),
Some("b"),
"standing on a server selects nothing"
);
typed(&mut model, &[egui::Key::ArrowDown]);
assert_eq!(
model.standing,
Some(server("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 server)")
);
assert_eq!(founding.standing, None);
assert!(shown.contains(crate::ui::composer::found::HINT), "{shown}");
}