diff --git a/crates/ui-egui/src/editing/tests.rs b/crates/ui-egui/src/editing/tests.rs index 02a79d4ef4..eb3be197c6 100644 --- a/crates/ui-egui/src/editing/tests.rs +++ b/crates/ui-egui/src/editing/tests.rs @@ -24,10 +24,11 @@ fn staging_dir(test: &str) -> PathBuf { /// The app on a host whose picks wait until the test answers them, in a window: the save flow /// takes a pick's answer on a pass, as it does for the user. -fn shown_with_picks() -> (Harness<'static, crate::PdfCraftApp>, Arc) { +fn shown_with_picks() -> (Harness<'static, crate::PdfCraftApp>, Arc, Arc) { let files = Arc::new(ScriptedFiles::held()); + let jobs = Arc::new(ManualJobs::new()); let info = AppInfo { id: "pdfcraft", name: "PdfCraft", version: env!("CARGO_PKG_VERSION") }; - let host = Host::builder(info).jobs(Arc::new(ManualJobs::new())).files(files.clone()).build(); + let host = Host::builder(info).jobs(jobs.clone()).files(files.clone()).build(); let (intake, _) = craft::platform::open::FileIntake::new(Wake::none()); let clipboard = craft::platform::clipboard::Clipboard::new(craft::platform::clipboard::EventClipboard::new(|| 0, |_| Ok(0))); let watch = craft::platform::watch::FileWatch::new(Wake::none()).inline(); @@ -41,13 +42,17 @@ fn shown_with_picks() -> (Harness<'static, crate::PdfCraftApp>, Arc, files: &ScriptedFiles, path: &Path) { +/// Answers the open Save picker with `path`, and lets the app take the answer on later passes and run the +/// jobs it starts for the write. +fn answer_save(h: &mut Harness<'static, crate::PdfCraftApp>, files: &ScriptedFiles, jobs: &ManualJobs, path: &Path) { assert!(files.answer(Picked::Paths(vec![path.to_path_buf()])).is_some(), "a Save picker was open"); - h.run_steps(3); + for _ in 0..6 { + jobs.run_all(); + h.run_steps(1); + } } /// A one-page document with a proper xref table. @@ -105,7 +110,7 @@ fn a_refused_text_box_is_put_back_whole() { fn save_commits_the_open_text_box() { let dir = staging_dir("open-text-box"); let dest = dir.join("out.pdf"); - let (mut h, files) = shown_with_picks(); + let (mut h, files, jobs) = shown_with_picks(); let app = h.state_mut(); app.open_bytes(&egui::Context::default(), "a.pdf", None, one_page_pdf()).unwrap(); let style = crate::content_ui::default_style(); @@ -118,7 +123,7 @@ fn save_commits_the_open_text_box() { let added = app.session.get(id).unwrap().added(); assert_eq!(added.len(), 1, "the open text box was committed before the save"); assert!(app.views[0].session.content.draft.is_none()); - answer_save(&mut h, &files, &dest); + answer_save(&mut h, &files, &jobs, &dest); assert!(std::fs::read(&dest).unwrap().starts_with(b"%PDF"), "the document with its text went where the user chose"); assert!(!h.state().session.get(id).unwrap().dirty); let _ = std::fs::remove_dir_all(&dir); @@ -185,13 +190,13 @@ fn save_asks_where_to_keep_an_email_attachment_and_leaves_the_temporary_copy_alo std::fs::write(&attachment, &original).unwrap(); let kept = dir.join("Quote.pdf"); - let (mut h, files) = shown_with_picks(); + let (mut h, files, jobs) = shown_with_picks(); let app = h.state_mut(); app.open_bytes(&egui::Context::default(), "Quote.pdf", Some(attachment.to_string_lossy().into_owned()), original.clone()).unwrap(); assert!(app.apply_edit(&egui::Context::default(), pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 })); assert!(!app.save_active(&egui::Context::default(), SaveTarget::InPlace), "Save asks instead of writing the temporary copy"); - answer_save(&mut h, &files, &kept); + answer_save(&mut h, &files, &jobs, &kept); assert_eq!(std::fs::read(&attachment).unwrap(), original, "the attachment's copy is untouched"); assert!(std::fs::read(&kept).unwrap().starts_with(b"%PDF"), "the document went where the user chose"); diff --git a/crates/ui-egui/src/workflows/print_ui/dialog.rs b/crates/ui-egui/src/workflows/print_ui/dialog.rs index eb600ffca2..8804f1fa60 100644 --- a/crates/ui-egui/src/workflows/print_ui/dialog.rs +++ b/crates/ui-egui/src/workflows/print_ui/dialog.rs @@ -157,7 +157,12 @@ impl PdfCraftApp { } /// Asks for a fresh printer list: the app's source reads it in the background, without one the spooler is asked now. + /// A list already being read is the fresh one (the dialog's first pass asks too, as `State::refresh` refuses to + /// while it discovers): reading again would replace the job that owns the dialog's receiver. fn refresh_printers(&mut self) { + if self.dialogs.get::().is_some_and(|dialog| dialog.state().discovering()) { + return; + } #[cfg(not(target_arch = "wasm32"))] if self.printer_source.is_some() { let receiver = self.list_printers(); diff --git a/crates/ui-egui/tests/it/combine_grid.rs b/crates/ui-egui/tests/it/combine_grid.rs index 22a92f8fd2..3ad287ad1d 100644 --- a/crates/ui-egui/tests/it/combine_grid.rs +++ b/crates/ui-egui/tests/it/combine_grid.rs @@ -6,6 +6,7 @@ use std::time::Duration; use crate::support::AppHarness as _; use craft::ui::primitives::textures::{TextureState, ThumbRequest}; use craft::ui::tile_grid::TileZoom; +use egui::accesskit::Role; use egui::{Key, Modifiers, Pos2, vec2}; use egui_kittest::Harness; use egui_kittest::kittest::{NodeT, Queryable}; @@ -331,7 +332,7 @@ fn combine_follows_the_order_shown_in_the_grid() { let (three, one) = (card(&h, "three.pdf"), card(&h, "one.pdf")); drag(&mut h, three.center(), one.center() - vec2(one.width() * 0.3, 0.0)); assert_eq!(names(&h), ["three.pdf", "one.pdf", "two.pdf"]); - h.get_by_label("Combine").click(); + h.get_by_role_and_label(Role::Button, "Combine").click(); h.run_steps(3); let app = h.state(); assert_eq!(app.views.len(), 1, "the result opens"); @@ -718,7 +719,7 @@ fn combining_with_files_expanded_gives_the_same_document() { h.get_by_label("Expand all").click(); h.run_steps(2); assert_eq!(h.state().combine_expanded(), [0, 1]); - h.get_by_label("Combine").click(); + h.get_by_role_and_label(Role::Button, "Combine").click(); h.run_steps(3); let app = h.state(); assert_eq!(app.views.len(), 1, "the result opens"); @@ -783,7 +784,7 @@ fn a_split_file_counts_once_and_combines_with_one_bookmark() { assert!(h.query_by_label_contains("Added more than once").is_none()); h.hover_at(egui::pos2(5.0, 890.0)); h.run_steps(2); - h.get_by_label("Combine").click(); + h.get_by_role_and_label(Role::Button, "Combine").click(); h.run_steps(3); let app = h.state(); assert_eq!(app.views.len(), 1, "the result opens"); @@ -861,7 +862,7 @@ fn a_files_parts_join_when_what_was_between_them_goes_and_one_file_cannot_be_com remove_hovered(&mut h); assert_eq!(parts(&h), ["one.pdf:[0, 1]"]); // One file is nothing to combine, however it is split. - assert!(h.get_by_label("Combine").accesskit_node().is_disabled()); + assert!(h.get_by_role_and_label(Role::Button, "Combine").accesskit_node().is_disabled()); h.key_press_modifiers(Modifiers::COMMAND, Key::Z); h.run_steps(2); assert_eq!(parts(&h), ["one.pdf:[0]", "two.pdf:[0]", "one.pdf:[1]"]); diff --git a/crates/ui-egui/tests/it/pageboxes.rs b/crates/ui-egui/tests/it/pageboxes.rs index 4abbe5b911..d9ea3f7546 100644 --- a/crates/ui-egui/tests/it/pageboxes.rs +++ b/crates/ui-egui/tests/it/pageboxes.rs @@ -1,6 +1,7 @@ //! Crop tool and Set Page Boxes in the real shell (egui_kittest). use crate::support::AppHarness as _; +use egui::accesskit::Role; use egui_kittest::Harness; use egui_kittest::kittest::Queryable; use pdfcraft_ui_egui::{PdfCraftApp, QuickTool}; @@ -84,7 +85,7 @@ fn set_page_boxes_dialog_applies_margins_to_the_chosen_pages() { let mut h = harness(); assert!(h.execute("page.boxes")); h.run_steps(3); - h.get_by_label("Set Page Boxes"); + h.get_by_role_and_label(Role::Dialog, "Set Page Boxes"); // One inch off every side (the units default to inches). for side in ["Top", "Bottom", "Left", "Right"] { h.get_by_label(side).click(); diff --git a/crates/ui-egui/tests/it/pointer.rs b/crates/ui-egui/tests/it/pointer.rs index 90a8269ea6..f029311068 100644 --- a/crates/ui-egui/tests/it/pointer.rs +++ b/crates/ui-egui/tests/it/pointer.rs @@ -196,6 +196,13 @@ fn open(pdf: Vec, zoom: &'static str, left_open: bool) -> Harness<'static, P h } +fn diag_pages(h: &Harness<'static, PdfCraftApp>) { + let thread = std::thread::current(); + let name = thread.name().and_then(|n| n.rsplit("::").next()).unwrap_or(""); + let v = &h.state().views[0]; + eprintln!("DIAG {name}: viewport {:?} placed {:?} gaps {}", v.viewport_rect(), v.visible_page_rects(), v.view.page_gaps); +} + fn stamp_tool(h: &mut Harness<'_, PdfCraftApp>) { h.state_mut().quick_tool = QuickTool::Stamp(StampKind::DynApproved); h.run_steps(4); @@ -214,8 +221,15 @@ fn at(h: &Harness<'_, PdfCraftApp>, x: f32, y: f32) -> egui::Pos2 { fn cursor_at(h: &mut Harness<'_, PdfCraftApp>, p: egui::Pos2) -> egui::CursorIcon { h.hover_at(p); - h.run_steps(2); - h.output().platform_output.cursor_icon + h.run_steps(1); + let first = h.output().platform_output.cursor_icon; + h.run_steps(1); + let second = h.output().platform_output.cursor_icon; + let thread = std::thread::current(); + let name = thread.name().and_then(|n| n.rsplit("::").next()).unwrap_or(""); + let (page, viewport) = (h.state().views[0].page_screen_rect(0), h.state().views[0].viewport_rect()); + eprintln!("DIAG {name}: cursor at {p:?}: {first:?} then {second:?}; page {page:?} viewport {viewport:?}"); + second } /// A mouse click: press and release in frames of their own, as `drag_at` and `drop_at` send them. @@ -1020,6 +1034,7 @@ fn drag_seen_only_past_page_ones_edge(tool: impl FnOnce(&mut PdfCraftApp)) -> Ha let mut h = open(two_pages_pdf(), "100", false); tool(h.state_mut()); h.run_steps(4); + diag_pages(&h); let (one, two) = { let v = &h.state().views[0]; (v.page_screen_rect(0).expect("page 1 on screen"), v.page_screen_rect(1).expect("page 2 on screen")) @@ -1367,6 +1382,7 @@ fn touching_pages(tool: impl FnOnce(&mut PdfCraftApp)) -> (Harness<'static, PdfC h.state_mut().views[0].view.page_gaps = false; tool(h.state_mut()); h.run_steps(4); + diag_pages(&h); let (one, two) = { let v = &h.state().views[0]; (v.page_screen_rect(0).expect("page 1 on screen"), v.page_screen_rect(1).expect("page 2 on screen")) diff --git a/crates/ui-egui/tests/it/print.rs b/crates/ui-egui/tests/it/print.rs index e51d32325b..8cc66e0e9b 100644 --- a/crates/ui-egui/tests/it/print.rs +++ b/crates/ui-egui/tests/it/print.rs @@ -933,8 +933,8 @@ fn print_restricted_documents_say_so_before_the_dialog() { }); h.ctx.set_os(egui::os::OperatingSystem::Windows); h.run_steps(4); - assert!(h.get_by_label("Print (Ctrl+P)").accesskit_node().is_disabled()); - h.get_by_label("Print (Ctrl+P)").hover(); + assert!(h.get_by_label("Print…").accesskit_node().is_disabled()); + h.get_by_label("Print…").hover(); h.run_steps(30); h.get_by_label_contains("don't allow printing"); assert!(!h.execute("print.dialog")); @@ -950,8 +950,8 @@ fn print_without_a_document_does_not_blame_security() { let mut h = rig_on(ScriptedFiles::new(), |_| {}); h.ctx.set_os(egui::os::OperatingSystem::Windows); h.run_steps(4); - assert!(h.get_by_label("Print (Ctrl+P)").accesskit_node().is_disabled()); - h.get_by_label("Print (Ctrl+P)").hover(); + assert!(h.get_by_label("Print…").accesskit_node().is_disabled()); + h.get_by_label("Print…").hover(); h.run_steps(30); assert!(h.query_by_label_contains("don't allow printing").is_none()); assert!(!h.is_open()); diff --git a/crates/ui-egui/tests/it/redact.rs b/crates/ui-egui/tests/it/redact.rs index db4a4a721c..6715f8bd72 100644 --- a/crates/ui-egui/tests/it/redact.rs +++ b/crates/ui-egui/tests/it/redact.rs @@ -6,6 +6,7 @@ use std::sync::Arc; use craft::host::{Picked, ScriptedFiles}; use egui::Pos2; +use egui::accesskit::Role; use egui_kittest::Harness; use egui_kittest::kittest::Queryable; use pdfcraft_ui_egui::{PdfCraftApp, SaveTarget}; @@ -81,6 +82,13 @@ fn marking_applying_and_clearing() { } h.drop_at(b); h.run_steps(4); + eprintln!( + "DIAG marking_applying_and_clearing: tool {:?} mode {:?} page {:?} from {a:?} to {b:?} cursor {:?}", + h.state().quick_tool, + h.state().mode, + h.state().views[0].page_screen_rect(0), + h.output().platform_output.cursor_icon + ); assert_eq!(marks(&h), 1); // Redact pages ▸ current page. h.execute("redact.pages"); @@ -372,7 +380,8 @@ fn undoing_saved_redactions_while_the_save_dialog_is_open_asks_again() { assert_eq!(h.state().views[0].redactions_undone_after_save, 1); let elsewhere = dir.join("contract_restored.pdf"); assert!(files.answer(Picked::Paths(vec![elsewhere.clone()])).is_some(), "Save asked again and waits for the user"); - h.run_steps(4); + // The write runs on a worker: step until it has landed. + crate::support::wait_until(&mut h, "the save to land", |_| files.file(&elsewhere).is_some()); assert_eq!(files.file(©).unwrap(), saved, "the redacted copy is left as it was"); assert!(files.file(&elsewhere).is_some(), "Save asked again and wrote where the user chose"); let _ = std::fs::remove_dir_all(&dir); @@ -406,7 +415,8 @@ fn undoing_apply_redactions_while_the_save_dialog_is_open_asks_again() { assert_eq!(h.state().views[0].redactions_applied, 0); let elsewhere = dir.join("contract_copy.pdf"); assert!(files.answer(Picked::Paths(vec![elsewhere.clone()])).is_some(), "Save asked again and waits for the user"); - h.run_steps(4); + // The write runs on a worker: step until it has landed. + crate::support::wait_until(&mut h, "the save to land", |_| files.file(&elsewhere).is_some()); assert!(files.file(©).is_none(), "the unredacted content is not saved under the _Redacted name"); assert!(files.file(&elsewhere).is_some(), "Save asked again and wrote where the user chose"); let _ = std::fs::remove_dir_all(&dir); @@ -509,7 +519,7 @@ fn redaction_codes_become_the_overlay_text() { let mut h = harness(); assert!(h.execute("redact.properties")); h.run_steps(2); - h.get_by_label("Redaction Tool Properties"); + h.get_by_role_and_label(Role::Dialog, "Redaction Tool Properties"); h.get_by_label("Use overlay text").click(); h.run_steps(2); h.get_by_label("Custom text").click(); @@ -604,9 +614,10 @@ fn redaction_properties_for_this_run_only_and_cancel() { assert!(h.execute("redact.properties")); h.run_steps(6); h.get_by_label("Redaction mark appearance"); - h.get_by_label("Outline colour:"); - h.get_by_label("Fill colour:"); - h.get_by_label("Opacity:"); + // A colour row's name labels both its text and its swatch button. + for row in ["Outline colour:", "Fill colour:", "Opacity:"] { + assert!(h.get_all_by_label(row).count() > 0, "{row} is offered"); + } h.get_by_label("Make properties default").click(); h.run_steps(3); assert!(!h.state().redact_props.as_ref().unwrap().remember); @@ -690,7 +701,7 @@ fn removing_hidden_information_and_sanitizing() { let mut h = harness(); h.execute("protect.remove_hidden"); h.run_steps(2); - h.get_by_label("Remove hidden information"); + h.get_by_role_and_label(Role::Dialog, "Remove hidden information"); { let d = h.state().hidden_draft.as_ref().unwrap(); let fields = d.found.iter().find(|f| f.0 == pdfcraft_engine::Hidden::FormFields).unwrap(); diff --git a/crates/ui-egui/tests/it/viewer_prefs.rs b/crates/ui-egui/tests/it/viewer_prefs.rs index e182c2f183..97823f8500 100644 --- a/crates/ui-egui/tests/it/viewer_prefs.rs +++ b/crates/ui-egui/tests/it/viewer_prefs.rs @@ -69,7 +69,7 @@ fn shown(h: &Harness<'static, PdfCraftApp>) -> (bool, bool, bool) { ( h.query_by_label("Find tools and commands").is_some(), h.query_by(|n| n.role() == egui::accesskit::Role::MenuItem && n.label().as_deref() == Some("File")).is_some(), - h.query_by_label("Toggle fit page / fit width").is_some(), + h.query_by_label("Toggle fit").is_some(), ) }