PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Tests: dropping a PDF on the window, and hovering a comment (two features now shipped)
Brandon Thomasead70695c80b
diff --git a/crates/ui-egui/tests/comments.rs b/crates/ui-egui/tests/comments.rsindex 5ce5520e7..1fafe9a50 100644--- a/crates/ui-egui/tests/comments.rs+++ b/crates/ui-egui/tests/comments.rs@@ -529,3 +529,28 @@ fn erasing_part_of_a_drawing() {drag_pt(&mut h, (40.0, 60.0), (260.0, 60.0));assert!(comments(&h).is_empty(), "{:?}", comments(&h));}++#[test]+fn hovering_a_comment_shows_its_author_and_text() {+ // A square comment by Ada over the first page's text.+ let pdf = String::from_utf8_lossy(TEXT_FIXTURE).replace("/Contents 5 0 R /Resources", "/Contents 5 0 R /Annots [8 0 R] /Resources").replace(+ "trailer",+ "8 0 obj << /Type /Annot /Subtype /Square /Rect [50 50 150 120] /C [1 0 0] /T (Ada) /Contents (Check this figure) >> endobj\ntrailer",+ );+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {+ let mut app = PrintCraftApp::new();+ app.open_bytes("hover.pdf", None, pdf.into_bytes()).expect("opens");+ app.set_option("left", "closed").unwrap();+ // No Comments panel: the comment's text should only appear in the hover popup.+ app.set_option("panel", "none").unwrap();+ app+ });+ h.run_steps(4);+ settle(&mut h);+ assert!(h.query_by_label_contains("Check this figure").is_none(), "no popup before hovering");+ let p = at(&h, 100.0, 85.0);+ h.hover_at(p);+ h.run_steps(3);+ h.get_by_label_contains("Check this figure");+ h.get_by_label_contains("Ada");+}diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rsindex bab498b81..7fab48f5c 100644--- a/crates/ui-egui/tests/ui.rs+++ b/crates/ui-egui/tests/ui.rs@@ -212,3 +212,31 @@ fn selection_works_in_every_view_rotation() {assert_eq!(h.state().views[0].selected_text().as_deref(), Some("quick brown"), "rotation {deg}");}}++/// A file dropped on the window, as the windowing layer hands it over.+#[derive(Debug)]+struct Dropped {+ path: std::path::PathBuf,+ bytes: Vec<u8>,+}++impl egui::DroppedFile for Dropped {+ fn path(&self) -> &std::path::Path {+ &self.path+ }+ fn bytes(&self) -> Result<Vec<u8>, String> {+ Ok(self.bytes.clone())+ }+}++#[test]+fn dropping_a_pdf_on_the_window_opens_it() {+ let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(|_cc| PrintCraftApp::new());+ h.run_steps(3);+ assert!(h.state().views.is_empty());+ let file: egui::DroppedFileHandle = std::sync::Arc::new(Dropped { path: "dropped.pdf".into(), bytes: FIXTURE.to_vec() });+ h.input_mut().dropped_files.push(file);+ h.run_steps(3);+ assert_eq!(h.state().views.len(), 1, "the dropped PDF opens in a tab");+ h.get_by_label_contains("dropped.pdf");+}diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.tomlindex 8785afc5d..314e35322 100644--- a/parity/acrobat-features.toml+++ b/parity/acrobat-features.toml@@ -643,11 +643,11 @@ title = "Open files by drag and drop"area = "A"tier = "P1"milestone = "M3"-status = "partial"+status = "shipped"commands = []tools = []-evidence = []-notes = "desktop drop is handled; no test yet"+evidence = ["crates/ui-egui/tests/ui.rs::dropping_a_pdf_on_the_window_opens_it"]+notes = "desktop: the dropped file opens in a tab (by path, or its bytes); web: read asynchronously"[[feature]]id = "core.recent-files"@@ -1151,11 +1151,11 @@ title = "Show comment text on hover"area = "B"tier = "P1"milestone = "M3"-status = "partial"+status = "shipped"commands = []tools = []-evidence = []-notes = "no test yet"+evidence = ["crates/ui-egui/tests/comments.rs::hovering_a_comment_shows_its_author_and_text"]+notes = "a popup with the author and the comment text, as Acrobat shows"[[feature]]id = "view.document-tabs"