use super::super::fixture::{World, world};
use super::super::screen::{Screen, press};
use crate::keymap::{CenterTab, InspectorTab};
use std::collections::HashSet;
const LAP: usize = 200;
struct Control {
seat: egui::Rect,
label: String,
said_something: bool,
}
fn is_a_surface(response: &egui::Response) -> bool {
response.id == response.layer_id.id.with("move")
}
fn controls(screen: &Screen, world: &mut World) -> Vec<(egui::Id, Control)> {
let mut walked = Vec::new();
let mut visited = HashSet::new();
for _ in 0..LAP {
screen.frame(world, vec![press(egui::Key::Tab, egui::Modifiers::NONE)]);
let Some(id) = screen.focused() else {
continue;
};
if !visited.insert(id) {
break;
}
let response = screen
.response(id)
.expect("the widget the cursor is on is a widget of this frame");
if response.sense.click && !is_a_surface(&response) {
walked.push((id, response.rect, screen.tooltipped(id)));
}
}
let mut painted = Vec::new();
for clipped in screen.shapes(world, Vec::new()) {
crate::paint_probe::collect(&clipped.shape, &mut painted);
}
walked
.into_iter()
.map(|(id, seat, said_something)| {
let label = painted
.iter()
.filter(|(_, at)| seat.contains_rect(*at))
.map(|(text, _)| text.as_str())
.collect::<Vec<_>>()
.join(" ");
(
id,
Control {
seat,
label,
said_something,
},
)
})
.collect()
}
fn sweep(
screen: &Screen,
world: &mut World,
judged: &mut HashSet<egui::Id>,
mute: &mut Vec<String>,
) {
screen.idle(world);
for (id, control) in controls(screen, world) {
if judged.insert(id) && !control.said_something {
mute.push(format!("{:?} at {:?}", control.label, control.seat));
}
}
}
#[test]
fn every_click_sensing_control_the_window_paints_says_what_it_does() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
world.state.activity_open = true;
let screen = Screen::new();
screen.idle(&mut world);
screen.reveal();
let (mut judged, mut mute) = (HashSet::new(), Vec::new());
for tab in CenterTab::all() {
world.state.center = tab;
sweep(&screen, &mut world, &mut judged, &mut mute);
}
world.state.center = CenterTab::Conversation;
for tab in InspectorTab::all() {
world.model.select_tab(tab);
sweep(&screen, &mut world, &mut judged, &mut mute);
}
assert!(
judged.len() > 50,
"the drive reached {} controls — a walk that stopped walking proves \
nothing, the same two-direction discipline the source scan keeps",
judged.len()
);
assert!(
mute.is_empty(),
"these controls sense a click and say nothing on hover — §11 requires \
every one of them to state what pressing it does:\n{}",
mute.join("\n")
);
}