use super::fixture::{World, world};
use super::screen::{Screen, click, locate, press};
use crate::keymap::CenterTab;
#[test]
fn escape_dismisses_the_new_workspace_form_and_mints_nothing() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
let before = spheres(&world);
screen.frame(&mut world, vec![press(egui::Key::W, egui::Modifiers::NONE)]);
assert!(world.state.new_ws.open, "bare `w` opens the §11 name form");
world.state.new_ws.typed = "ops".to_owned();
assert!(
screen.frame(
&mut world,
vec![press(egui::Key::Escape, egui::Modifiers::NONE)]
),
"the dismissing frame hands the keyboard straight back to the composer: \
the keys are lifted before any panel paints, so unlike the window's \
own close button there is no frame in between"
);
assert!(!world.state.new_ws.open, "one Escape closes it");
assert!(
world.state.new_ws.typed.is_empty(),
"and the draft dies with it"
);
assert_eq!(spheres(&world), before, "no sphere wall was raised");
assert!(screen.idle(&mut world), "and the keyboard stays in the box");
}
#[test]
fn a_click_beneath_the_open_form_reaches_nothing() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
let seat = locate(&screen.shapes(&mut world, Vec::new()), "⚙ Config")
.expect("the Config entry reaches the paint layer");
click(&screen, &mut world, seat);
assert_eq!(
world.state.center,
CenterTab::Config,
"the coordinate really is the Config entry"
);
let home = locate(&screen.shapes(&mut world, Vec::new()), "Conversation")
.expect("the center strip's home tab reaches the paint layer");
click(&screen, &mut world, home);
assert_eq!(
world.state.center,
CenterTab::Conversation,
"and the strip is the way back — a tab focus is left by focusing another"
);
screen.frame(&mut world, vec![press(egui::Key::W, egui::Modifiers::NONE)]);
assert!(world.state.new_ws.open, "the form is up");
click(&screen, &mut world, seat);
assert_eq!(
world.state.center,
CenterTab::Conversation,
"the click must not reach the panel beneath the modal"
);
assert!(
world.state.new_ws.open,
"and the form is still standing — the backdrop swallowed the click \
rather than being hoisted above the dialog it sits under"
);
}
#[test]
fn return_submits_a_valid_name_and_a_refused_one_keeps_the_form() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
screen.frame(&mut world, vec![press(egui::Key::W, egui::Modifiers::NONE)]);
world.state.new_ws.typed = "Not A Sphere".to_owned();
screen.frame(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::NONE)],
);
assert!(world.state.new_ws.open, "a refused Enter keeps the form up");
assert_eq!(
world.state.new_ws.typed, "Not A Sphere",
"with what was typed still in it"
);
world.converge();
assert!(
world
.model
.last_failure(crate::opslog::Origin::Conversation)
.is_none(),
"and nothing was dispatched"
);
world.state.new_ws.typed = "ops".to_owned();
screen.frame(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::NONE)],
);
assert!(
!world.state.new_ws.open,
"Enter submits and closes the form"
);
world.converge();
let raise = world
.model
.last_failure(crate::opslog::Origin::Conversation)
.expect("Enter reached the §8.1 planner");
assert!(
raise.argv.ends_with(" prime"),
"the raise begins at the world seed: {}",
raise.argv
);
}
fn spheres(world: &World) -> Vec<std::ffi::OsString> {
let root = world.ws.parent().expect("the workspaces root");
let mut names: Vec<std::ffi::OsString> = std::fs::read_dir(root)
.expect("the workspaces root is readable")
.map(|e| e.expect("a directory entry").file_name())
.collect();
names.sort();
names
}