From 4a76442e8f8c9d37ff24b27c8af36f33c8a188ba Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 01:53:46 +0700 Subject: [PATCH] Port trials follow upstream's APIs: the guides rig without a body rect, in-place tidy and English names on the menu model, page-aware document points --- crates/automation/tests/it/access.rs | 2 +- crates/menu/tests/it/heading.rs | 28 ++++++++----------- .../tests/it/canvas_controls/guides.rs | 9 +++--- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/crates/automation/tests/it/access.rs b/crates/automation/tests/it/access.rs index 5a7fbe559..9ce1acc66 100644 --- a/crates/automation/tests/it/access.rs +++ b/crates/automation/tests/it/access.rs @@ -51,7 +51,7 @@ impl Rig { /// Sends `method`; when it is accepted, runs frames until the host has processed the input. fn send(&mut self, method: &str, params: Value) -> Result<(), String> { - input_method(method, ¶ms, &self.host, ViewportId::ROOT, &|_| None).expect("an input method")?; + input_method(method, ¶ms, &self.host, ViewportId::ROOT, &|_, _| None).expect("an input method")?; for _ in 0..32 { self.fx.frame(Vec::new()); if self.host.injected_idle() { diff --git a/crates/menu/tests/it/heading.rs b/crates/menu/tests/it/heading.rs index 65e2b44d8..93c6eaf79 100644 --- a/crates/menu/tests/it/heading.rs +++ b/crates/menu/tests/it/heading.rs @@ -1,7 +1,8 @@ //! A heading is a caption over the rows after it: structure, never a command. use craft_host::target::Os; -use craft_menu::{CommandRef, Item, Labeled, LayoutOptions, Menu, MenuBar, MenuBarUi, Node, Target, tidy}; +use craft_menu::{Item, LayoutOptions, Menu, MenuBar, MenuBarUi, Node, Target, tidy}; +use craft_ui::contract::Tracked; use craft_ui::testing::{Fixture, trial}; use egui::{Key, Modifiers}; @@ -12,36 +13,31 @@ use crate::sample::ids; /// they are and runs nothing when clicked. #[trial] fn a_heading_is_structure_and_never_a_command() { - let nodes = tidy(vec![ + let mut nodes = vec![ Node::heading("最近"), - Item::new("file.new", "新建").into(), - Item::new("file.open", "打开").into(), + Item::new("file.new", "新建").english("New").into(), + Item::new("file.open", "打开").english("Open").into(), Node::Separator, Node::heading("Empty"), Node::Separator, - Item::new("file.close", "关闭").into(), + Item::new("file.close", "关闭").english("Close").into(), Node::heading("Trailing"), - ]); + ]; + tidy(&mut nodes); assert_eq!( ids(&nodes), ["#最近", "file.new", "file.open", "---", "file.close"], "a heading with no item after it goes, and the separators it leaves collapse" ); - let bar = MenuBar::new(vec![Menu::new("文件", nodes)]); - let entries = bar.help_entries(Target::Linux, &LayoutOptions::new("Trial"), None); + let bar = MenuBar::new(vec![Menu::new("文件", nodes).english("File")]); + let entries = bar.help_entries(Target::Linux, &LayoutOptions::new("Trial")); let listed: Vec = entries.iter().map(|entry| entry.command().key()).filter(|key| key.starts_with("file.")).collect(); assert_eq!(listed, ["file.new", "file.open", "file.close"], "the help search lists the items, never the heading"); - let english = |labeled: Labeled<'_>| match labeled { - Labeled::Title("文件") => Some("File".to_owned()), - Labeled::Command(command) if *command == CommandRef::new("file.new") => Some("New".to_owned()), - Labeled::Command(command) if *command == CommandRef::new("file.open") => Some("Open".to_owned()), - Labeled::Command(command) if *command == CommandRef::new("file.close") => Some("Close".to_owned()), - _ => None, - }; + let bar = Tracked::new(bar); let mut fixture = Fixture::new(move |ui| { - MenuBarUi::new(&bar).english(&english).show(ui); + MenuBarUi::new(&bar).show(ui); }); // A Mac bar has no letters. fixture.os(Os::Linux); diff --git a/crates/ui-canvas/tests/it/canvas_controls/guides.rs b/crates/ui-canvas/tests/it/canvas_controls/guides.rs index 02ae3e40d..5382d20c7 100644 --- a/crates/ui-canvas/tests/it/canvas_controls/guides.rs +++ b/crates/ui-canvas/tests/it/canvas_controls/guides.rs @@ -235,9 +235,10 @@ fn a_dragged_guide_is_removed_off_the_bounds_or_on_a_ruler_and_alt_and_shift_cha fn a_double_press_on_a_ruler_places_a_guide_at_once() { let placed = |mods: Modifiers, at: &dyn Fn(Rect) -> Pos2| -> Vec { let guides: Shared> = Rc::new(RefCell::new(Vec::new())); - let (mut fixture, body) = ruled(1.0, &guides); + let mut fixture = ruled(1.0, &guides); + let rect = fixture.canvas().rect; fixture.fixture().hold(mods); - fixture.double_press_at(at(body.get())); + fixture.double_press_at(at(rect)); fixture.fixture().hold(Modifiers::NONE); let placed = guides.borrow().clone(); placed @@ -257,8 +258,8 @@ fn a_double_press_on_a_ruler_places_a_guide_at_once() { assert!(placed(Modifiers::ALT, &top(650.0)).is_empty(), "a double press outside the bounds adds none"); let guides: Shared> = Rc::new(RefCell::new(Vec::new())); - let (mut fixture, body) = ruled(1.0, &guides); - let rect = body.get(); + let mut fixture = ruled(1.0, &guides); + let rect = fixture.canvas().rect; drag_with(&mut fixture, Modifiers::NONE, pos2(300.0, rect.min.y + 4.0), pos2(300.0, 247.6)); assert_eq!(guides.borrow().len(), 1, "a press and drag out of a strip adds exactly one guide: {:?}", guides.borrow()); }