mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-31 21:48:09 -06:00
The ui-egui integration tests drive the shell by its English labels, and `i18n::system_lang` returns `Lang::EN` under `cfg!(test)` so they can. That only covers the unit tests: an integration test links the library as it ships, where `cfg!(test)` is off, so `PdfCraftApp::new()` leaves `language` on `auto` and the shell is drawn in the system language. On a Spanish Windows eleven of the test binaries fail; a French, Russian, Chinese, Japanese, Portuguese, Czech or Telugu machine does the same. CI never sees it because its locale is English. `tests/theme.rs` and `tests/create.rs` already pin the option; the other 119 harnesses now do too, and the comment in `system_lang` says why, so a test copied from an existing one keeps the line. Also `i18n::tests::windows_display_language_query_returns_a_locale_tag` treated the return of `windows_ui_language()` as a single tag. It is the preferred-language list, one tag per line, as `first_supported` reads it, so on a Windows with two or more display languages the assertion tripped over the newline. It now checks the shape of every line. Co-authored-by: Fernando Areán <soporte@codebit.es> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
98 lines
3.6 KiB
Rust
98 lines
3.6 KiB
Rust
//! Header & footer, watermark and background dialogs in the real shell (egui_kittest).
|
|
|
|
use egui_kittest::Harness;
|
|
use egui_kittest::kittest::Queryable;
|
|
use pdfcraft_engine::MarkKind;
|
|
use pdfcraft_ui_egui::{Dialog, PdfCraftApp};
|
|
|
|
const FIXTURE: &[u8] = b"%PDF-1.7
|
|
1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
|
|
2 0 obj << /Type /Pages /Kids [3 0 R 4 0 R 5 0 R] /Count 3 /MediaBox [0 0 300 400] >> endobj
|
|
3 0 obj << /Type /Page /Parent 2 0 R >> endobj
|
|
4 0 obj << /Type /Page /Parent 2 0 R >> endobj
|
|
5 0 obj << /Type /Page /Parent 2 0 R >> endobj
|
|
trailer << /Root 1 0 R >>
|
|
%%EOF";
|
|
|
|
fn harness() -> Harness<'static, PdfCraftApp> {
|
|
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
|
let mut app = PdfCraftApp::new();
|
|
app.set_option("language", "en").unwrap();
|
|
app.open_bytes("doc.pdf", None, FIXTURE.to_vec()).unwrap();
|
|
app
|
|
});
|
|
h.run_steps(4);
|
|
h
|
|
}
|
|
|
|
fn marks(h: &Harness<'static, PdfCraftApp>) -> Vec<MarkKind> {
|
|
let s = h.state();
|
|
s.session.get(s.views[0].id).unwrap().marks.clone()
|
|
}
|
|
|
|
#[test]
|
|
fn header_and_footer_dialog_inserts_tokens_and_applies_to_a_subset() {
|
|
let mut h = harness();
|
|
assert!(!h.state_mut().execute("edit.header_footer.remove"), "nothing to remove yet");
|
|
assert!(h.state_mut().execute("edit.header_footer"));
|
|
h.run_steps(3);
|
|
assert_eq!(h.state().dialog, Some(Dialog::Marks(MarkKind::HeaderFooter)));
|
|
// The center footer box takes the page-number token.
|
|
h.state_mut().marks_draft.focused_box = 4;
|
|
h.get_by_label("Insert Page Number").click();
|
|
h.run_steps(2);
|
|
assert_eq!(h.state().marks_draft.hf.text[4], "<<1>>");
|
|
h.state_mut().marks_draft.range.subset = pdfcraft_ui_egui::marks::Subset::Odd;
|
|
h.run_steps(2);
|
|
h.get_by_label("OK").click();
|
|
h.run_steps(4);
|
|
assert_eq!(h.state().dialog, None);
|
|
assert_eq!(marks(&h), [MarkKind::HeaderFooter]);
|
|
// Update and Remove are now available.
|
|
assert!(h.state_mut().execute("edit.header_footer.update"));
|
|
h.run_steps(2);
|
|
h.get_by_label("Update Header and Footer");
|
|
h.get_by_label("Cancel").click();
|
|
h.run_steps(2);
|
|
assert!(h.state_mut().execute("edit.header_footer.remove"));
|
|
assert!(marks(&h).is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn watermark_and_background_dialogs() {
|
|
let mut h = harness();
|
|
h.state_mut().execute("edit.watermark");
|
|
h.run_steps(2);
|
|
assert!(h.query_by(|n| n.label().as_deref() == Some("OK") && n.is_disabled()).is_some(), "OK waits for text");
|
|
h.state_mut().marks_draft.wm.text = "DRAFT".into();
|
|
h.run_steps(2);
|
|
h.get_by_label("OK").click();
|
|
h.run_steps(3);
|
|
h.state_mut().execute("edit.background");
|
|
h.run_steps(2);
|
|
h.get_by_label("OK").click();
|
|
h.run_steps(3);
|
|
assert_eq!(marks(&h).len(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn backgrounds_and_watermarks_from_a_file() {
|
|
let mut h = harness();
|
|
h.state_mut().execute("edit.background");
|
|
h.run_steps(2);
|
|
h.get_by_label("File").click();
|
|
h.run_steps(2);
|
|
h.get_by_label("No file chosen");
|
|
assert!(h.query_by(|n| n.label().as_deref() == Some("OK") && n.is_disabled()).is_some(), "OK waits for a file");
|
|
// (Browse… opens the system picker; the test supplies the file directly.)
|
|
h.state_mut().marks_draft.file = Some(("letterhead.pdf".into(), std::sync::Arc::new(FIXTURE.to_vec())));
|
|
h.run_steps(2);
|
|
h.get_by_label("Page number");
|
|
h.get_by_label("Scale relative to target page");
|
|
h.get_by_label("OK").click();
|
|
h.run_steps(3);
|
|
assert_eq!(marks(&h), vec![MarkKind::Background]);
|
|
let s = h.state();
|
|
assert_eq!(s.session.get(s.views[0].id).unwrap().can_undo(), Some("Add background"));
|
|
}
|