From 24237189d4f75c07f35880d5a9526a52afbf97de Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 16:19:27 +0000 Subject: [PATCH] RecentList registers as a pattern; the recent-row trial finds rows by their name with the folder Co-Authored-By: Claude Sonnet 5.5 --- crates/ui-shell/src/shell/recent_list.rs | 1 + crates/ui-shell/tests/it/shell/start.rs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/ui-shell/src/shell/recent_list.rs b/crates/ui-shell/src/shell/recent_list.rs index 7f06f763a..47e9b054a 100644 --- a/crates/ui-shell/src/shell/recent_list.rs +++ b/crates/ui-shell/src/shell/recent_list.rs @@ -28,6 +28,7 @@ use std::path::PathBuf; /// The recent files as rows, with the commands of a recent file and its context menu. The files arrive in the order /// the app wants them shown; the list does not sort. #[must_use = "show the list with `show`"] +#[derive(crate::contract::Pattern)] pub struct RecentList<'a> { recent: &'a [RecentFile], max_recent: usize, diff --git a/crates/ui-shell/tests/it/shell/start.rs b/crates/ui-shell/tests/it/shell/start.rs index 259fce185..aeba07598 100644 --- a/crates/ui-shell/tests/it/shell/start.rs +++ b/crates/ui-shell/tests/it/shell/start.rs @@ -77,6 +77,14 @@ fn a_double_click_on_the_empty_room_opens_and_one_on_a_card_opens_only_its_file( assert_eq!(opens(&log), 0, "a double click on a rail link opens no file: {:?}", log.borrow()); } +/// The row of the recent file named `file`: a list row whose name starts with the file's name and carries its folder. +fn recent_row(fixture: &Fixture, file: &str) -> Option { + [Role::LIST_ITEM, Role::LIST_BOX_OPTION] + .into_iter() + .flat_map(|role| fixture.by_role(role)) + .find(|row| fixture.tree().name_of(row.node).is_some_and(|name| name.starts_with(file))) +} + /// A recent row opens its file on a click, shows its remove part on hover and reports that file's removal, and the /// row's menu clears the list. #[trial] @@ -93,16 +101,16 @@ fn a_recent_row_names_its_full_path_and_reveals_remove_on_hover_or_focus() { log.borrow_mut().clear(); let poster = PathBuf::from("/tmp/work/Poster.psd"); - let row = fixture.by_label("Poster.psd").expect("the row shows"); - let description = fixture.tree().description_of(row.node).map(str::to_owned); - assert!(description.is_some_and(|text| text.contains("/tmp/work")), "the row's description names the file's folder"); + let row = recent_row(&fixture, "Poster.psd").expect("the row shows"); + let name = fixture.tree().name_of(row.node).map(str::to_owned); + assert!(name.is_some_and(|text| text.contains("/tmp/work")), "the row's name carries the file's folder"); fixture.click(&row).idle(2); assert!(log.borrow().contains(&StartAction::OpenRecent(poster.clone())), "a click opens the row's file: {:?}", log.borrow()); // Focus stays on the Flyer row after its click; Enter opens it again, and the pointer far away leaves the remove // part revealed by focus alone. log.borrow_mut().clear(); - let flyer = fixture.by_label("Flyer.psd").expect("the second row shows"); + let flyer = recent_row(&fixture, "Flyer.psd").expect("the second row shows"); fixture.click(&flyer).idle(2); log.borrow_mut().clear(); fixture.frame(vec![moved(egui::pos2(1.0, 1.0))]); @@ -126,7 +134,7 @@ fn a_recent_row_names_its_full_path_and_reveals_remove_on_hover_or_focus() { assert!(log.borrow().contains(&StartAction::RemoveRecent(poster)), "the remove part removes that row's file: {:?}", log.borrow()); log.borrow_mut().clear(); - let at = fixture.by_label("Flyer.psd").expect("the second row shows").center(); + let at = recent_row(&fixture, "Flyer.psd").expect("the second row shows").center(); fixture.frame(vec![moved(at)]); fixture.frame(vec![secondary(at, true)]); fixture.frame(vec![secondary(at, false)]);