From 04bb1e1b5b468f3d18464e0ce4faf9bb36282592 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 19:57:56 +0000 Subject: [PATCH] ui-patterns tests: settle after dialog actions instead of fixed frame counts Save for Web's open and palette helpers, its slices test, Export As's scale test and the New Document card tests wait until the dialog is stable rather than 4 to 30 frames; the card tests run without motion, since they read cards where they are painted. Clock-timed steps stay as they were. --- .../tests/it/form_dialogs/hosted.rs | 12 +++++----- .../tests/it/form_dialogs/new_document.rs | 17 ++++++++------ .../tests/it/form_dialogs/save_for_web.rs | 22 +++++++++---------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/crates/ui-patterns/tests/it/form_dialogs/hosted.rs b/crates/ui-patterns/tests/it/form_dialogs/hosted.rs index d44f6dbbe..c59d51f01 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/hosted.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/hosted.rs @@ -386,19 +386,19 @@ fn export_as_keeps_scale_all_within_its_limits_and_enter_in_a_field_only_commits let host = Rc::new(RefCell::new(DialogHost::new())); let mut fixture = fixture(&host); host.borrow_mut().open(HostedExportAs::new("Poster", PICTURE, ExportOptions::default())); - fixture.idle(10); + fixture.settle(); let options = |host: &Rc>| host.borrow().get::().map(|dialog| dialog.options().clone()).expect("open"); let scale = fixture.by_label("Scale").expect("the Scale field"); - fixture.click(&scale).idle(2); + fixture.click(&scale).settle(); fixture.key(Key::A, Modifiers::COMMAND).type_text("50"); - fixture.key(Key::Enter, Modifiers::NONE).idle(4); + fixture.key(Key::Enter, Modifiers::NONE).settle(); assert!(host.borrow().is_open::(), "Enter in the Scale field leaves the dialog open"); assert_eq!(options(&host).output_size(PICTURE), PixelSize::new(800, 450), "Enter commits the field"); for _ in 1..ScaleRow::MAX_ROWS { let add = fixture.by_label("Add a size").expect("the + button"); - fixture.click(&add).idle(4); + fixture.click(&add).settle(); } let rows = options(&host).scale_rows(); assert_eq!(rows.len(), ScaleRow::MAX_ROWS, "+ adds rows up to the limit"); @@ -409,9 +409,9 @@ fn export_as_keeps_scale_all_within_its_limits_and_enter_in_a_field_only_commits assert!(fixture.tree().is_disabled_key(add.node), "+ is disabled at the limit"); let suffix = fixture.by_label("Suffix 2").expect("the second row's suffix"); - fixture.click(&suffix).idle(2); + fixture.click(&suffix).settle(); fixture.key(Key::A, Modifiers::COMMAND).type_text(&"s".repeat(ScaleRow::MAX_SUFFIX + 10)); - fixture.key(Key::Tab, Modifiers::NONE).idle(4); + fixture.key(Key::Tab, Modifiers::NONE).settle(); assert_eq!(options(&host).scale_rows()[1].suffix.chars().count(), ScaleRow::MAX_SUFFIX, "a suffix is cut at its limit"); } diff --git a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs index ef83f8435..f56c6eddc 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs @@ -1,6 +1,7 @@ //! New Document: saved presets, the Save Document Preset pane, Bitmap's depth, the Web and Mobile cards' Artboards and //! the pixel aspect ratio. +use craft_behavior::MotionMode; use craft_ui::buttons::Button; use craft_ui::contract::{Bind, SaveKey, Show as _, clicked}; use craft_ui::dialog::DialogHost; @@ -35,10 +36,10 @@ fn shows(fixture: &Fixture, text: &str) -> bool { /// Opens `tab` and clicks the card titled `card` in it. fn pick(fixture: &mut Fixture, tab: &str, card: &str) { let target = fixture.by_label(tab).unwrap_or_else(|| panic!("the {tab} tab")); - fixture.click(&target).idle(10); + fixture.click(&target).settle(); // A card's node is named by its title and size line together; its title is clicked where it is painted. let title = fixture.texts().iter().find(|painted| painted.text == card).map(|painted| painted.rect.center()); - fixture.click_at(title.unwrap_or_else(|| panic!("the {card} card in {tab}"))).idle(10); + fixture.click_at(title.unwrap_or_else(|| panic!("the {card} card in {tab}"))).settle(); } /// The most a host's count may be: its `fitted` caps it. @@ -176,12 +177,13 @@ fn the_orientation_turns_the_built_in_cards() { let _ = NewDocumentDialog::new(Bind::bound(&mut options)).show(ui); *held.borrow_mut() = options; }); - fixture.room(Vec2::new(1400.0, 1000.0)).idle(30); + // The cards are read where they are painted, so the motion is off: a settled frame shows them at rest. + fixture.motion(MotionMode::Off).room(Vec2::new(1400.0, 1000.0)).settle(); let art = fixture.by_label("Art & Illustration").expect("the Art tab"); - fixture.click(&art).idle(10); + fixture.click(&art).settle(); let turn = |fixture: &mut Fixture, orientation: &str| { let control = fixture.by_label(orientation).unwrap_or_else(|| panic!("the {orientation} control")); - fixture.click(&control).idle(10); + fixture.click(&control).settle(); }; let page = |shared: &Rc>| { let size = shared.borrow().size; @@ -394,13 +396,14 @@ fn web_cards_turn_artboards_on_and_only_take_back_their_own() { let _ = NewDocumentDialog::new(Bind::bound(&mut options)).show(ui); *held.borrow_mut() = options; }); - fixture.room(Vec2::new(1400.0, 1000.0)).idle(30); + // The cards are read where they are painted, so the motion is off: a settled frame shows them at rest. + fixture.motion(MotionMode::Off).room(Vec2::new(1400.0, 1000.0)).settle(); pick(&mut fixture, "Web", "Web Most Common"); assert!(shared.borrow().artboard, "a Web card turns Artboards on"); pick(&mut fixture, "Photo", "Landscape, 6 x 4"); assert!(!shared.borrow().artboard, "a Photo card takes it back"); let artboards = fixture.by_label("Artboards").expect("the Artboards box"); - fixture.click(&artboards).idle(10); + fixture.click(&artboards).settle(); pick(&mut fixture, "Photo", "Landscape, 7 x 5"); assert!(shared.borrow().artboard, "the user's tick stays"); } diff --git a/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs b/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs index e3171d24b..105ec43c9 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs @@ -43,7 +43,7 @@ fn open(web: HostedSaveForWeb) -> (Rc>, Fixture) { let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui)); fixture.room(Vec2::new(1400.0, 1000.0)); host.borrow_mut().open(web); - fixture.idle(10); + fixture.settle(); (host, fixture) } @@ -178,7 +178,7 @@ fn show_palette(host: &Rc>, fixture: &mut Fixture) { let revision = wanted.first().map_or(1, |want| want.request.revision); let variant = WebVariant::new(0, revision, texture(), 1000).colors(4).palette(PALETTE.to_vec()); host.borrow_mut().get_mut::().expect("open").set_variant(variant); - fixture.idle(4); + fixture.settle(); select_optimized_pane(fixture); } @@ -212,7 +212,7 @@ fn slices_and_palette_edits_follow_the_settings() { let web = HostedSaveForWeb::new("poster.psd", IMAGE, texture()).options(start).slices(slices()).presets(vec![preset]); let (host, mut fixture) = open(web); let actual = fixture.by_label("100%").expect("the 100% button"); - fixture.click(&actual).idle(4); + fixture.click(&actual).settle(); // A click selects one slice; Shift adds and removes. click_picture(&mut fixture, pos2(50.0, 50.0)); @@ -233,38 +233,38 @@ fn slices_and_palette_edits_follow_the_settings() { show_palette(&host, &mut fixture); assert_eq!(current(&host).slices, WebSlices::Selected(vec![1, 2]), "a click beside the picture leaves the slices"); let cell = fixture.by_label("1 #00ff00").expect("the Color Table lists the palette"); - fixture.click(&cell).key(Key::Enter, Modifiers::NONE).idle(4); + fixture.click(&cell).key(Key::Enter, Modifiers::NONE).settle(); let (id, request) = host.borrow_mut().take_color_request().expect("opening a cell asks for its colour"); assert_eq!(request.key, PALETTE_COLOR_KEY); host.borrow_mut().answer_color(id, PALETTE_COLOR_KEY, Srgba::rgb(1.0, 0.0, 1.0)); - fixture.idle(4); + fixture.settle(); let shift = (ColorTableEdit::Shift([255, 0, 255]), vec![[0, 255, 0]]); assert_eq!(table_events(&host), vec![shift], "the answer shifts the opened entry's colour"); let interlaced = fixture.by_label("Interlaced").expect("the Interlaced check box"); - fixture.click(&interlaced).idle(4); + fixture.click(&interlaced).settle(); assert!(table_events(&host).is_empty(), "a setting that leaves the palette alone files no table event"); let colors = fixture.by_label("Colors").expect("the Colors field"); - fixture.click(&colors).key(Key::ArrowUp, Modifiers::NONE).idle(4); + fixture.click(&colors).key(Key::ArrowUp, Modifiers::NONE).settle(); assert_eq!(current(&host).colors, 9, "the colour count changed"); let restore = (ColorTableEdit::Restore, Vec::new()); assert_eq!(table_events(&host), vec![restore], "a colour-count change restores the generated table"); // A preset pick keeps the slices. let select = fixture.by_label("Preset").expect("the Preset list"); - fixture.click(&select).idle(4); + fixture.click(&select).settle(); let entry = fixture.by_label("GIF 16").expect("the preset entry"); - fixture.click(&entry).idle(4); + fixture.click(&entry).settle(); let after = current(&host); assert_eq!(after.colors, 16, "the preset applied"); assert_eq!(after.slices, WebSlices::Selected(vec![1, 2]), "a preset keeps the slices"); // Save answers the selection in the order it was made. let save = fixture.by_label("Save…").expect("the Save button"); - fixture.click(&save).idle(4); + fixture.click(&save).settle(); let request = host.borrow_mut().get_mut::().and_then(HostedSaveForWeb::pick_path).expect("Save asks for a path"); host.borrow_mut().get_mut::().expect("open").answer_path(request.key.clone(), PathBuf::from("/tmp/poster.gif")); - fixture.idle(6); + fixture.settle(); let result = host.borrow_mut().take::().and_then(DialogResult::ok).expect("the path finishes the dialog"); assert_eq!(result.options.slices, WebSlices::Selected(vec![1, 2]), "Save answers the selected slices"); }