From 22314f552dc1b14e25267ec1e9cec8489f966bfb Mon Sep 17 00:00:00 2001 From: Martin Ball <98639962+benandez@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:59:43 +0000 Subject: [PATCH] Make the seven ui-egui tests that failed on macOS platform-aware (#7144) Mod is Cmd on macOS, so the paste tests hold the platform's Mod key; Alt+Q is the command search off macOS only; the unsaved-changes prompt asks Save on macOS and Yes elsewhere; the default-app row shows Finder's steps on macOS, no button; the i18n audit knows macOS chord symbols such as the Read Aloud hint. Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/tests.rs | 41 ++++++++++++++++------------- crates/ui-egui/src/i18n/audit.rs | 4 ++- crates/ui-egui/src/keys/tests.rs | 16 ++++++++--- crates/ui-egui/src/tests.rs | 14 +++++++--- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index 4a050156fd..008f416e61 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -374,25 +374,28 @@ fn shortcut_text_is_swallowed_once() { frames(&mut h, 4); h }; - // The shortcut and its text in one frame. - let mut h = fresh(); - h.event(key(egui::Key::Q, true)); - h.event(egui::Event::Text("q".into())); - frames(&mut h, 3); - // The app is in Focus, where the title bar's Search box is hidden, so the dialog takes the request (#5398). - assert!(is_open(h.state(), "commands"), "Alt+Q opens the palette"); - assert_eq!(query(&h), "", "Alt+Q's q, same frame"); - // The text a frame late; then typing. - let mut h = fresh(); - h.event(key(egui::Key::Q, true)); - frames(&mut h, 1); - h.event(egui::Event::Text("q".into())); - frames(&mut h, 1); - assert_eq!(query(&h), "", "the q a frame late"); - h.event(key(egui::Key::B, false)); - h.event(egui::Event::Text("b".into())); - frames(&mut h, 2); - assert_eq!(query(&h), "b", "then typing lands"); + // Alt+Q is the command search off macOS only (Option+Q types a character there; `tools.search` has no key). + if !cfg!(target_os = "macos") { + // The shortcut and its text in one frame. + let mut h = fresh(); + h.event(key(egui::Key::Q, true)); + h.event(egui::Event::Text("q".into())); + frames(&mut h, 3); + // The app is in Focus, where the title bar's Search box is hidden, so the dialog takes the request (#5398). + assert!(is_open(h.state(), "commands"), "Alt+Q opens the palette"); + assert_eq!(query(&h), "", "Alt+Q's q, same frame"); + // The text a frame late; then typing. + let mut h = fresh(); + h.event(key(egui::Key::Q, true)); + frames(&mut h, 1); + h.event(egui::Event::Text("q".into())); + frames(&mut h, 1); + assert_eq!(query(&h), "", "the q a frame late"); + h.event(key(egui::Key::B, false)); + h.event(egui::Event::Text("b".into())); + frames(&mut h, 2); + assert_eq!(query(&h), "b", "then typing lands"); + } // A palette opened by a click takes typing. let mut h = fresh(); open_named(&mut h, "commands", json!({})); diff --git a/crates/ui-egui/src/i18n/audit.rs b/crates/ui-egui/src/i18n/audit.rs index 28507ac9c0..08e1a80d52 100644 --- a/crates/ui-egui/src/i18n/audit.rs +++ b/crates/ui-egui/src/i18n/audit.rs @@ -239,8 +239,10 @@ impl<'a> Exempt<'a> { fn allows(&self, app: &WordApp, text: &str) -> bool { let plain = unmarked(text); let plain = plain.trim().trim_end_matches(" —").trim(); + // A chord is `Ctrl+Shift+K` or, on macOS, the modifiers' symbols run into the key (`⌥⌘Space`, `⇧⌘K`). let chord = |s: &str| { - s.split('+').all(|k| matches!(k, "Ctrl" | "Shift" | "Alt" | "Cmd" | "Esc" | "Tab" | "Enter" | "Space") || k.chars().count() <= 3) + let key = |k: &str| matches!(k, "Ctrl" | "Shift" | "Alt" | "Cmd" | "Esc" | "Tab" | "Enter" | "Space") || k.chars().count() <= 3; + s.split('+').all(|k| key(k) || key(k.trim_start_matches(['⌃', '⌥', '⇧', '⌘']))) }; let is_shortcut = || chord(plain); // A command's hover hint, drawn as one text: its marked label, name and location, so what is left is the diff --git a/crates/ui-egui/src/keys/tests.rs b/crates/ui-egui/src/keys/tests.rs index d790dd3de1..80a78e7714 100644 --- a/crates/ui-egui/src/keys/tests.rs +++ b/crates/ui-egui/src/keys/tests.rs @@ -113,6 +113,16 @@ fn batch_frame(h: &mut H, events: Vec) { crate::test_harness::frame(h); } +/// The modifiers of the platform's Mod key as egui reports them: Cmd on macOS (`mac_cmd` with `command`, and no +/// Control), Ctrl elsewhere. +fn mod_held() -> Modifiers { + if cfg!(target_os = "macos") { + Modifiers { mac_cmd: true, command: true, ..Default::default() } + } else { + Modifiers { ctrl: true, command: true, ..Default::default() } + } +} + /// One frame with `modifiers` held, then `events`. fn mods_frame(h: &mut H, modifiers: Modifiers, events: Vec) { let events = std::iter::once(egui::Event::ModifiersChanged(modifiers)).chain(events).collect(); @@ -224,7 +234,7 @@ fn user_assignments_become_overrides() { /// bold HTML, whichever of Shift and V is released first. #[test] fn mod_shift_v_released_shift_first_pastes_once() { - let chord = Modifiers { ctrl: true, command: true, shift: true, ..Default::default() }; + let chord = Modifiers { shift: true, ..mod_held() }; let ctrl = Modifiers { shift: false, ..chord }; let mut h = alt_frame_app(); run(&mut h, "text.insert", json!({"text": "source target"})); @@ -241,7 +251,7 @@ fn mod_shift_v_released_shift_first_pastes_once() { #[test] fn a_global_mod_shift_v_leaves_the_next_mod_v_picture_paste_alone() { let mut h = picture_app(); - let chord = Modifiers { ctrl: true, command: true, shift: true, ..Default::default() }; + let chord = Modifiers { shift: true, ..mod_held() }; mods_frame(&mut h, chord, vec![key_event(Key::V, true, chord)]); let ctrl = Modifiers { shift: false, ..chord }; mods_frame(&mut h, ctrl, vec![key_event(Key::V, false, ctrl)]); @@ -296,7 +306,7 @@ fn key_event(key: Key, pressed: bool, modifiers: Modifiers) -> egui::Event { /// whether V or Ctrl is released first, and a plain V is no paste. #[test] fn mod_v_released_mod_first_pastes_the_clipboard_picture() { - let ctrl = Modifiers { ctrl: true, command: true, ..Default::default() }; + let ctrl = mod_held(); let mut h = alt_frame_app(); run(&mut h, "text.insert", json!({"text": "x"})); diff --git a/crates/ui-egui/src/tests.rs b/crates/ui-egui/src/tests.rs index fca2d103cf..32b69e872b 100644 --- a/crates/ui-egui/src/tests.rs +++ b/crates/ui-egui/src/tests.rs @@ -1911,6 +1911,7 @@ fn window_close_save_as_that_fails_says_so_and_keeps_the_document() { /// #1445: the prompt that comes back after a failed save shows the reason on screen. #[test] fn save_prompt_shows_why_the_save_failed() { + use egui_kittest::kittest::NodeT; let dir = scratch("prompt-reason"); let blocker = dir.join("folder"); std::fs::write(&blocker, b"not a folder").unwrap(); @@ -1923,7 +1924,13 @@ fn save_prompt_shows_why_the_save_failed() { h.run_steps(4); // The prompt shows it, and so does the status line the failed save wrote it to (`prompt_message` above is the prompt's own). assert!(h.query_all_by_label(reason.as_str()).next().is_some(), "the reason is in the prompt"); - assert!(h.query_by_label("Save").is_some(), "Save again is offered"); + // The accepting button: the platform's word for Save (the framework asks Yes, No, Cancel off macOS). macOS also + // keeps a hidden, greyed Save in the title bar, so ask for the one on screen. + let accept = if cfg!(target_os = "macos") { "Save" } else { "Yes" }; + let offered = h + .query_all_by_role_and_label(egui::accesskit::Role::Button, accept) + .any(|n| !n.accesskit_node().is_hidden() && !n.accesskit_node().is_disabled()); + assert!(offered, "{accept} again is offered"); let _ = std::fs::remove_dir_all(&dir); } @@ -2012,8 +2019,9 @@ fn the_default_app_button_shows_only_with_the_hosts_hook() { ); h.run_steps(4); assert!(h.query_by_label("Show the community button in the title bar").is_some(), "hook {hook}: the Options page rendered"); - // The framework's button and the row that holds it can both carry the label. - assert_eq!(h.query_all_by_label(LABEL).next().is_some(), hook, "hook {hook}: the button"); + // The row carries the label too (macOS shows it, with Finder's steps instead of a button): ask for the button. + let button = h.query_all_by_role_and_label(egui::accesskit::Role::Button, LABEL).next().is_some(); + assert_eq!(button, hook, "hook {hook}: the button"); if hook { // The button itself, not the row that carries its label. h.get_by_role_and_label(egui::accesskit::Role::Button, LABEL).click();