mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-02 20:20:35 -05:00
Merge pull request #8632 from storytold/fix/macos-ui-tests
test(ui): run the UI tests on one shell on every machine; in-window menus follow the shell (#8630)
This commit is contained in:
10 files changed
+70
-64
No files matched your search
@@ -4,7 +4,6 @@ use std::borrow::Cow;
|
||||
|
||||
use craft::behavior::{DisplayOrder, IconId, ItemSource, SelectionChange};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::Target;
|
||||
use craft::ui::bars::{Bar, BarKind};
|
||||
use craft::ui::buttons::{CommandSearch, IconButton};
|
||||
use craft::ui::contract::{Bind, CollectionEvent, Props as _, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
@@ -105,7 +104,7 @@ pub(super) fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
/// What the palette searches: the menus' commands, each ready tool group, and the catalogue items
|
||||
/// that are not commands of their own.
|
||||
fn palette_entries(app: &PdfCraftApp, ctx: &egui::Context) -> Vec<HelpEntry> {
|
||||
let mut entries = app.menu_bar(ctx).help_entries(Target::current(), &crate::menus::layout_options());
|
||||
let mut entries = app.menu_bar(ctx).help_entries(crate::menus::shell_target(ctx), &crate::menus::layout_options());
|
||||
for group in TOOL_GROUPS {
|
||||
if group.availability == Availability::Ready {
|
||||
let select = CommandRef::with_params("tool.group", serde_json::json!({ "group": group.id }));
|
||||
|
||||
@@ -26,7 +26,7 @@ fn keymap(ctx: &egui::Context) -> Keymap {
|
||||
let defs = crate::commands::catalog::shared_catalog(crate::commands::mac_shortcuts(ctx))
|
||||
.map(|c| c.defs().iter().map(localized).collect())
|
||||
.unwrap_or_default();
|
||||
Keymap::new(defs, Scopes::new(), Platform::current())
|
||||
Keymap::new(defs, Scopes::new(), Platform::of_egui(ctx.os()))
|
||||
}
|
||||
|
||||
/// `def` as the window shows it: labelled as the menus label it, under its menu bar path.
|
||||
|
||||
@@ -297,6 +297,11 @@ pub(crate) fn layout_options() -> LayoutOptions<'static> {
|
||||
LayoutOptions::new(APP_NAME).label(&translate)
|
||||
}
|
||||
|
||||
/// The platform the window's shell runs on, for menus drawn in the window.
|
||||
pub(crate) fn shell_target(ctx: &egui::Context) -> Target {
|
||||
Target::of_shell(&craft::ui::runtime::windows::WindowHost::of(ctx).shell())
|
||||
}
|
||||
|
||||
/// Whether a dialog, a prompt or the command palette holds the window: the gate over the menu bar's
|
||||
/// keys and the native menu. The command gate (`commands::catalog::command_input`) leaves the
|
||||
/// palette out, so the palette lists and runs the commands as the window under it has them.
|
||||
@@ -520,12 +525,13 @@ impl PdfCraftApp {
|
||||
/// couldn't be installed), where the top bar starts. A chosen command fires through the board.
|
||||
pub(crate) fn menu_bar_ui(&mut self, ui: &mut egui::Ui) {
|
||||
let ctx = ui.ctx().clone();
|
||||
let bar = craft::menu::layout(&self.menu_bar(&ctx), Target::current(), &layout_options()).bar;
|
||||
let target = shell_target(&ctx);
|
||||
let bar = craft::menu::layout(&self.menu_bar(&ctx), target, &layout_options()).bar;
|
||||
let modal = gated(self);
|
||||
if *self.window_menu_bar != bar {
|
||||
*self.window_menu_bar = bar;
|
||||
}
|
||||
craft::menu::MenuBarUi::new(&self.window_menu_bar).target(Target::current()).keyboard(!modal).icons(false).compact(true).show(ui);
|
||||
craft::menu::MenuBarUi::new(&self.window_menu_bar).target(target).keyboard(!modal).icons(false).compact(true).show(ui);
|
||||
}
|
||||
|
||||
/// Install the native menu bar (macOS), once, from the eframe app creator. `false` when
|
||||
|
||||
@@ -1069,10 +1069,10 @@ fn preferences_menu_and_shortcut_allow_switching_interface_languages() {
|
||||
let (mut h, c) = harness();
|
||||
ok(&mut h, &c, "ui.set", json!({ "key": "language", "value": "ja" }));
|
||||
// The menu bar's Edit menu holds Preferences on Windows and Linux. On macOS the in-window bar
|
||||
// takes the Mac layout (`Target::current()`), which moves it to the app menu as Settings….
|
||||
// takes the shell layout (`Target::of_shell`), which moves it to the app menu as Settings….
|
||||
// Titles and rows carry their mnemonic ("編集(E)", "環境設定(P)…"), so match by the start of
|
||||
// the label.
|
||||
let (menu, preferences) = if cfg!(target_os = "macos") {
|
||||
let (menu, preferences) = if h.ctx.os() == egui::os::OperatingSystem::Mac {
|
||||
let ja = pdfcraft_ui_egui::i18n::Lang::from_code("ja").unwrap();
|
||||
("PdfCraft", pdfcraft_ui_egui::i18n::tr(ja, "Settings…").trim_end_matches('…'))
|
||||
} else {
|
||||
@@ -1147,9 +1147,23 @@ fn japanese_dialogs_errors_and_custom_action_names() {
|
||||
("compare-files", "ファイルを比較"),
|
||||
("sign", "署名用のデジタル ID を設定"),
|
||||
] {
|
||||
// Close the previous modal before opening another; a hosted dialog must not be
|
||||
// inspected through the JavaScript console or another modal's access boundary.
|
||||
ok(&mut h, &c, "ui.set", json!({"key": "dialog", "value": "none"}));
|
||||
settle(&mut h);
|
||||
ok(&mut h, &c, "ui.set", json!({"key": "dialog", "value": dialog}));
|
||||
// Hosted dialogs publish their access tree on a subsequent frame.
|
||||
settle(&mut h);
|
||||
let found = ok(&mut h, &c, "ui.inspect", json!({"query": label}));
|
||||
assert!(found["count"].as_u64().unwrap() > 0, "{dialog}: {found}");
|
||||
if dialog == "js-console" {
|
||||
// The console is an inline window outside the hosted dialog stack. Close it
|
||||
// through its translated button before inspecting the next hosted dialog.
|
||||
ok(&mut h, &c, "ui.click", json!({"label": "閉じる"}));
|
||||
settle(&mut h);
|
||||
let closed = ok(&mut h, &c, "ui.inspect", json!({"query": label}));
|
||||
assert_eq!(closed["count"], 0, "the console must close before the next dialog: {closed}");
|
||||
}
|
||||
}
|
||||
ok(&mut h, &c, "ui.set", json!({"key": "dialog", "value": "none"}));
|
||||
let ctx_h = h.ctx.clone();
|
||||
@@ -1264,6 +1278,9 @@ fn commands_keys_and_typing() {
|
||||
#[test]
|
||||
fn ctrl_dragging_a_thumbnail_through_the_control_channel_copies_the_page() {
|
||||
let (mut h, c) = harness_pages(3);
|
||||
// The control protocol normalizes modifier flags for the host OS. Exercise that same
|
||||
// OS in the shell rather than pairing macOS protocol input with the Linux test shell.
|
||||
craft::ui::testing::windows::set_os(&h.ctx, craft::host::target::Os::current());
|
||||
ok(&mut h, &c, "ui.set", json!({ "key": "tool", "value": "organize" }));
|
||||
h.run_steps(3);
|
||||
// The grid cell of a page: the node labelled exactly "Page N" (the checkbox says "Select page N").
|
||||
|
||||
@@ -87,8 +87,8 @@ fn page_texts(app: &PdfCraftApp) -> Vec<String> {
|
||||
}
|
||||
|
||||
/// Organize copies pages as a file manager copies files: Option on macOS, Ctrl elsewhere.
|
||||
fn copy_modifier(_h: &Harness<'static, PdfCraftApp>, copying: bool) -> Modifiers {
|
||||
match (copying, cfg!(target_os = "macos")) {
|
||||
fn copy_modifier(h: &Harness<'static, PdfCraftApp>, copying: bool) -> Modifiers {
|
||||
match (copying, h.ctx.os() == egui::os::OperatingSystem::Mac) {
|
||||
(false, _) => Modifiers::NONE,
|
||||
(true, true) => Modifiers::ALT,
|
||||
// Ctrl as a keyboard sends it off macOS: the command key too.
|
||||
|
||||
@@ -147,6 +147,16 @@ pub fn app_with_clipboard(clipboard: RecordingClipboard) -> PdfCraftApp {
|
||||
pub fn install_runtime(ctx: &egui::Context) {
|
||||
let spec = InstallSpec::new(ShellInfo::default(), Arc::new(NoWindows));
|
||||
embed::install(ctx, spec, &pdfcraft_ui_egui::fonts::ui_fonts(i18n::Lang::EN)).expect("the runtime installs on a fresh context");
|
||||
pin_shell_os(ctx);
|
||||
}
|
||||
|
||||
/// Runs every test on the same shell whatever machine runs it: Linux's key table, chords, menu layout
|
||||
/// and capabilities. Without it a macOS runner gave the tests its own shell (⌘ chords, the macOS
|
||||
/// menu layout), so tests written for the in-window menu bar and Ctrl failed there and passed on
|
||||
/// Linux and Windows. A test of another platform's behaviour sets it with
|
||||
/// `craft::ui::testing::windows::set_os` (the shell) or `ctx.set_os` (egui's OS only), as before.
|
||||
pub fn pin_shell_os(ctx: &egui::Context) {
|
||||
craft::ui::testing::windows::set_os(ctx, craft::host::target::Os::Linux);
|
||||
}
|
||||
|
||||
/// A clipboard backend the tests share: what the app writes is read back through the clone the test keeps.
|
||||
|
||||
@@ -218,24 +218,8 @@ fn page_shadow_preference_round_trips_and_ignores_invalid_settings() {
|
||||
assert_eq!(enabled(&app), Some(true));
|
||||
}
|
||||
|
||||
/// An app on the default host with test services: no wake-ups, no autosave folder, the GitHub update
|
||||
/// source, a fresh intake and an inline watch (as `tests/it/control.rs`' `new_app`).
|
||||
fn new_app() -> pdfcraft_ui_egui::PdfCraftApp {
|
||||
use craft::host::{AppInfo, Host, Wake};
|
||||
use craft::platform::clipboard::{Clipboard, SystemClipboard};
|
||||
use craft::platform::open::FileIntake;
|
||||
use craft::platform::watch::FileWatch;
|
||||
let host = Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "test" }).build();
|
||||
let services = pdfcraft_ui_egui::AppServices::new(
|
||||
Wake::none(),
|
||||
Clipboard::new(SystemClipboard::new()),
|
||||
None,
|
||||
None,
|
||||
FileIntake::new(Wake::none()).0,
|
||||
FileWatch::new(Wake::none()).inline(),
|
||||
);
|
||||
pdfcraft_ui_egui::PdfCraftApp::with_host(std::sync::Arc::new(host), services)
|
||||
}
|
||||
mod support;
|
||||
use support::new_app;
|
||||
|
||||
/// The app's command and option entry points with the harness's own context (L-208).
|
||||
trait AppHarness {
|
||||
|
||||
@@ -163,7 +163,9 @@ fn wheel_frames_build_only_the_pages_in_view() {
|
||||
if frame % 3 == 0 {
|
||||
h.event(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: egui::vec2(0.0, -1.0),
|
||||
// Three lines, as one wheel notch: a line is 100 points on Linux and Windows but 40 on
|
||||
// macOS (`scroll_speed`), and twenty single lines there don't leave the first page at 200%.
|
||||
delta: egui::vec2(0.0, -3.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
@@ -197,28 +199,14 @@ fn panels_build_only_the_rows_in_view() {
|
||||
}
|
||||
}
|
||||
|
||||
/// An app on the default host with test services: no wake-ups, no autosave folder, the GitHub update
|
||||
/// source, a fresh intake and an inline watch (as `tests/it/control.rs`' `new_app`).
|
||||
fn new_app() -> pdfcraft_ui_egui::PdfCraftApp {
|
||||
use craft::host::{AppInfo, Host, Wake};
|
||||
use craft::platform::clipboard::{Clipboard, SystemClipboard};
|
||||
use craft::platform::open::FileIntake;
|
||||
use craft::platform::watch::FileWatch;
|
||||
let host = Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "test" }).build();
|
||||
let services = pdfcraft_ui_egui::AppServices::new(
|
||||
Wake::none(),
|
||||
Clipboard::new(SystemClipboard::new()),
|
||||
None,
|
||||
None,
|
||||
FileIntake::new(Wake::none()).0,
|
||||
FileWatch::new(Wake::none()).inline(),
|
||||
);
|
||||
pdfcraft_ui_egui::PdfCraftApp::with_host(std::sync::Arc::new(host), services)
|
||||
}
|
||||
mod support;
|
||||
use support::new_app;
|
||||
|
||||
/// Installs the framework runtime on a harness context, as `tests/it/support`'s `install_runtime` (L-227).
|
||||
fn install_runtime(ctx: &egui::Context) {
|
||||
let spec = craft::ui::InstallSpec::new(craft::host::target::ShellInfo::default(), std::sync::Arc::new(craft::window::system::NoWindows));
|
||||
craft::ui::shell::embed::install(ctx, spec, &pdfcraft_ui_egui::fonts::ui_fonts(pdfcraft_ui_egui::i18n::Lang::EN))
|
||||
.expect("the runtime installs on a fresh context");
|
||||
// The same shell on every machine, as `tests/it/support`'s `pin_shell_os`.
|
||||
craft::ui::testing::windows::set_os(ctx, craft::host::target::Os::Linux);
|
||||
}
|
||||
@@ -374,24 +374,8 @@ fn letter_pdf(content: &str) -> Vec<u8> {
|
||||
out
|
||||
}
|
||||
|
||||
/// An app on the default host with test services: no wake-ups, no autosave folder, the GitHub update
|
||||
/// source, a fresh intake and an inline watch (as `tests/it/control.rs`' `new_app`).
|
||||
fn new_app() -> pdfcraft_ui_egui::PdfCraftApp {
|
||||
use craft::host::{AppInfo, Host, Wake};
|
||||
use craft::platform::clipboard::{Clipboard, SystemClipboard};
|
||||
use craft::platform::open::FileIntake;
|
||||
use craft::platform::watch::FileWatch;
|
||||
let host = Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "test" }).build();
|
||||
let services = pdfcraft_ui_egui::AppServices::new(
|
||||
Wake::none(),
|
||||
Clipboard::new(SystemClipboard::new()),
|
||||
None,
|
||||
None,
|
||||
FileIntake::new(Wake::none()).0,
|
||||
FileWatch::new(Wake::none()).inline(),
|
||||
);
|
||||
pdfcraft_ui_egui::PdfCraftApp::with_host(std::sync::Arc::new(host), services)
|
||||
}
|
||||
mod support;
|
||||
use support::new_app;
|
||||
|
||||
/// The app's command and option entry points with the harness's own context (L-208).
|
||||
trait AppHarness {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/// An app on the default host with test services: no wake-ups, no autosave folder, the GitHub update
|
||||
/// source, a fresh intake and an inline watch (as `tests/it/control.rs`' `new_app`).
|
||||
pub fn new_app() -> pdfcraft_ui_egui::PdfCraftApp {
|
||||
use craft::host::{AppInfo, Host, Wake};
|
||||
use craft::platform::clipboard::{Clipboard, SystemClipboard};
|
||||
use craft::platform::open::FileIntake;
|
||||
use craft::platform::watch::FileWatch;
|
||||
let host = Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "test" }).build();
|
||||
let services = pdfcraft_ui_egui::AppServices::new(
|
||||
Wake::none(),
|
||||
Clipboard::new(SystemClipboard::new()),
|
||||
None,
|
||||
None,
|
||||
FileIntake::new(Wake::none()).0,
|
||||
FileWatch::new(Wake::none()).inline(),
|
||||
);
|
||||
pdfcraft_ui_egui::PdfCraftApp::with_host(std::sync::Arc::new(host), services)
|
||||
}
|
||||
Reference in new issue
Block a user