use super::fixture::{crowd, world_crowded};
use super::screen::{Screen, click, locate, rects_of};
use crate::delete::agent::Census;
use crate::keymap::CenterTab;
const ARMING: &str = "Armingrow";
const DESCENDANTS: usize = 120;
fn on_glass(out: &egui::FullOutput, size: (f32, f32), head: &str) -> Vec<egui::Rect> {
let (w, h) = size;
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(w, h));
crate::paint_probe::seen_of(out)
.into_iter()
.filter(|seen| seen.text.starts_with(head))
.map(|seen| seen.shown.intersect(screen))
.filter(|rect| rect.width() > 0.5 && rect.height() > 0.5)
.collect()
}
fn seated(screen: &Screen, world: &mut super::fixture::World) -> egui::FullOutput {
screen.idle(world);
screen.output(world, Vec::new())
}
#[test]
fn the_navigator_keeps_its_doors_on_the_glass_under_a_tall_list() {
let mut report = Vec::new();
for size in super::SIZES {
let (w, h) = size;
let mut world = world_crowded();
let screen = Screen::sized(w, h);
let out = seated(&screen, &mut world);
let column = screen.column();
let names = crowd::names();
let rows = names
.iter()
.filter(|name| !on_glass(&out, size, name).is_empty())
.count();
if rows == 0 || rows == names.len() {
report.push(format!(
"at {w:.0}x{h:.0} the column showed {rows} of {} crowd rows — it \
must show some and not all, or nothing here is being tested",
names.len()
));
}
for door in ["⚙ Config", "Login"] {
let seated = on_glass(&out, size, door)
.into_iter()
.any(|rect| rect.right() <= column + 1.0);
if !seated {
report.push(format!(
"at {w:.0}x{h:.0} the navigator's `{door}` reached no pixel of the column"
));
}
}
}
assert!(report.is_empty(), "{}", report.join("\n"));
}
#[test]
fn the_config_entry_still_clicks_when_the_list_outgrows_the_column() {
let mut world = world_crowded();
let screen = Screen::sized(800.0, 500.0);
screen.idle(&mut world);
screen.release(&mut world);
let shapes = screen.shapes(&mut world, Vec::new());
let names = crowd::names();
let shown = names
.iter()
.filter(|name| !rects_of(&shapes, name).is_empty())
.count();
assert!(shown > 0, "the crowded roster paints rows at all");
assert!(
shown < names.len(),
"the fixture must really outgrow the column, or this beat asserts \
nothing: {shown} of {} rows are on the glass",
names.len()
);
let seat = locate(&shapes, "⚙ Config")
.expect("the Config entry reaches the paint layer under a tall list");
click(&screen, &mut world, seat);
assert_eq!(
world.state.center,
CenterTab::Config,
"the coordinate really is the Config entry"
);
}
#[test]
fn the_workspace_delete_dialog_keeps_its_arming_row_on_the_glass() {
let mut report = Vec::new();
for size in super::SIZES {
let (w, h) = size;
let mut world = world_crowded();
let screen = Screen::sized(w, h);
screen.idle(&mut world);
super::super::delete::open(&world.model, &mut world.state, crowd::WALL);
world.state.delete.typed = ARMING.to_owned();
let out = seated(&screen, &mut world);
assert!(
world.state.delete.target.is_some(),
"the dialog stands on a named wall at {w:.0}x{h:.0} — a foreign one \
closes on the frame it opens and would prove nothing"
);
for seat in [ARMING, "Delete workspace"] {
if on_glass(&out, size, seat).is_empty() {
report.push(format!(
"at {w:.0}x{h:.0} the workspace dialog's `{seat}` reached no pixel"
));
}
}
}
assert!(report.is_empty(), "{}", report.join("\n"));
}
#[test]
fn the_conversation_delete_dialog_keeps_its_fire_button_on_the_glass() {
let mut report = Vec::new();
for size in super::SIZES {
let (w, h) = size;
let mut world = world_crowded();
let ws = world.ws.clone();
let screen = Screen::sized(w, h);
screen.idle(&mut world);
world.state.delete_agent = super::super::delete_agent::DeleteAgentState {
target: Some((ws, "c-1".to_owned())),
census: Some(Census {
descendants: (0..DESCENDANTS).map(|n| format!("c-1-{n:04}-x")).collect(),
pending_deposits: 7,
}),
typed: ARMING.to_owned(),
..super::super::delete_agent::DeleteAgentState::default()
};
let out = seated(&screen, &mut world);
assert!(
world.state.delete_agent.target.is_some(),
"the dialog stands at {w:.0}x{h:.0}"
);
for seat in [ARMING, "Delete conversation"] {
if on_glass(&out, size, seat).is_empty() {
report.push(format!(
"at {w:.0}x{h:.0} the conversation dialog's `{seat}` reached no pixel"
));
}
}
}
assert!(report.is_empty(), "{}", report.join("\n"));
}