diff --git a/crates/ui-egui/src/panels/tests_asset_export.rs b/crates/ui-egui/src/panels/tests_asset_export.rs index e988159719..af4efb3e09 100644 --- a/crates/ui-egui/src/panels/tests_asset_export.rs +++ b/crates/ui-egui/src/panels/tests_asset_export.rs @@ -122,10 +122,16 @@ fn close_screens(p: &Panel, ok: bool) -> bool { let ctx = p.ctx().clone(); let host = p.app().dialogs().expect("a window"); let closed = host.with(|h| if ok { h.confirm::(&ctx) } else { h.cancel::(&ctx) }); - if ok { - crate::dialogs::host::pump(&mut p.app(), &ctx); + if !ok { + return closed; } - closed + crate::dialogs::host::pump(&mut p.app(), &ctx); + // The dialog holds its OK: the pump accepts the filed answer, and OK then closes it with it. + if closed || !host.with(|h| h.confirm::(&ctx)) { + return closed; + } + crate::dialogs::host::pump(&mut p.app(), &ctx); + true } /// Delivers the scripted pick's answer to the panel's pending export. @@ -177,7 +183,8 @@ fn the_rows_are_the_shared_export_settings() { // A preset set by an agent shows as its rows. run(&p, "assets.settings.set", json!({"preset": "mobile"})); p.frame(); - assert!(p.shows("iOS") && p.shows("@3x")); + // "@3x" is the third row's Suffix: a field's text, not a name. + assert!(p.shows("iOS") && p.shows_value("@3x")); // Export (nothing selected: every asset) downloads one zip on the web. p.click("Export"); let log = log.borrow(); diff --git a/crates/ui-egui/src/tests/panel_harness.rs b/crates/ui-egui/src/tests/panel_harness.rs index d0ee7463ef..3445c82d3f 100644 --- a/crates/ui-egui/src/tests/panel_harness.rs +++ b/crates/ui-egui/src/tests/panel_harness.rs @@ -33,6 +33,10 @@ impl Panel { let shown = Rc::clone(&app); let mut fixture = Fixture::new(move |ui| draw(&mut shown.borrow_mut(), ui)); fixture.room(ROOM); + // A host the test installed on the app's window (a scripted file service) goes with it to the fixture's. + if let Some(host) = app.borrow().ui_ctx.as_ref().and_then(craft::host::Host::try_of_ctx) { + craft::host::Host::clone(&host).install(fixture.ctx()); + } // The fixture's context is the app's window, as a host's is. app.borrow_mut().ui_ctx = Some(fixture.ctx().clone()); let mut panel = Panel { fixture, app }; @@ -102,6 +106,15 @@ impl Panel { self.after(); } + /// Clicks the item named `name` of the open menu, where a control of the panel may have the same name. + pub(crate) fn click_menu_item(&mut self, name: &str) { + let tree = self.fixture.tree(); + let item = self.fixture.by_role(craft::ui::contract::Role::MENU_ITEM).into_iter().find(|t| tree.name_of(t.node) == Some(name)); + let item = item.unwrap_or_else(|| panic!("no menu item {name:?} in {:?}", self.names())); + self.fixture.click(&item); + self.after(); + } + /// Clicks the control named `name` with `mods` held. pub(crate) fn click_with(&mut self, name: &str, mods: Modifiers) { let target = self.find(name); @@ -122,6 +135,13 @@ impl Panel { self.after(); } + /// Presses on the control named `name`, moves the pointer by `by` and keeps the button down until [`Panel::release`]. + pub(crate) fn drag_hold(&mut self, name: &str, by: Vec2) { + let target = self.find(name); + self.fixture.drag_hold_at(target.center(), by); + self.after(); + } + /// Releases the button a [`Panel::press`] held, where the pointer is. pub(crate) fn release(&mut self) { let at = self.fixture.ctx().input(|i| i.pointer.latest_pos()).unwrap_or_default(); @@ -227,6 +247,17 @@ impl Panel { self.fixture.tree().value_of(self.look(name).node).map(str::to_owned) } + /// The description of the control named `name` (a list row's trailing texts). + pub(crate) fn description(&self, name: &str) -> Option { + self.fixture.tree().description_of(self.look(name).node).map(str::to_owned) + } + + /// Whether a control in the latest frame holds the value text `value`. + pub(crate) fn shows_value(&self, value: &str) -> bool { + let tree = self.fixture.tree(); + tree.keys().into_iter().any(|key| tree.value_of(key) == Some(value)) + } + /// The toggle state of the control named `name`. // PLAN: assumed the facade re-exports the behavior crate's `Mixed` as `craft::behavior::Mixed`. pub(crate) fn toggled(&self, name: &str) -> Option> {