mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 03:49:11 +00:00
pdf-comments-w15: net change of 3 commits
- pdf-comments-w15: written by an agent - pdf-comments-w15: finished by an agent - pdf-comments-w15: review fixes (review-1)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
//! The annotation quick bar's pin is a preference, including across older settings files.
|
||||
//! The annotation quick bar's pin is a preference that survives a restart.
|
||||
|
||||
use egui::{Pos2, pos2};
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
use pdfcraft_ui_egui::{PdfCraftApp, QuickTool, comments::CommentTool};
|
||||
use serde_json::{Value, json};
|
||||
// PLAN: path of `PdfCraftSettings` assumed to be the crate root (pdf-shell-w9).
|
||||
use pdfcraft_ui_egui::{PdfCraftApp, PdfCraftSettings, QuickTool, comments::CommentTool};
|
||||
|
||||
// Contributor-original blank page: no document assets or fonts are needed.
|
||||
const PDF: &[u8] = b"%PDF-1.7
|
||||
@@ -21,12 +21,12 @@ startxref
|
||||
186
|
||||
%%EOF";
|
||||
|
||||
/// Start a fresh shell with the state a previous process saved.
|
||||
fn harness(saved: Option<String>) -> Harness<'static, PdfCraftApp> {
|
||||
/// Start a fresh shell with the settings a previous process saved.
|
||||
fn harness(saved: Option<PdfCraftSettings>) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = PdfCraftApp::new();
|
||||
if let Some(saved) = saved {
|
||||
app.restore(&saved);
|
||||
if let Some(saved) = &saved {
|
||||
app.apply_settings(saved);
|
||||
}
|
||||
app.set_option("language", "en").unwrap();
|
||||
app.set_option("author", "Tester").unwrap();
|
||||
@@ -75,7 +75,7 @@ fn pin_from_quick_bar_survives_restart_and_unpinning() {
|
||||
assert!(doc.repair_log().is_empty(), "the synthetic page opens without repair");
|
||||
assert_eq!(doc.bytes.as_slice(), PDF, "changing this preference leaves the PDF unchanged");
|
||||
assert!(!doc.dirty);
|
||||
let saved = h.state().persist();
|
||||
let saved = h.state().settings_snapshot();
|
||||
drop(h);
|
||||
|
||||
let mut h = harness(Some(saved));
|
||||
@@ -90,72 +90,14 @@ fn pin_from_quick_bar_survives_restart_and_unpinning() {
|
||||
h.run_steps(3);
|
||||
assert!(!h.state().comment_prefs.pinned);
|
||||
shot(&mut h, "pin-disabled.png");
|
||||
let saved = h.state().persist();
|
||||
let saved = h.state().settings_snapshot();
|
||||
callout(&mut h, 60.0);
|
||||
crate::support::wait_until(&mut h, "the unpinned callout returning to Select", |app| {
|
||||
app.session.get(app.views[0].id).unwrap().info.annotations.len() == 2 && matches!(app.quick_tool, QuickTool::Select)
|
||||
});
|
||||
assert!(!matches!(h.state().quick_tool, QuickTool::Comment(_)), "unpinning restores one-shot use");
|
||||
drop(h);
|
||||
|
||||
let mut restored = PdfCraftApp::new();
|
||||
restored.comment_prefs.pinned = true;
|
||||
restored.restore(&saved);
|
||||
assert!(!restored.comment_prefs.pinned, "unpinning survives the next restart too");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_pin_round_trips_both_boolean_values() {
|
||||
for pinned in [true, false] {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.comment_prefs.pinned = pinned;
|
||||
let saved = app.persist();
|
||||
let value: Value = serde_json::from_str(&saved).unwrap();
|
||||
assert_eq!(value["comment_tool_pinned"], json!(pinned));
|
||||
let mut restored = PdfCraftApp::new();
|
||||
restored.comment_prefs.pinned = !pinned;
|
||||
restored.restore(&saved);
|
||||
assert_eq!(restored.comment_prefs.pinned, pinned);
|
||||
assert!(matches!(restored.quick_tool, QuickTool::Select), "remembering the pin does not select a drawing tool at startup");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restoring_explicit_pin_choice_overrides_current_choice() {
|
||||
for pinned in [true, false] {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.comment_prefs.pinned = !pinned;
|
||||
app.restore(&json!({"comment_tool_pinned": pinned}).to_string());
|
||||
assert_eq!(app.comment_prefs.pinned, pinned);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_settings_keep_the_default_and_other_preferences() {
|
||||
let mut app = PdfCraftApp::new();
|
||||
assert!(!app.comment_prefs.pinned);
|
||||
let legacy = r#"{"author":"Legacy reviewer","comment_styles":[{"tool":"comment.line","color":[0.25,0.5,1.0]}]}"#;
|
||||
app.restore(legacy);
|
||||
assert!(!app.comment_prefs.pinned, "old settings retain the default one-shot behavior");
|
||||
assert_eq!(app.comment_prefs.author, "Legacy reviewer");
|
||||
assert_eq!(app.comment_prefs.style(CommentTool::Line).color, [0.25, 0.5, 1.0]);
|
||||
app.comment_prefs.pinned = true;
|
||||
app.restore(legacy);
|
||||
assert!(app.comment_prefs.pinned, "a partial restore without this key leaves the current choice alone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_pin_values_preserve_the_current_choice() {
|
||||
for pinned in [false, true] {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.comment_prefs.pinned = pinned;
|
||||
for value in [json!(null), json!(0), json!(1), json!(-1), json!("true"), json!("false"), json!([]), json!({})] {
|
||||
app.restore(&json!({"comment_tool_pinned": value, "author": "Still restored"}).to_string());
|
||||
assert_eq!(app.comment_prefs.pinned, pinned, "invalid pin value: {value}");
|
||||
assert_eq!(app.comment_prefs.author, "Still restored", "other valid preferences still restore");
|
||||
}
|
||||
for invalid in ["", "{", r#"{"comment_tool_pinned":true"#, "[]", "null", "false", "0"] {
|
||||
app.restore(invalid);
|
||||
assert_eq!(app.comment_prefs.pinned, pinned);
|
||||
}
|
||||
}
|
||||
let h = harness(Some(saved));
|
||||
assert!(!h.state().comment_prefs.pinned, "unpinning survives the next restart too");
|
||||
}
|
||||
|
||||
+763
-1729
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user