mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-14 19:27:04 -04:00
Tests: dropping a PDF on the window, and hovering a comment (two features now shipped)
Both features worked but had no test, so parity listed them as partial: - core.drag-drop-open: a file dropped on the window opens in a tab (ui.rs::dropping_a_pdf_on_the_window_opens_it, through egui's DroppedFile). - view.annotation-hover: hovering a comment shows a popup with its author and text (comments.rs::hovering_a_comment_shows_its_author_and_text). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
8703172692
commit
ead70695c8
3 files changed
+59
-6
No files matched your search
@@ -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");
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user