From 14a88abca6375198d22f428b613869b037b10084 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Thu, 19 Nov 2026 17:26:56 -0500 Subject: [PATCH] red9 g5: app red round 9 fixes --- Cargo.lock | 1 + crates/ui-egui/Cargo.toml | 5 ++ crates/ui-egui/src/app.rs | 30 +++++++----- crates/ui-egui/src/canvas.rs | 6 +++ crates/ui-egui/src/canvas/page_parts.rs | 5 +- crates/ui-egui/src/commands.rs | 7 +++ crates/ui-egui/src/editing/close.rs | 5 +- crates/ui-egui/src/panes.rs | 7 +++ crates/ui-egui/src/tools/object_ui.rs | 49 +++++++++++++------ .../ui-egui/src/workflows/combine_ui/tests.rs | 6 +++ crates/ui-egui/src/workflows/files.rs | 13 +++-- .../ui-egui/src/workflows/ocr_verify/panes.rs | 4 ++ crates/ui-egui/tests/it/accessibility.rs | 3 +- crates/ui-egui/tests/it/control.rs | 14 +++--- crates/ui-egui/tests/it/create.rs | 4 +- crates/ui-egui/tests/it/document_links.rs | 3 +- crates/ui-egui/tests/it/pickers.rs | 8 ++- crates/ui-egui/tests/it/signing.rs | 34 ++++++++----- crates/ui-egui/tests/it/updates.rs | 12 ++++- crates/ui-egui/tests/it/view.rs | 5 +- 20 files changed, 162 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45687e5c99..ff8e0d94ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6536,6 +6536,7 @@ dependencies = [ "craft-menu", "craft-quit", "craft-ui", + "craft-update", "edit-session", "eframe", "egui", diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 51a0f9326a..5a2e0e06dc 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -112,5 +112,10 @@ toml = "1" # Only synthetic attribute fixtures use xattr; product reads/writes use rustix. xattr = "1.6" +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +# `Updater::ready_for_tests` (through the facade): an updater whose update has installed, for the +# Restart to Update screen tests. +craft-update = { workspace = true, features = ["screen-testing"] } + [target.'cfg(target_os = "linux")'.dev-dependencies] tempfile = "3.27" diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 805f0ee88d..393352819a 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -44,7 +44,7 @@ pub struct AppServices { clipboard: Clipboard, recovery_dir: Option, #[cfg(not(target_arch = "wasm32"))] - update_source: Option, + updater: craft::update::updater::Updater, intake: FileIntake, #[cfg(not(target_arch = "wasm32"))] watch: craft::platform::watch::FileWatch, @@ -62,18 +62,34 @@ impl AppServices { intake: FileIntake, #[cfg(not(target_arch = "wasm32"))] watch: craft::platform::watch::FileWatch, ) -> Self { + #[cfg(not(target_arch = "wasm32"))] + let updater = { + let updater = craft::update::updater::Updater::new(&UPDATE_APP, pdfcraft_engine::build_info::version().to_string()); + match update_source { + Some(source) => updater.with_source(source), + None => updater, + } + }; Self { wake, clipboard, recovery_dir, #[cfg(not(target_arch = "wasm32"))] - update_source, + updater, intake, #[cfg(not(target_arch = "wasm32"))] watch: reload::document_watch(watch), } } + /// These services with `updater` in place of the one over the update source: an updater + /// whose update has already installed (craft-update's `Updater::ready_for_tests`). + #[cfg(not(target_arch = "wasm32"))] + pub fn with_updater(mut self, updater: craft::update::updater::Updater) -> Self { + self.updater = updater; + self + } + /// The desktop's or the browser's own services, waking `ctx`, reading the files to open from /// `intake`. pub fn system(ctx: &egui::Context, intake: FileIntake) -> Self { @@ -192,7 +208,7 @@ impl PdfCraftApp { clipboard, recovery_dir, #[cfg(not(target_arch = "wasm32"))] - update_source, + updater, intake, #[cfg(not(target_arch = "wasm32"))] watch, @@ -206,14 +222,6 @@ impl PdfCraftApp { }); let recovered = store.as_ref().map(|s| s.leftovers()).unwrap_or_default(); let autosave = Autosave::new(store.is_some().then(|| std::time::Duration::from_secs_f64(recovery::AUTOSAVE_SECS))); - #[cfg(not(target_arch = "wasm32"))] - let updater = { - let updater = craft::update::updater::Updater::new(&UPDATE_APP, pdfcraft_engine::build_info::version().to_string()); - match update_source { - Some(source) => updater.with_source(source), - None => updater, - } - }; Self { #[cfg(not(target_arch = "wasm32"))] // PLAN: assumed open_worker::queue(&Host, Wake) -> JobQueue (pdf-shell-w13). diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index db306ecde7..665b150a69 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -505,6 +505,12 @@ impl DocView { self.middle_scrolling } + /// The tab is off screen: a middle-button gesture its last pass recorded has ended with it, as + /// production's scroll did when the active view changed. + pub(crate) fn left_screen(&mut self) { + self.middle_scrolling = false; + } + /// Whether a held middle-button pan is active, outside Linux (tests and automation). pub fn middle_panning(&self) -> bool { // PLAN: `CanvasOutput` reports one `auto_scrolling` for a latched and a held middle scroll (CV-C6) and no diff --git a/crates/ui-egui/src/canvas/page_parts.rs b/crates/ui-egui/src/canvas/page_parts.rs index 910c3e75c9..e61286ff23 100644 --- a/crates/ui-egui/src/canvas/page_parts.rs +++ b/crates/ui-egui/src/canvas/page_parts.rs @@ -6,7 +6,7 @@ use craft::behavior::{CursorIcon, HitLevel, HitPriority, HitShape, Input, Intent, Metrics, PartKey, PartRef, PressPhase, Sense}; use craft::keymap::Mods; use craft::ui::contract::{ - Common, Component, Cx, Focus as _, MeasureCx, NoValue, Outcome, PartsCx, Pointer as _, Props as _, Role, TooltipAt, TooltipSpec, + Common, Component, Cx, Focus as _, MeasureCx, NoValue, Outcome, PartsCx, Pointer as _, Props as _, Role, TooltipAt, TooltipSpec, TooltipWhen, }; use craft::ui::runtime::commands::FireSource; use craft::ui::runtime::env::Label; @@ -371,7 +371,8 @@ impl Component for PageParts<'_> { builder = builder.cursor(cursor); } if let Some(tip) = &part.tip { - builder = builder.tooltip(TooltipSpec::new(Label::from(tip.clone())).at(TooltipAt::Pointer)); + // At once, as the canvas's hover tip always showed. + builder = builder.tooltip(TooltipSpec::new(Label::from(tip.clone())).at(TooltipAt::Pointer).when(TooltipWhen::Now)); } if part.focusable { builder.focusable(); diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index da76ea4f34..a359593e42 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -315,6 +315,13 @@ impl PdfCraftApp { session.pending_edit = crate::prepare::delete_selected(session); return session.pending_edit.is_some(); } + // Copy and Cut take the objects selected together in Edit a PDF, as the catalog enables them for those. + if (id == "edit.copy" || id == crate::menus::CUT) + && let Some(i) = self.active.filter(|&i| self.views.get(i).is_some_and(|v| !v.organize && v.session.objects.count() > 0)) + && self.quick_tool == crate::QuickTool::EditText + { + return self.copy_objects(ctx, i, id == crate::menus::CUT); + } let Some(spec) = commands::command(id) else { return false }; if !self.command_enabled(spec) { let why = self.disabled_reason(spec); diff --git a/crates/ui-egui/src/editing/close.rs b/crates/ui-egui/src/editing/close.rs index 3b2218ce18..4b169b3029 100644 --- a/crates/ui-egui/src/editing/close.rs +++ b/crates/ui-egui/src/editing/close.rs @@ -164,7 +164,10 @@ impl PdfCraftApp { close_root_window(ctx); return true; } - self.begin_close(ctx, CloseScope::Quit, dirty); + // A second quit while the quit is asking leaves the question as it is, as a second close of the window does. + if !self.close_guard.as_ref().is_some_and(|g| g.scope() == CloseScope::Quit) { + self.begin_close(ctx, CloseScope::Quit, dirty); + } ctx.request_repaint(); false } diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index b69ebd80c4..058f93e98f 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -420,6 +420,13 @@ pub(crate) fn frame(app: &mut PdfCraftApp, ctx: &egui::Context) { } app.drain_reveals(); app.settle_panes(ctx); + // A tab off screen runs no page view this frame, so no pass records its gestures. + let shown = app.views_on_screen(); + for (i, view) in app.views.iter_mut().enumerate() { + if !shown.contains(&i) { + view.left_screen(); + } + } } /// The page area: the main pane's tab (Home or Combine files while it has none, a comparison's diff --git a/crates/ui-egui/src/tools/object_ui.rs b/crates/ui-egui/src/tools/object_ui.rs index 1b22fa9cd5..59ad5290e1 100644 --- a/crates/ui-egui/src/tools/object_ui.rs +++ b/crates/ui-egui/src/tools/object_ui.rs @@ -226,19 +226,13 @@ fn object_at(xf: &PageXform, info: &DocInfo, page: usize, objects: &[EditableObj /// notice that the page's objects can't be selected together. `false` where no object lies (the /// press starts an area selection that adds to them) and off the page. pub(crate) fn modified_press_at(session: &mut PageSession, doc: &Document, info: &DocInfo, page: usize, xf: &PageXform, p: Pos2) -> bool { - if !xf.rect.contains(p) { - return false; - } - if session.content.draft.is_some() || session.line_editor.as_ref().is_some_and(|e| e.has_changes()) { - session.objects.notice = Some(tl!("Finish or discard the text being edited before selecting several objects.").into()); - return true; - } - let objects = match session.objects.inventory(doc, page) { - Ok(objects) => objects, - Err(_) => { - session.objects.notice = Some(tl!("This page contains objects that cannot be selected together.").into()); + let objects = match modified_target(session, doc, page, xf, p) { + ModifiedTarget::None => return false, + ModifiedTarget::Refused(notice) => { + session.objects.notice = Some(notice.into()); return true; } + ModifiedTarget::Objects(objects) => objects, }; let Some(object) = object_at(xf, info, page, &objects, p).and_then(|t| objects.iter().find(|o| o.target == t)) else { return false; @@ -268,9 +262,36 @@ pub(crate) fn modified_press_at(session: &mut PageSession, doc: &Document, info: // PLAN: contract A-6 gives `Option`; a modified press never makes an edit and the caller needs to know it was taken pub(crate) fn modified_press(session: &mut PageSession, doc: &Document, info: &DocInfo, press: &PagePress, geo: PageGeometry<'_>) -> bool { let Some(xf) = session.page_xform(press.page, geo) else { return false }; - match press.phase.start() { - Some(start) if matches!(press.phase, PressPhase::Down { .. }) => modified_press_at(session, doc, info, press.page, &xf, start.origin), - _ => false, + match press.phase { + PressPhase::Down { start, .. } => modified_press_at(session, doc, info, press.page, &xf, start.origin), + // The rest of a press its Down took is the toggle's too: its release is no click on what lies under it + // (a click on added text would open it for typing). + _ => press.phase.start().is_some_and(|start| match modified_target(session, doc, press.page, &xf, start.origin) { + ModifiedTarget::None => false, + ModifiedTarget::Refused(_) => true, + ModifiedTarget::Objects(objects) => object_at(&xf, info, press.page, &objects, start.origin).is_some(), + }), + } +} + +/// What a modified press at `p` on `page` meets: nothing it takes (off the page), a refusal with its +/// notice, or the page's objects to toggle one of. +enum ModifiedTarget { + None, + Refused(&'static str), + Objects(Vec), +} + +fn modified_target(session: &mut PageSession, doc: &Document, page: usize, xf: &PageXform, p: Pos2) -> ModifiedTarget { + if !xf.rect.contains(p) { + return ModifiedTarget::None; + } + if session.content.draft.is_some() || session.line_editor.as_ref().is_some_and(|e| e.has_changes()) { + return ModifiedTarget::Refused(tl!("Finish or discard the text being edited before selecting several objects.")); + } + match session.objects.inventory(doc, page) { + Ok(objects) => ModifiedTarget::Objects(objects), + Err(_) => ModifiedTarget::Refused(tl!("This page contains objects that cannot be selected together.")), } } diff --git a/crates/ui-egui/src/workflows/combine_ui/tests.rs b/crates/ui-egui/src/workflows/combine_ui/tests.rs index eaa87c759c..47cd79b273 100644 --- a/crates/ui-egui/src/workflows/combine_ui/tests.rs +++ b/crates/ui-egui/src/workflows/combine_ui/tests.rs @@ -232,6 +232,12 @@ fn a_password_answered_after_combine_opens_behind_the_combine_tab() { assert!(app.combine_showing()); app.submit_password(&egui::Context::default(), Some("pw".into())); assert!(app.password_prompt.is_none()); + // The unlocked document opens through the open queue, which the host's threads run. + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); + while app.views.is_empty() && std::time::Instant::now() < deadline { + app.poll_pending_opens(&egui::Context::default()); + std::thread::sleep(std::time::Duration::from_millis(5)); + } assert_eq!(app.views.len(), 1, "the document is open"); assert!(app.combine_showing(), "and the Combine files tab still shows"); diff --git a/crates/ui-egui/src/workflows/files.rs b/crates/ui-egui/src/workflows/files.rs index 152990d752..7ec9143882 100644 --- a/crates/ui-egui/src/workflows/files.rs +++ b/crates/ui-egui/src/workflows/files.rs @@ -159,11 +159,12 @@ fn name_of(path: &std::path::Path) -> String { path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_else(|| "file.pdf".into()) } -/// A picked file's name and bytes, or its name and why it can't be read. +/// A picked file's name and bytes, read through the host's file service as every pick is, or its +/// name and why it can't be read. #[cfg(not(target_arch = "wasm32"))] -fn read_named(path: &std::path::Path) -> Result<(String, Vec), (String, String)> { +fn read_named(host: &craft::host::Host, path: &std::path::Path) -> Result<(String, Vec), (String, String)> { let name = name_of(path); - match std::fs::read(path) { + match host.files().read(path) { Ok(bytes) => Ok((name, bytes)), Err(e) => Err((name, e.to_string())), } @@ -241,13 +242,15 @@ impl PdfCraftApp { if purpose == FilePurpose::CreateMultiple { // Each file is read when its turn comes, so the selection's bytes are not all held at once. if !paths.is_empty() { - self.stage_create_multiple(paths.iter().map(|p| read_named(p))); + let host = self.host.clone(); + self.stage_create_multiple(paths.iter().map(|p| read_named(&host, p))); } return; } if purpose == FilePurpose::CreateMultipleSeparate { if !paths.is_empty() { - self.ask_separate_folder(paths.to_vec().into_iter().map(|p| read_named(&p))); + let host = self.host.clone(); + self.ask_separate_folder(paths.to_vec().into_iter().map(move |p| read_named(&host, &p))); } return; } diff --git a/crates/ui-egui/src/workflows/ocr_verify/panes.rs b/crates/ui-egui/src/workflows/ocr_verify/panes.rs index fd29810fa8..95e7b5faa9 100644 --- a/crates/ui-egui/src/workflows/ocr_verify/panes.rs +++ b/crates/ui-egui/src/workflows/ocr_verify/panes.rs @@ -13,6 +13,7 @@ use craft::ui::layout_components::{Row, Stack}; use craft::ui::list::{List, ListRow, ThumbAspect}; use craft::ui::patterns::panels::Inspector; use craft::ui::primitives::textures::TextureState; +use craft::ui::runtime::focus::FocusRequest; use craft::ui::text::{RunWord, TextField, WordRun, WordState}; use egui::Rect; use pdfcraft_engine::ocr::{OcrPage, is_suspect}; @@ -51,7 +52,10 @@ pub(super) fn pages(app: &PdfCraftApp, ui: &mut egui::Ui, n: &mut Intents) { let v = &app.ocr_verify; let rows = PageRows(&v.pages); // The pane's panel scrolls its body, so the list takes its natural height and the panel carries the scroll. + // The screen's keys (F8) reach it while focus is inside it: the list takes the focus nothing else holds, so + // they work from the moment the screen opens, as they always did. let out = List::::new(tl!("Pages")) + .request_focus(FocusRequest::WhenNone) .select(SelectMode::Single) .selection(Bind::given(Selection::single(v.current))) .natural_height(true) diff --git a/crates/ui-egui/tests/it/accessibility.rs b/crates/ui-egui/tests/it/accessibility.rs index e1467882f1..ba1c5e63a3 100644 --- a/crates/ui-egui/tests/it/accessibility.rs +++ b/crates/ui-egui/tests/it/accessibility.rs @@ -326,7 +326,8 @@ fn setting_alternate_text_figure_by_figure() { h.run_steps(2); h.get_by_role_and_label(Role::Dialog, "Set Alternate Text"); h.get_by_label("Figure 1 of 2 on page 1"); - let field = h.get_by_role_and_label(Role::TextInput, "Alternate text"); + // The alternate text box takes several lines. + let field = h.get_by_role_and_label(Role::MultilineTextInput, "Alternate text"); field.focus(); field.type_text("A grey square"); h.run_steps(2); diff --git a/crates/ui-egui/tests/it/control.rs b/crates/ui-egui/tests/it/control.rs index bd3f294409..bccc405b71 100644 --- a/crates/ui-egui/tests/it/control.rs +++ b/crates/ui-egui/tests/it/control.rs @@ -1627,11 +1627,12 @@ fn control_open_of_an_already_open_file_replies_ok_and_focuses_its_tab() { }); h.run_steps(4); let c = tx; - // This test pins the synchronous open contract (focus vs open vs failure): the open job is - // run before the reply is read. A live app replies `pending` instead (#1620). + // Opens go through the open queue: the first two are accepted, then open once their jobs run (#1620). let first = call_running(&mut h, &c, &jobs, "ui.open", json!({ "path": a })).unwrap(); - assert_eq!(first["opened"], json!(a), "{first}"); + assert_eq!(first["accepted"], json!(a), "{first}"); call_running(&mut h, &c, &jobs, "ui.open", json!({ "path": b })).unwrap(); + run_jobs(&mut h, &jobs); + assert_eq!(h.state().views.len(), 2, "both files are open"); // The file is already open: the tab focuses, and the reply must be Ok — an agent driving the // app headlessly would otherwise read a focus as a read failure (#1620). let again = call_running(&mut h, &c, &jobs, "ui.open", json!({ "path": a })).unwrap(); @@ -1900,11 +1901,12 @@ fn control_collapses_and_expands_a_pinned_folder() { run_jobs(&mut h, &jobs); let folded = |h: &mut Harness<'static, PdfCraftApp>| ok(h, &c, "ui.state", json!({}))["pinned_folders"].clone(); assert_eq!(folded(&mut h), json!([{ "folder": folder, "collapsed": false }])); - h.get_by_label("inside.pdf"); + // A file's row is named by the file, then when it changed and its size. + h.get_by_label_contains("inside.pdf"); ok(&mut h, &c, "ui.set", json!({ "key": "folder-collapsed", "value": format!("{folder}=on") })); run_jobs(&mut h, &jobs); assert_eq!(folded(&mut h), json!([{ "folder": folder, "collapsed": true }])); - assert!(h.query_by_label("inside.pdf").is_none(), "a collapsed folder lists nothing"); + assert!(h.query_by_label_contains("inside.pdf").is_none(), "a collapsed folder lists nothing"); let unpinned = call(&mut h, &c, "ui.set", json!({ "key": "folder-collapsed", "value": "/not/pinned=on" })).unwrap_err(); assert!(unpinned.contains("not a pinned folder"), "{unpinned}"); let bad = call(&mut h, &c, "ui.set", json!({ "key": "folder-collapsed", "value": format!("{folder}=yes") })).unwrap_err(); @@ -1913,7 +1915,7 @@ fn control_collapses_and_expands_a_pinned_folder() { ok(&mut h, &c, "ui.set", json!({ "key": "folder-collapsed", "value": format!("{folder}=off") })); run_jobs(&mut h, &jobs); assert_eq!(folded(&mut h), json!([{ "folder": folder, "collapsed": false }])); - h.get_by_label("inside.pdf"); + h.get_by_label_contains("inside.pdf"); let _ = std::fs::remove_dir_all(&dir); } diff --git a/crates/ui-egui/tests/it/create.rs b/crates/ui-egui/tests/it/create.rs index 9dc370fee9..793def5e1b 100644 --- a/crates/ui-egui/tests/it/create.rs +++ b/crates/ui-egui/tests/it/create.rs @@ -68,10 +68,10 @@ fn image_import_dialog_chooses_dpi_and_cancels() { field.focus(); h.key_press_modifiers(Modifiers::COMMAND, Key::A); h.get_all_by_label("DPI").find(|n| n.accesskit_node().role() != Role::Group).expect("the DPI field").type_text("144"); + // Enter in the field is the dialog's default action, Create. h.key_press(Key::Enter); - h.run_steps(2); - h.get_by_label("Create").click(); h.run_steps(3); + assert!(h.state().image_import.is_none(), "Enter creates the PDF"); let page = &h.state().session.docs()[1].info.pages[0]; assert_eq!((page.width, page.height), (4.0, 2.0)); h.state_mut().begin_image_import(&ctx, vec![("scan.png".into(), png())]); diff --git a/crates/ui-egui/tests/it/document_links.rs b/crates/ui-egui/tests/it/document_links.rs index f50b094f9c..ca9583297b 100644 --- a/crates/ui-egui/tests/it/document_links.rs +++ b/crates/ui-egui/tests/it/document_links.rs @@ -628,7 +628,8 @@ fn an_absolute_gotor_waits_for_consent_and_keeps_its_destination_across_tabs() { let pending = h.state().pending_remote_link.as_ref().unwrap(); assert_eq!(pending.source, source); assert_eq!(pending.path, target); - h.get_by_label(file); + // The path is an isolate of its own, so it reads left to right in any interface language. + h.get_by_label_contains(file); h.get_by_label("Allow"); assert_eq!(h.state().views.len(), 1); assert_eq!(h.state().session.docs().len(), 1); diff --git a/crates/ui-egui/tests/it/pickers.rs b/crates/ui-egui/tests/it/pickers.rs index 1420403401..a4392270f2 100644 --- a/crates/ui-egui/tests/it/pickers.rs +++ b/crates/ui-egui/tests/it/pickers.rs @@ -583,10 +583,14 @@ fn a_watermark_file_from_browse_lands_only_in_the_dialog_that_asked() { assert!(h.query_by_label("Browse…").is_none(), "the dialog is closed"); } h.answer(Picked::Paths(vec![file.clone()])); + // The picked file is the File box's text. + let file_box = |h: &Rig| { + h.query_all_by(|n| n.role() == egui::accesskit::Role::TextInput && n.value().is_some_and(|v| v.contains("mark.pdf"))).next().is_some() + }; if keep_open { - assert!(h.query_by_label_contains("mark.pdf").is_some(), "the open dialog gets the file"); + assert!(file_box(&h), "the open dialog gets the file"); } else { - assert!(h.query_by_label_contains("mark.pdf").is_none(), "a closed dialog's pick is dropped"); + assert!(!file_box(&h), "a closed dialog's pick is dropped"); } } let _ = std::fs::remove_dir_all(&dir); diff --git a/crates/ui-egui/tests/it/signing.rs b/crates/ui-egui/tests/it/signing.rs index 3dafa0454c..16e930aafa 100644 --- a/crates/ui-egui/tests/it/signing.rs +++ b/crates/ui-egui/tests/it/signing.rs @@ -177,8 +177,15 @@ fn sign_with_created_id(h: &mut Harness<'static, PdfCraftApp>, dir: &std::path:: } fn trust_signer_and_inspect_certificate(h: &mut Harness<'static, PdfCraftApp>) { - // Signatures panel: expand, trust the signer → valid. - h.get_by_label_contains("Signed by Grace Hopper").click(); + // Signatures panel: expand, trust the signer → valid. The head row is the panel list's item. + { + use egui::accesskit::Role; + let roles: Vec = h.query_all_by_label_contains("Signed by Grace Hopper").map(|n| n.accesskit_node().role()).collect(); + h.query_all_by_label_contains("Signed by Grace Hopper") + .find(|n| matches!(n.accesskit_node().role(), Role::ListItem | Role::TreeItem | Role::Row)) + .unwrap_or_else(|| panic!("the signature's row in the Signatures panel, among {roles:?}")) + .click(); + } h.run_steps(2); h.get_by_label("Signature validity is UNKNOWN:"); // Seed a find so the trust path proves it invalidates the view: trust rebuilds @@ -365,8 +372,10 @@ fn save_as_keeps_a_signed_document_incremental() { }; assert_eq!(status(&h), Some(SignatureStatus::Valid)); let ctx_h = h.ctx.clone(); - assert!(h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::As), "a signed document can be saved as a copy"); - let saved = files.file(&out).expect("file written"); + // Save As asks where first, and writes once the answer arrives on a later pass. + h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::As); + h.run_steps(4); + let saved = files.file(&out).expect("a signed document can be saved as a copy"); assert!(saved.starts_with(&signed), "the signed revision is kept as it was"); assert_eq!(status(&h), Some(SignatureStatus::Valid)); } @@ -421,8 +430,10 @@ fn save_as_appends_to_a_document_whose_field_walk_passes_a_signature_over() { let ctx_h = h.ctx.clone(); assert!(h.state_mut().apply_edit(&ctx_h, pdfcraft_engine::Edit::AddAnnotation(note))); let ctx_h = h.ctx.clone(); - assert!(h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::As), "the document can be saved as a copy"); - let saved = files.file(&out).expect("file written"); + // Save As asks where first, and writes once the answer arrives on a later pass. + h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::As); + h.run_steps(4); + let saved = files.file(&out).expect("the document can be saved as a copy"); assert!(saved.starts_with(&original), "Save As rewrote the file instead of appending to it"); let mut s = pdfcraft_engine::Session::new(); let id = s.open("copy.pdf", None, std::sync::Arc::new(saved), None).expect("the copy opens"); @@ -494,9 +505,8 @@ fn sign_the_empty_field(h: &mut Harness<'static, PdfCraftApp>) { /// Whether the page's hover tip shows and says `text`. fn tip_says(h: &Harness<'static, PdfCraftApp>, text: &str) -> bool { - let layer = egui::LayerId::new(egui::Order::Tooltip, egui::Id::unique("canvas-hover")); - let Some(tip) = h.ctx.memory(|m| m.area_rect(egui::Id::unique("canvas-hover")).filter(|_| m.areas().is_visible(&layer))) else { return false }; - h.query_all_by_label_contains(text).any(|n| tip.contains(n.rect().center())) + let tips: Vec = h.query_all_by_role(egui::accesskit::Role::Tooltip).map(|n| n.rect()).collect(); + h.query_all_by_label_contains(text).any(|n| tips.iter().any(|tip| tip.contains(n.rect().center()))) } /// A signed field's validation badge is the viewer's own mark, not part of the page: its verdict @@ -750,8 +760,10 @@ fn os_store_identities_are_not_persisted() { } let saved = app.settings_snapshot(); let settings = serde_json::to_value(&saved).unwrap(); - assert_eq!(settings["digital_ids"].as_array().unwrap().len(), 1); - assert_eq!(settings["digital_ids"][0]["path"], "file-id.p12"); + // Digital IDs are kept in the settings' signature table. + let ids = &settings["signature"]["digital_ids"]; + assert_eq!(ids.as_array().unwrap().len(), 1); + assert_eq!(ids[0]["path"], "file-id.p12"); let mut restored = crate::control::new_app(); restored.set_option(&egui::Context::default(), "language", "en").unwrap(); restored.apply_settings(&saved); diff --git a/crates/ui-egui/tests/it/updates.rs b/crates/ui-egui/tests/it/updates.rs index 6d09e22403..61b1e2bbe0 100644 --- a/crates/ui-egui/tests/it/updates.rs +++ b/crates/ui-egui/tests/it/updates.rs @@ -182,7 +182,8 @@ fn settings_from_the_old_opt_in_leave_the_check_at_start_on() { } /// An app with an unsaved change to a form in a new temporary folder, which Save writes without -/// asking where; its update check dialog is open. Returns the document's path too. +/// asking where; its update has installed and the check dialog says so. Returns the document's +/// path too. fn app_with_unsaved_file(test: &str) -> (Harness<'static, PdfCraftApp>, PathBuf) { let dir = std::env::temp_dir().join(format!("pdfcraft-ui-updates-{test}-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); @@ -190,7 +191,14 @@ fn app_with_unsaved_file(test: &str) -> (Harness<'static, PdfCraftApp>, PathBuf) let path = dir.join("source.pdf"); let bytes = include_bytes!("../data/form.pdf").to_vec(); std::fs::write(&path, &bytes).unwrap(); - let mut h = harness(Ok(None)); + let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(move |cc| { + crate::support::install_runtime(&cc.egui_ctx); + let updater = craft::update::updater::Updater::ready_for_tests(&pdfcraft_ui_egui::UPDATE_APP, "0.1.0", release("v99.0.0"), || Ok(())); + let host = Arc::new(Host::builder(info()).build()); + let mut app = PdfCraftApp::with_host(host, services_asking(None).with_updater(updater)); + app.set_option(&egui::Context::default(), "language", "en").unwrap(); + app + }); h.run_steps(2); let app = h.state_mut(); app.open_bytes(&egui::Context::default(), "source.pdf", Some(path.to_string_lossy().into_owned()), bytes).unwrap(); diff --git a/crates/ui-egui/tests/it/view.rs b/crates/ui-egui/tests/it/view.rs index 3c0941d8d2..114abf14e0 100644 --- a/crates/ui-egui/tests/it/view.rs +++ b/crates/ui-egui/tests/it/view.rs @@ -2276,6 +2276,7 @@ fn the_pages_panel_tools_insert_from_a_file_and_extract() { craft::host::Picked::Paths(vec![more.clone()]), craft::host::Picked::Paths(vec![out.clone()]), ])); + let host_files = files.clone(); let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |cc| { crate::support::install_runtime(&cc.egui_ctx); { @@ -2307,7 +2308,9 @@ fn the_pages_panel_tools_insert_from_a_file_and_extract() { h.get_by_label("Extract pages as separate files").click(); h.run_steps(2); h.get_all_by_label("Extract").last().unwrap().click(); - assert!(crate::support::step_until(&mut h, |_| std::fs::read_dir(&out).is_ok_and(|d| d.count() == 2)), "the two selected pages, each a file"); + // The files are written through the host's file service. + let extracted = |out: &std::path::Path| host_files.written().iter().filter(|p| p.parent() == Some(out)).count(); + assert!(crate::support::step_until(&mut h, |_| extracted(&out) == 2), "the two selected pages, each a file"); let _ = std::fs::remove_dir_all(&dir); }