From e4506377bae55e7944b5e67700ee97c61fadcfd7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 15:49:02 -0800 Subject: [PATCH] Main: the resting-card test checks only the New Document dialog's cards resting_preset_cards_stand_on_a_tile took the first unselected list item in the frame's access tree. That tree also holds the Home screen's document cards behind the dialog, which lie flat by design, and the update lists nodes in hash-map order, which changes from process to process. When a Home card came first the test failed, so it failed on some runs of the full workspace and passed alone. The test now walks the dialog node's subtree and checks every unselected card in it, so the result no longer depends on node order. --- crates/ui-egui/src/dialogs/new_document.rs | 34 +++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index c20582141e..db83163e57 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -1127,21 +1127,35 @@ mod tests { open(&mut app); let out = laid_out(&mut app); let nodes = out.platform_output.accesskit_update.as_ref().map(|u| u.nodes.clone()).unwrap_or_default(); - let card = nodes + // The Home screen's own document cards stand behind the dialog, and the update lists nodes in no fixed order: + // the card is looked for under the dialog only. + let by_id: std::collections::HashMap<_, _> = nodes.iter().map(|(id, n)| (*id, n)).collect(); + let mut in_dialog = Vec::new(); + let mut stack: Vec<_> = nodes.iter().filter(|(_, n)| n.role() == egui::accesskit::Role::Dialog).map(|(id, _)| *id).collect(); + while let Some(id) = stack.pop() { + if let Some(node) = by_id.get(&id) { + in_dialog.push(*node); + stack.extend(node.children().iter().copied()); + } + } + let cards: Vec<_> = in_dialog .iter() - .find(|(_, n)| n.role() == egui::accesskit::Role::ListItem && n.label().is_some_and(|l| !l.is_empty()) && n.is_selected() == Some(false)) - .and_then(|(_, n)| n.bounds()) + .filter(|n| n.role() == egui::accesskit::Role::ListItem && n.label().is_some_and(|l| !l.is_empty()) && n.is_selected() == Some(false)) + .filter_map(|n| n.bounds()) .map(|b| egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32))) - .expect("a preset card that is not selected"); + .collect(); + assert!(!cards.is_empty(), "a preset card that is not selected"); let shapes = crate::tests_labels::flat_painted_shapes(&out.shapes); let rects: Vec<_> = shapes.iter().filter_map(|shape| if let egui::Shape::Rect(rect) = shape { Some(rect) } else { None }).collect(); let veil = |fill: egui::Color32| fill.a() > 0 && fill.a() < scrim.a() && fill.to_opaque() == scrim.to_opaque(); - assert!( - rects.iter().any(|rect| veil(rect.fill) && rect.rect.contains_rect(card.shrink(1.0)) && card.expand(1.0).contains_rect(rect.rect)), - "a veil of the scrim {scrim:?} covers the resting card {card:?}: {:?}", - rects.iter().filter(|rect| card.expand(1.0).contains_rect(rect.rect)).map(|rect| (rect.rect, rect.fill)).collect::>() - ); - assert!(rects.iter().any(|rect| rect.fill == egui::Color32::WHITE && card.contains_rect(rect.rect)), "the card's paper is on the tile"); + for card in cards { + assert!( + rects.iter().any(|rect| veil(rect.fill) && rect.rect.contains_rect(card.shrink(1.0)) && card.expand(1.0).contains_rect(rect.rect)), + "a veil of the scrim {scrim:?} covers the resting card {card:?}: {:?}", + rects.iter().filter(|rect| card.expand(1.0).contains_rect(rect.rect)).map(|rect| (rect.rect, rect.fill)).collect::>() + ); + assert!(rects.iter().any(|rect| rect.fill == egui::Color32::WHITE && card.contains_rect(rect.rect)), "the card's paper is on the tile"); + } } /// Recent shows each entry as it was made: a portrait and a landscape A3 are two documents, and