use super::super::screen::Screen;
use super::drive::{band, column, seat, visible};
const LEAF_FLAGGED: &str = "c-1-20260803T045801Z-3c7d55e6";
const LEAF_QUIET: &str = "c-1-20260803T045802Z-4d8e66f7";
#[test]
fn one_depths_titles_share_an_edge_across_attention_and_clear_their_metadata() {
let mut world = super::nested_world();
world.add_child("c-1", LEAF_FLAGGED);
world.add_child("c-1", LEAF_QUIET);
world.quiet(LEAF_QUIET);
let ws = world.ws.clone();
world.model.mark_dirty([ws]);
world.converge();
world.state.expanded.insert("c-1".to_owned());
let rows = visible(&world);
let row = |id: &str| {
rows.iter()
.find(|r| r.root_id == id)
.unwrap_or_else(|| panic!("{id} is a row of this list: {rows:?}"))
};
assert!(
row(LEAF_FLAGGED).attention > 0 && row(LEAF_QUIET).attention == 0,
"the two leaves must differ in attention, one each way: {rows:?}"
);
let screen = Screen::new();
let painted = column(&screen, &mut world);
let root = seat(&painted, "hello").left();
let depth1: Vec<(String, egui::Rect)> = rows
.iter()
.filter(|r| r.depth == 1)
.map(|r| (r.display_name(), seat(&painted, &r.display_name())))
.collect();
assert_eq!(
depth1.len(),
3,
"three direct children reach the list: {rows:?}"
);
let edge = depth1.first().map_or(0.0, |(_, r)| r.left());
assert!(
edge > root + 1.0,
"a child's title edge is its own, right of the root's: {edge} vs {root}"
);
for (name, rect) in &depth1 {
assert!(
(rect.left() - edge).abs() < 0.5,
"the title edge is the depth's, not attention's: {name} sits at {} not {edge}",
rect.left()
);
for (other, r) in band(&painted, *rect) {
assert!(
r == *rect || r.right() <= rect.left() + 0.5 || r.left() >= rect.right() - 0.5,
"{other:?} at {r:?} overlaps the title {name} at {rect:?}"
);
}
}
let flagged = seat(&painted, &row(LEAF_FLAGGED).display_name());
let quiet = seat(&painted, &row(LEAF_QUIET).display_name());
let flag = band(&painted, flagged)
.into_iter()
.find(|(text, _)| text == "⚑")
.unwrap_or_else(|| panic!("the flagged leaf paints its ⚑ at {flagged:?}"));
assert!(
flag.1.left() > edge,
"the flag rides the trailing group, right of every title: {:?}",
flag.1
);
assert!(
!band(&painted, quiet).iter().any(|(text, _)| text == "⚑"),
"and the abandoned leaf paints none at all"
);
}