Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Drop: dropping an already-open document focuses its tab (#1620)

Eduardo Soaresa7160cf45c72
diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs
index 38cde809b..1e2df54bc 100644
--- a/crates/ui-egui/tests/ui.rs
+++ b/crates/ui-egui/tests/ui.rs
@@ -616,6 +616,29 @@ fn dropping_a_pdf_on_the_window_opens_it() {
h.get_by_label_contains("dropped.pdf");
}
+#[test]
+fn dropping_an_open_pdf_again_focuses_its_tab() {
+ let dir = std::env::temp_dir().join(format!("pdfcraft-drop-dedup-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(&dir).unwrap();
+ let path = dir.join("dropped.pdf");
+ std::fs::write(&path, FIXTURE).unwrap();
+ let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(|_cc| {
+ let mut app = PdfCraftApp::new();
+ app.set_option("language", "en").unwrap();
+ app
+ });
+ h.run_steps(3);
+ let file: egui::DroppedFileHandle = std::sync::Arc::new(Dropped { path: path.clone(), bytes: FIXTURE.to_vec() });
+ h.input_mut().dropped_files.push(file.clone());
+ h.run_steps(3);
+ assert_eq!(h.state().views.len(), 1, "the dropped PDF opens in a tab");
+ h.input_mut().dropped_files.push(file);
+ h.run_steps(3);
+ assert_eq!(h.state().views.len(), 1, "dropping it again adds no tab");
+ std::fs::remove_dir_all(&dir).unwrap();
+}
+
#[test]
fn a_file_dropped_on_the_page_grid_is_read_from_disk_and_inserted() {
// The grid's drop reads a file from its path when its turn to be inserted comes, and inserts it