mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-27 04:37:07 +00:00
Merge branch 'tfix1/t-rest' into area/app-1
This commit is contained in:
@@ -102,7 +102,7 @@ mod tests {
|
||||
|
||||
/// The display the saved settings name as the default: what a restart would open with.
|
||||
fn saved_display(app: &PdfCraftApp) -> PageDisplay {
|
||||
let token = app.settings_snapshot().view.default_layout;
|
||||
let token = app.settings_snapshot().layout.default_layout;
|
||||
token.as_deref().and_then(craft::pages::parse_display_token).map(|(display, _)| display).unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ mod tests {
|
||||
let second = second_path.to_str().unwrap();
|
||||
for enabled in [false, true] {
|
||||
let mut app = test_app();
|
||||
app.set_option("default-layout", "single").unwrap();
|
||||
app.set_option(&egui::Context::default(), "default-layout", "single").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "restored.pdf", None, include_bytes!("../../../crates/ui-egui/tests/data/form.pdf").to_vec())
|
||||
.unwrap();
|
||||
let restored = app.views[0].id;
|
||||
@@ -207,11 +207,11 @@ mod tests {
|
||||
if enabled {
|
||||
app.set_launch_layout("continuous").unwrap();
|
||||
} else {
|
||||
app.set_option("layout", "continuous").unwrap();
|
||||
app.set_option(&egui::Context::default(), "layout", "continuous").unwrap();
|
||||
}
|
||||
assert_eq!(app.views[2].view.display, PageDisplay::Single);
|
||||
assert!(app.views[2].view.continuous);
|
||||
app.set_option("default-layout", "two-up").unwrap();
|
||||
app.set_option(&egui::Context::default(), "default-layout", "two-up").unwrap();
|
||||
assert_eq!(app.view_defaults.display, PageDisplay::TwoUp);
|
||||
assert!(app.view_defaults.continuous);
|
||||
assert_eq!(saved_display(&app), PageDisplay::TwoUp);
|
||||
@@ -233,7 +233,7 @@ mod tests {
|
||||
for count in [1, 2] {
|
||||
let args = Arguments::parse(prefix.into_iter().chain(names.iter().take(count).copied()).map(str::to_owned));
|
||||
let mut app = test_app();
|
||||
app.set_option("default-layout", "continuous").unwrap();
|
||||
app.set_option(&egui::Context::default(), "default-layout", "continuous").unwrap();
|
||||
app.open_bytes(
|
||||
&egui::Context::default(),
|
||||
"restored.pdf",
|
||||
@@ -271,7 +271,7 @@ mod repeated_file_tests {
|
||||
std::fs::write(&path, include_bytes!("../../../crates/ui-egui/tests/data/form.pdf")).unwrap();
|
||||
let name = path.to_str().unwrap().to_string();
|
||||
let mut app = test_app();
|
||||
app.set_option("default-layout", "continuous").unwrap();
|
||||
app.set_option(&egui::Context::default(), "default-layout", "continuous").unwrap();
|
||||
app.open_path(&name);
|
||||
let original = app.views[0].id;
|
||||
open_files(&mut app, &[name.clone(), name], true);
|
||||
|
||||
@@ -54,7 +54,7 @@ fn automatic_text_tagging_opens_reviewable_tags() {
|
||||
h.run_steps(3);
|
||||
assert!(h.execute("a11y.autotag"));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Tags));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Tags));
|
||||
let doc = h.state().session.get(h.state().views[h.state().active.unwrap()].id).unwrap();
|
||||
let tags = doc.tags();
|
||||
assert_eq!(tags.len(), 2);
|
||||
@@ -67,11 +67,9 @@ fn checking_fixing_skipping_and_reporting() {
|
||||
let files = Arc::new(ScriptedFiles::new().saving_suggested());
|
||||
let scripted = files.clone();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
let mut app = crate::control::app_with_files(scripted);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "notes.pdf", None, FIXTURE.to_vec()).unwrap();
|
||||
// PLAN: assumed `PdfCraftApp::set_files(Arc<dyn Files>)` (pdf-workflows-w13, A-6)
|
||||
app.set_files(scripted);
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
@@ -83,7 +81,7 @@ fn checking_fixing_skipping_and_reporting() {
|
||||
h.get_by_label("Start Checking").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().dialogs.is_empty());
|
||||
assert_eq!(h.state().right, Some(RightPanel::Accessibility));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Accessibility));
|
||||
h.get_by_label("Document (3 issues)");
|
||||
h.get_by_label("Title - Failed");
|
||||
h.get_by_label("Color contrast - Skipped");
|
||||
@@ -240,7 +238,7 @@ fn tagging_form_fields_opens_the_tags_panel() {
|
||||
h.run_steps(3);
|
||||
assert!(h.execute("a11y.autotag_fields"));
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Tags));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Tags));
|
||||
let id = h.state().views[0].id;
|
||||
let report = h
|
||||
.state()
|
||||
@@ -334,7 +332,7 @@ fn tags_panel_edits_a_tag_property_and_undoes_it() {
|
||||
h.run_steps(4);
|
||||
assert!(h.execute("a11y.tags"));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Tags));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Tags));
|
||||
// The list's own disclosure: Left closes the selected group, Right opens it.
|
||||
h.get_by_label("Document · 6").click();
|
||||
h.key_press(egui::Key::ArrowLeft);
|
||||
@@ -422,17 +420,17 @@ fn checker_finding_opens_its_structure_tag() {
|
||||
assert_eq!(finding.object.map(|o| o.num), Some(7));
|
||||
h.get_by_label(&finding.message).click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Tags));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Tags));
|
||||
h.get_by_label("7 0 R");
|
||||
let title = h.get_by_role_and_label(Role::TextInput, "Title");
|
||||
title.focus();
|
||||
title.type_text("Unsaved title");
|
||||
h.run_steps(1);
|
||||
h.state_mut().right = Some(RightPanel::Accessibility);
|
||||
h.set_option("panel", "accessibility").unwrap();
|
||||
h.run_steps(2);
|
||||
h.get_by_label(&finding.message).click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Accessibility), "an unfinished tag edit is preserved");
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Accessibility), "an unfinished tag edit is preserved");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -446,7 +444,7 @@ fn finding_untagged_content_shows_the_focused_accessibility_results() {
|
||||
h.run_steps(3);
|
||||
assert!(h.execute("a11y.find_untagged"));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Accessibility));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Accessibility));
|
||||
let report = &h.state().a11y.report.as_ref().unwrap().1;
|
||||
let active: Vec<Rule> = report.results.iter().filter(|result| result.status != Status::Skipped).map(|result| result.rule).collect();
|
||||
assert_eq!(active, [Rule::TaggedContent, Rule::TaggedAnnotations, Rule::TaggedFormFields]);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::host::{AppInfo, Host, ManualJobs, Picked, ScriptedFiles};
|
||||
use craft::host::{ManualJobs, Picked, ScriptedFiles};
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
@@ -16,10 +16,9 @@ use crate::support::AppHarness as _;
|
||||
|
||||
/// An app over the scripted file service and manual jobs.
|
||||
fn harness(files: &Arc<ScriptedFiles>, jobs: &Arc<ManualJobs>) -> Harness<'static, PdfCraftApp> {
|
||||
let host = Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" }).files(files.clone()).jobs(jobs.clone()).build();
|
||||
let host = support::host_with(jobs.clone(), files.clone());
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
// PLAN: assumed `PdfCraftApp::with_host(host: Host) -> PdfCraftApp` (L-71)
|
||||
let mut app = PdfCraftApp::with_host(host);
|
||||
let mut app = support::test_app(host);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app
|
||||
});
|
||||
@@ -73,10 +72,10 @@ fn run_and_create_actions() {
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().custom_actions.len(), 1);
|
||||
h.get_by_label("1. Add watermark: DRAFT");
|
||||
let saved = h.state().persist();
|
||||
let saved = h.state().settings_snapshot();
|
||||
let mut fresh = crate::control::new_app();
|
||||
fresh.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
fresh.restore(&saved);
|
||||
fresh.apply_settings(&saved);
|
||||
assert_eq!(fresh.custom_actions, h.state().custom_actions);
|
||||
h.get_by_label("Start").click();
|
||||
finish(&mut h, &jobs);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::host::{AppInfo, Host, Picked, ScriptedFiles};
|
||||
use craft::host::{Picked, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
@@ -56,14 +56,11 @@ fn harness_with_pdf(pdf: Vec<u8>) -> Harness<'static, PdfCraftApp> {
|
||||
}
|
||||
|
||||
/// [`harness_with_pdf`] whose file picks `files` answers.
|
||||
// PLAN: assumed `crate::support::test_app(Arc<Host>) -> PdfCraftApp`, the shared harness that builds the app over a host
|
||||
// with its test services (pdf-chrome-w9, w9-1).
|
||||
fn harness_answering(pdf: Vec<u8>, files: Arc<ScriptedFiles>) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_eframe(move |_cc| {
|
||||
let host = Arc::new(Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" }).files(files).build());
|
||||
let mut app = crate::support::test_app(host);
|
||||
let mut app = crate::support::test_app(crate::support::host_with_files(files));
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes("doc.pdf", None, pdf).unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "doc.pdf", None, pdf).unwrap();
|
||||
app.set_option(&egui::Context::default(), "panel", "attachments").unwrap();
|
||||
app
|
||||
});
|
||||
@@ -134,7 +131,7 @@ fn right_click(h: &mut Harness<'static, PdfCraftApp>, label: &str) {
|
||||
fn attachment_rows_turn_their_events_into_attachment_actions() {
|
||||
let saved = Path::new("out/saved notes.txt");
|
||||
let from_menu = Path::new("out/from menu.pdf");
|
||||
let files = Arc::new(ScriptedFiles::answering([Picked::file(saved), Picked::file(from_menu)]));
|
||||
let files = Arc::new(ScriptedFiles::answering([Picked::Paths(vec![saved.to_path_buf()]), Picked::Paths(vec![from_menu.to_path_buf()])]));
|
||||
let mut h = harness_answering(attachments_pdf(), files.clone());
|
||||
assert_eq!(h.state().views.len(), 1);
|
||||
double_click(&mut h, "notes.txt");
|
||||
|
||||
@@ -270,12 +270,13 @@ fn new_bookmarks_from_text_styles_from_the_bookmark_options() {
|
||||
h.run_steps(3);
|
||||
};
|
||||
open(&mut h);
|
||||
assert_eq!(h.state().dialog, Some(pdfcraft_ui_egui::Dialog::BookmarksFromTextStyles));
|
||||
assert!(crate::support::dialog_open(&h), "the dialog opens");
|
||||
h.get_by_label("New bookmarks from text styles");
|
||||
assert_eq!(h.state().text_style_draft.levels, [Some(0), None, None, None], "the largest style is offered for level 1");
|
||||
// Cancel: nothing made.
|
||||
h.get_by_label("Cancel").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, None);
|
||||
assert!(!crate::support::dialog_open(&h));
|
||||
assert!(h.state().session.get(id).unwrap().info.outline.is_empty());
|
||||
// Level 2 from its list: the sections' style.
|
||||
open(&mut h);
|
||||
@@ -291,7 +292,7 @@ fn new_bookmarks_from_text_styles_from_the_bookmark_options() {
|
||||
assert_eq!(h.state().text_style_draft.levels, [Some(0), Some(1), None, None]);
|
||||
h.get_by_label("Create").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().dialog, None);
|
||||
assert!(!crate::support::dialog_open(&h));
|
||||
let outline = h.state().session.get(id).unwrap().info.outline.clone();
|
||||
assert_eq!(outline.len(), 1);
|
||||
assert_eq!(outline[0].title, "Untitled");
|
||||
@@ -299,7 +300,7 @@ fn new_bookmarks_from_text_styles_from_the_bookmark_options() {
|
||||
assert_eq!(titles, [("Introduction", Some(0)), ("Results", Some(1))]);
|
||||
assert_eq!(outline[0].children[0].children[0].title, "Background");
|
||||
assert_eq!(h.state().session.get(id).unwrap().can_undo(), Some("New bookmarks from text styles"));
|
||||
assert_eq!(h.state().right, Some(pdfcraft_ui_egui::RightPanel::Bookmarks));
|
||||
assert_eq!(crate::support::right(h.state()), Some(pdfcraft_ui_egui::RightPanel::Bookmarks));
|
||||
// A document with no text: nothing to choose from.
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().open_bytes(&ctx_h, "pages.pdf", None, PAGES.to_vec()).unwrap();
|
||||
@@ -309,11 +310,11 @@ fn new_bookmarks_from_text_styles_from_the_bookmark_options() {
|
||||
// The dialog's Close, below the message (the panel has a Close of its own).
|
||||
h.get_all_by_label("Close").find(|n| n.rect().top() > message.bottom()).expect("the dialog's Close").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, None);
|
||||
assert!(!crate::support::dialog_open(&h));
|
||||
// The command (Pages menu, command palette) opens it too.
|
||||
assert!(h.execute("bookmark.from_text_styles"));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, Some(pdfcraft_ui_egui::Dialog::BookmarksFromTextStyles));
|
||||
assert!(crate::support::dialog_open(&h), "the dialog opens");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -502,7 +503,7 @@ fn cut_copy_and_paste_a_bookmark_subtree_within_and_between_documents() {
|
||||
h.get_by_label("Paste bookmarks").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(active_outline(&h), [("Intro".to_string(), Some(0), 0), ("Results".to_string(), None, 1)]);
|
||||
let toast = h.state().toast.as_ref().map(|t| t.0.clone()).unwrap_or_default();
|
||||
let toast = crate::support::shown_notice(&h).unwrap_or_default();
|
||||
assert!(toast.contains("1 pasted bookmark points past the last page"), "{toast}");
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::Z);
|
||||
h.run_steps(3);
|
||||
@@ -543,7 +544,7 @@ fn cutting_a_subtree_too_deep_to_copy_keeps_it() {
|
||||
assert_eq!(before.first().map(|b| b.0.as_str()), Some("Top"));
|
||||
menu(&mut h, "Top", "Cut");
|
||||
assert_eq!(active_outline(&h), before, "nothing was cut");
|
||||
let toast = h.state().toast.as_ref().map(|t| t.0.clone()).unwrap_or_default();
|
||||
let toast = crate::support::shown_notice(&h).unwrap_or_default();
|
||||
assert!(toast.contains("so nothing was cut"), "{toast}");
|
||||
assert!(h.state().bookmark_clipboard.is_some(), "the copy is still on the bookmark clipboard");
|
||||
}
|
||||
|
||||
@@ -35,10 +35,9 @@ fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, P
|
||||
/// `harness` on the injected `clipboard`, whose recorded writes a test reads.
|
||||
fn harness_on(clipboard: crate::support::RecordingClipboard, setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_eframe(move |_cc| {
|
||||
// PLAN: assumed support::app_with_clipboard(RecordingClipboard) -> PdfCraftApp (pdf-chrome-w9: `PdfCraftApp::with_host` over `AppServices` holding the clipboard)
|
||||
let mut app = crate::support::app_with_clipboard(clipboard);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes("table.pdf", None, table()).expect("opens");
|
||||
app.open_bytes(&egui::Context::default(), "table.pdf", None, table()).expect("opens");
|
||||
app.set_option(&egui::Context::default(), "left", "closed").unwrap();
|
||||
app.set_option(&egui::Context::default(), "author", "Tester").unwrap();
|
||||
setup(&mut app);
|
||||
@@ -165,7 +164,6 @@ fn a_column_selection_copies_plain_text_only() {
|
||||
drag(&mut h, from, to, Modifiers::ALT);
|
||||
assert!(h.execute("edit.copy"));
|
||||
h.step();
|
||||
// PLAN: assumed RecordingClipboard::writes() -> Vec<Vec<Flavor>> (each write's flavours, `mime` and `data`).
|
||||
let html = clipboard.writes().iter().flatten().any(|flavor| flavor.mime.to_string() == "text/html");
|
||||
assert!(!html, "no HTML for a column selection");
|
||||
let copied = h.output().platform_output.commands.iter().any(|c| matches!(c, egui::OutputCommand::CopyText(t) if t == "Name\tQty\nApple\t12"));
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::ui::primitives::textures::TextureState;
|
||||
use craft::ui::primitives::textures::{TextureState, ThumbRequest};
|
||||
use craft::ui::tile_grid::TileZoom;
|
||||
use egui::{Key, Modifiers, Pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use pdfcraft_render::{PageRenderer, RenderRequest, RequestKind};
|
||||
use pdfcraft_ui_egui::settings::import_json;
|
||||
use pdfcraft_ui_egui::{CombineView, FilePurpose, PdfCraftApp};
|
||||
|
||||
/// An `n`-page document with a proper xref table; page `i` shows "Page i+1".
|
||||
@@ -138,6 +139,16 @@ fn settle(h: &mut Harness<'static, PdfCraftApp>, done: impl Fn(&PdfCraftApp) ->
|
||||
false
|
||||
}
|
||||
|
||||
/// What the grid's thumbnails are read at.
|
||||
fn request() -> ThumbRequest {
|
||||
ThumbRequest::for_cell(256.0, 1.0)
|
||||
}
|
||||
|
||||
/// Each file's grid thumbnail, as the harness's frames have stored them.
|
||||
fn thumbnails(h: &Harness<'static, PdfCraftApp>) -> Vec<TextureState> {
|
||||
h.state().combine_thumbnails(&h.ctx, &request())
|
||||
}
|
||||
|
||||
fn ready(t: &TextureState) -> bool {
|
||||
matches!(t, TextureState::Ready(_))
|
||||
}
|
||||
@@ -222,14 +233,14 @@ fn combine_shows_a_grid_by_default_and_the_view_is_kept_in_the_settings() {
|
||||
assert_eq!(h.state().combine_view, CombineView::List);
|
||||
h.get_by_label("File name");
|
||||
// Kept in the settings, and read back.
|
||||
let saved = h.state().persist();
|
||||
let saved = h.state().settings_snapshot();
|
||||
let mut fresh = crate::control::new_app();
|
||||
assert_eq!(fresh.combine_view, CombineView::Grid);
|
||||
fresh.restore(&saved);
|
||||
fresh.apply_settings(&saved);
|
||||
assert_eq!(fresh.combine_view, CombineView::List);
|
||||
// A damaged setting keeps the default.
|
||||
let mut damaged = crate::control::new_app();
|
||||
damaged.restore(r#"{"combine_view": "tiles"}"#);
|
||||
damaged.apply_settings(&import_json(r#"{"combine_view": "tiles"}"#).0);
|
||||
assert_eq!(damaged.combine_view, CombineView::Grid);
|
||||
// Scriptable, with a clear refusal for anything else.
|
||||
let app = h.state_mut();
|
||||
@@ -269,12 +280,16 @@ fn thumbnails_show_the_first_page_each_file_takes() {
|
||||
let pages = fixture_pages(&[(200.0, 300.0), (200.0, 300.0), (300.0, 200.0)]);
|
||||
let mut h = grid_of(vec![("three.pdf", pages), ("one.pdf", fixture(1))], vec2(1400.0, 900.0));
|
||||
h.state_mut().combine_draft[0].range = "3, 1".into();
|
||||
let ctx = h.ctx.clone();
|
||||
assert!(
|
||||
settle(&mut h, |app| app.combine_thumbnails().iter().all(ready) && landscape(&app.combine_thumbnails()[0])),
|
||||
settle(&mut h, |app| {
|
||||
let thumbs = app.combine_thumbnails(&ctx, &request());
|
||||
thumbs.iter().all(ready) && landscape(&thumbs[0])
|
||||
}),
|
||||
"{:?}",
|
||||
h.state().combine_thumbnails()
|
||||
thumbnails(&h)
|
||||
);
|
||||
let thumbs = h.state().combine_thumbnails();
|
||||
let thumbs = thumbnails(&h);
|
||||
assert!(landscape(&thumbs[0]), "\"3, 1\" starts with page 3: {:?}", thumbs[0]);
|
||||
assert!(portrait(&thumbs[1]), "{:?}", thumbs[1]);
|
||||
let (width, height) = shape(&thumbs[1]).unwrap();
|
||||
@@ -282,28 +297,29 @@ fn thumbnails_show_the_first_page_each_file_takes() {
|
||||
assert!(width > 0.0 && height > 0.0 && width <= 1536.0 && height <= 1536.0, "{width}×{height}");
|
||||
// A new range is a new thumbnail, never the old page.
|
||||
h.state_mut().combine_draft[0].range = "2".into();
|
||||
assert!(settle(&mut h, |app| portrait(&app.combine_thumbnails()[0])), "{:?}", h.state().combine_thumbnails());
|
||||
assert!(settle(&mut h, |app| portrait(&app.combine_thumbnails(&ctx, &request())[0])), "{:?}", thumbnails(&h));
|
||||
// A range that can't be used shows no page at all.
|
||||
h.state_mut().combine_draft[0].range = "9".into();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().combine_thumbnails()[0], TextureState::Missing);
|
||||
assert_eq!(thumbnails(&h)[0], TextureState::Missing);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_locked_file_shows_no_page_until_unlocked_and_undo_locks_it_again() {
|
||||
let mut h = grid_of(vec![("one.pdf", fixture(1)), ("secret.pdf", protected("pw", "owner"))], vec2(1400.0, 900.0));
|
||||
assert!(settle(&mut h, |app| ready(&app.combine_thumbnails()[0])));
|
||||
assert_eq!(h.state().combine_thumbnails()[1], TextureState::Missing, "nothing is drawn of a locked file");
|
||||
let ctx = h.ctx.clone();
|
||||
assert!(settle(&mut h, |app| ready(&app.combine_thumbnails(&ctx, &request())[0])));
|
||||
assert_eq!(thumbnails(&h)[1], TextureState::Missing, "nothing is drawn of a locked file");
|
||||
assert!(h.state_mut().combine_unlock_rows(&[1], "pw"));
|
||||
assert!(settle(&mut h, |app| ready(&app.combine_thumbnails()[1])), "{:?}", h.state().combine_thumbnails());
|
||||
assert!(settle(&mut h, |app| ready(&app.combine_thumbnails(&ctx, &request())[1])), "{:?}", thumbnails(&h));
|
||||
// Undo brings back the locked file: its unlocked thumbnail goes with the password.
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::Z);
|
||||
h.run_steps(3);
|
||||
assert!(h.state().combine_draft[1].lock.is_some());
|
||||
assert_eq!(h.state().combine_thumbnails()[1], TextureState::Missing);
|
||||
assert_eq!(thumbnails(&h)[1], TextureState::Missing);
|
||||
// Unlocked again (a new branch of the history): drawn again, from this unlock.
|
||||
assert!(h.state_mut().combine_unlock_rows(&[1], "pw"));
|
||||
assert!(settle(&mut h, |app| ready(&app.combine_thumbnails()[1])), "{:?}", h.state().combine_thumbnails());
|
||||
assert!(settle(&mut h, |app| ready(&app.combine_thumbnails(&ctx, &request())[1])), "{:?}", thumbnails(&h));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -549,13 +565,13 @@ fn the_toolbar_sizes_the_cards_within_limits_and_the_size_is_kept_in_the_setting
|
||||
let smallest_card = card(&h, "a.pdf");
|
||||
assert!(smallest_card.width() < before.width() && smallest_card.height() < before.height(), "{smallest_card:?}");
|
||||
// Kept in the settings, and read back; a damaged setting is clamped or ignored.
|
||||
let saved = h.state().persist();
|
||||
let saved = h.state().settings_snapshot();
|
||||
let mut fresh = crate::control::new_app();
|
||||
fresh.restore(&saved);
|
||||
fresh.apply_settings(&saved);
|
||||
assert_eq!(fresh.combine_zoom, smallest);
|
||||
fresh.restore(r#"{"combine_zoom": 99}"#);
|
||||
fresh.apply_settings(&import_json(r#"{"combine_zoom": 99}"#).0);
|
||||
assert_eq!(fresh.combine_zoom, largest);
|
||||
fresh.restore(r#"{"combine_zoom": "big"}"#);
|
||||
fresh.apply_settings(&import_json(r#"{"combine_zoom": "big"}"#).0);
|
||||
assert_eq!(fresh.combine_zoom, largest);
|
||||
// Scriptable in percent, with a clear refusal outside the range.
|
||||
let app = h.state_mut();
|
||||
@@ -594,11 +610,12 @@ fn expanding_a_file_shows_the_pages_it_adds_in_order_with_their_numbers() {
|
||||
assert!(xs.windows(2).all(|w| w[0] < w[1]), "pages 3, 1, 4 in that order: {xs:?}");
|
||||
assert!(h.query_by_label(&page_card(2, "b.pdf")).is_none(), "page 2 isn't added, so isn't shown");
|
||||
// Each renders its own page.
|
||||
let ctx = h.ctx.clone();
|
||||
assert!(settle(&mut h, |app| {
|
||||
let pages = app.combine_page_thumbnails(1);
|
||||
let pages = app.combine_page_thumbnails(&ctx, 1, &request());
|
||||
pages.len() == 3 && pages.iter().all(|(_, t)| ready(t))
|
||||
}));
|
||||
let shapes: Vec<(usize, TextureState)> = h.state().combine_page_thumbnails(1);
|
||||
let shapes: Vec<(usize, TextureState)> = h.state().combine_page_thumbnails(&ctx, 1, &request());
|
||||
assert_eq!(shapes.iter().map(|(p, _)| *p).collect::<Vec<_>>(), [2, 0, 3]);
|
||||
assert!(landscape(&shapes[0].1) && portrait(&shapes[1].1), "{shapes:?}");
|
||||
let (w, h4) = shape(&shapes[2].1).unwrap();
|
||||
|
||||
@@ -49,7 +49,7 @@ fn harness_controlled() -> (Harness<'static, PdfCraftApp>, ControlClient) {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = new_app();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.attach_control(rx, None);
|
||||
app.attach_control(craft::automation::ControlChannel::new(rx), None);
|
||||
app.open_bytes(&egui::Context::default(), "doc.pdf", None, fixture(3)).unwrap();
|
||||
app
|
||||
});
|
||||
@@ -78,11 +78,15 @@ fn close_requested(h: &Harness<'static, PdfCraftApp>) -> bool {
|
||||
h.output().viewport_output.values().any(|v| v.commands.iter().any(|c| matches!(c, egui::ViewportCommand::Close)))
|
||||
}
|
||||
|
||||
/// Whether the export dialog a tool opens is on screen.
|
||||
// PLAN: assumed `pdfcraft_ui_egui::export_ui::open_kind(&PdfCraftApp) -> Option<_>` is reachable from
|
||||
// integration tests (pdf-workflows-w12); `workflows` is a private module at the base.
|
||||
fn export_open(app: &PdfCraftApp) -> bool {
|
||||
pdfcraft_ui_egui::export_ui::open_kind(app).is_some()
|
||||
/// Whether the export dialog a tool opens is on screen: the only dialog these tests open.
|
||||
fn export_open(h: &Harness<'static, PdfCraftApp>) -> bool {
|
||||
support::dialog_open(h)
|
||||
}
|
||||
|
||||
/// Runs the registry command `id` as the menu does, with the harness's own context.
|
||||
fn run_command(h: &mut Harness<'static, PdfCraftApp>, id: &str) {
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().run_command(&ctx, id);
|
||||
}
|
||||
|
||||
/// Commands that open a native file picker can't run headless.
|
||||
@@ -140,7 +144,7 @@ fn every_registered_command_is_implemented() {
|
||||
// Give undo/redo something to do.
|
||||
app.apply_edit(&egui::Context::default(), pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 });
|
||||
if spec.id == "edit.redo" {
|
||||
app.undo();
|
||||
app.undo(&egui::Context::default());
|
||||
}
|
||||
if spec.id == "prepress.marks.remove" {
|
||||
use pdfcraft_engine::{Edit, PrinterMarks};
|
||||
@@ -282,19 +286,22 @@ fn a_tool_chosen_with_no_document_asks_for_one_and_runs_on_it() {
|
||||
let path = dir.join("picked.pdf");
|
||||
std::fs::write(&path, fixture(2)).unwrap();
|
||||
let mut h = harness_picking(Some(&path), |_| {});
|
||||
h.state_mut().run_command("export.text");
|
||||
support::wait_until(&mut h, "picked document and chosen tool", |app| app.active.is_some() && export_open(app));
|
||||
run_command(&mut h, "export.text");
|
||||
assert!(
|
||||
support::step_until(&mut h, |h| h.state().active.is_some() && export_open(h)),
|
||||
"timed out waiting for the picked document and chosen tool"
|
||||
);
|
||||
assert!(h.state().active.is_some(), "the picked file is open");
|
||||
assert!(export_open(h.state()), "and the tool runs on it");
|
||||
assert!(export_open(&h), "and the tool runs on it");
|
||||
let (_, id) = h.state().active_ids().unwrap();
|
||||
let doc = h.state().session.get(id).unwrap();
|
||||
assert_eq!(doc.name, "picked.pdf");
|
||||
assert_eq!(doc.bytes.as_slice(), fixture(2).as_slice());
|
||||
// Cancelled: nothing opens and nothing runs.
|
||||
let mut h = harness_picking(None, |_| {});
|
||||
h.state_mut().run_command("export.text");
|
||||
run_command(&mut h, "export.text");
|
||||
h.run_steps(3);
|
||||
assert!(h.state().active.is_none() && !export_open(h.state()));
|
||||
assert!(h.state().active.is_none() && !export_open(&h));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
@@ -310,12 +317,12 @@ fn a_tool_chosen_with_an_already_open_file_focuses_its_tab_and_still_runs() {
|
||||
app.open_path(&opened);
|
||||
app.active = None;
|
||||
});
|
||||
h.state_mut().run_command("export.text");
|
||||
run_command(&mut h, "export.text");
|
||||
h.run_steps(3);
|
||||
let app = h.state();
|
||||
assert_eq!(app.views.len(), 1, "the existing tab is reused, not duplicated");
|
||||
assert_eq!(app.active, Some(0), "the pick focused the tab it already opened");
|
||||
assert!(export_open(app), "the tool still runs on it");
|
||||
assert!(export_open(&h), "the tool still runs on it");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
use egui::{Pos2, pos2};
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
// PLAN: path of `PdfCraftSettings` assumed to be the crate root (pdf-shell-w9).
|
||||
use pdfcraft_ui_egui::{PdfCraftApp, PdfCraftSettings, QuickTool, comments::CommentTool};
|
||||
use pdfcraft_ui_egui::settings::PdfCraftSettings;
|
||||
use pdfcraft_ui_egui::{PdfCraftApp, QuickTool, comments::CommentTool};
|
||||
|
||||
// Contributor-original blank page: no document assets or fonts are needed.
|
||||
const PDF: &[u8] = b"%PDF-1.7
|
||||
|
||||
@@ -25,8 +25,8 @@ fn compare_two_versions() {
|
||||
h.get_by_label("Compare Files");
|
||||
h.get_by_label("Compare").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Compare));
|
||||
assert_eq!(h.state().toast.clone().unwrap().0, "2 differences found");
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Compare));
|
||||
assert_eq!(crate::support::shown_notice(&h).as_deref(), Some("2 differences found"));
|
||||
h.get_by_label("2 Replaced");
|
||||
h.get_by_label("\"five\" → \"three\"").click();
|
||||
h.run_steps(2);
|
||||
@@ -127,7 +127,8 @@ fn compare_filters_hide_text_or_visual_changes() {
|
||||
});
|
||||
h.run_steps(4);
|
||||
h.state_mut().compare_old = h.state().views.first().map(|v| v.id);
|
||||
h.state_mut().run_compare();
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().run_compare(&ctx);
|
||||
h.run_steps(3);
|
||||
let new_i = h.state().active_ids().unwrap().0;
|
||||
let old_i = h.state().views.iter().position(|v| v.id == h.state().compare.as_ref().unwrap().old).unwrap();
|
||||
@@ -242,13 +243,12 @@ fn pdfa_dialog_shows_a_declared_pdfua() {
|
||||
#[test]
|
||||
fn export_to_word_html_and_rtf() {
|
||||
let doc = Session::new().create_from_text("t", "Exported words").unwrap().to_vec();
|
||||
let mut app = crate::control::new_app();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "e.pdf", None, doc).unwrap();
|
||||
for ext in ["docx", "pptx", "html", "rtf"] {
|
||||
// Each save is answered with the suggested name in the suggested folder.
|
||||
let files = std::sync::Arc::new(craft::host::ScriptedFiles::new().saving_suggested());
|
||||
app.set_files(files.clone()); // PLAN: assumed `PdfCraftApp::set_files(Arc<dyn Files>)` (pdf-shell-w16)
|
||||
let mut app = crate::control::app_with_files(files.clone());
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "e.pdf", None, doc.clone()).unwrap();
|
||||
assert!(app.execute(&egui::Context::default(), &format!("export.{ext}")));
|
||||
let request = files.requests().pop().expect("the export asked where to save");
|
||||
let path = request.directory.or(request.default_directory).unwrap_or_default().join(request.file_name.expect("a suggested name"));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Edit a PDF ▸ Add content in the real shell (egui_kittest): type text onto a page, move it,
|
||||
//! restyle it from the panel, add an image, delete with the keyboard.
|
||||
|
||||
use craft::pages::ui::view::GoTo;
|
||||
use egui::{Pos2, pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
@@ -406,7 +407,7 @@ fn typing_thai_text_keeps_marks_and_commits_to_page() {
|
||||
if pdfcraft_fonts::document_thai_font().is_none() {
|
||||
return;
|
||||
}
|
||||
let fonts = pdfcraft_ui_egui::theme::font_definitions();
|
||||
let fonts = pdfcraft_ui_egui::fonts::ui_fonts(pdfcraft_ui_egui::i18n::Lang::EN).stack().flat_definitions();
|
||||
let face = pdfcraft_fonts::document_thai_font().unwrap();
|
||||
assert!(fonts.families[&egui::FontFamily::Proportional].contains(&face.name()));
|
||||
let mut h = harness();
|
||||
@@ -816,10 +817,10 @@ fn mode_tab_cursors(
|
||||
let page = |h: &Harness<'static, PdfCraftApp>| h.state().views[0].page_screen_rect(0).expect("on screen");
|
||||
let y = what(h).center().y - page(h).top();
|
||||
let tabs = mode_tab(h, "Convert").center().y;
|
||||
h.state_mut().views[0].goto = Some((0, 0.0));
|
||||
h.state_mut().views[0].view.go_to = Some(GoTo::Top { page: 0, fraction: 0.0 });
|
||||
h.run_steps(4);
|
||||
let top = page(h).top();
|
||||
h.state_mut().views[0].goto = Some((0, (top - (tabs - y)) / page(h).height()));
|
||||
h.state_mut().views[0].view.go_to = Some(GoTo::Top { page: 0, fraction: ((top - (tabs - y)) / page(h).height()).into() });
|
||||
h.run_steps(4);
|
||||
let under = what(h);
|
||||
["All tools", "Edit", "Convert", "E-Sign"].map(|label| {
|
||||
@@ -847,13 +848,13 @@ fn mode_tabs_keep_the_hand_over_added_text_scrolled_under_them() {
|
||||
assert!(h.execute("edit.text"));
|
||||
h.set_option("left", "closed").unwrap();
|
||||
// The page across the window, so text placed at its left edge reaches under the tabs.
|
||||
h.state_mut().views[0].fit() = pdfcraft_ui_egui::canvas::Fit::Width;
|
||||
h.state_mut().views[0].view.fit = pdfcraft_ui_egui::canvas::Fit::Width;
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().quick_tool, QuickTool::AddText);
|
||||
// The empty page, ready for text.
|
||||
assert_eq!(mode_tab_cursors(&mut h, |h| item_on_screen(h, [10.0, 290.0, 210.0, 305.0])), HAND_ON_EVERY_TAB, "the page under the tabs");
|
||||
// Text kept by a click lower down, which starts a second box (#74).
|
||||
h.state_mut().views[0].goto = Some((0, 0.0));
|
||||
h.state_mut().views[0].view.go_to = Some(GoTo::Top { page: 0, fraction: 0.0 });
|
||||
h.run_steps(4);
|
||||
let p = at(&h, 10.0, 40.0);
|
||||
click(&mut h, p);
|
||||
@@ -1355,7 +1356,7 @@ fn redo_from_the_menu_is_enabled_for_the_added_text_boxs_own_typing() {
|
||||
assert_eq!(h.state().views[0].session.content.draft.as_ref().map(|d| d.text.as_str()), Some("Reviewed"), "Undo takes it back in the box");
|
||||
assert_eq!(h.state().session.get(h.state().views[0].id).unwrap().can_redo(), None, "the document has nothing to redo");
|
||||
// A range retained while the unfocused editor still showed its previous text.
|
||||
h.state_mut().views[0].session.content.draft.as_mut().unwrap().selection = Some(0..1);
|
||||
h.state_mut().views[0].session.content.draft.as_mut().unwrap().selection = Some(craft::text::ui::editor::TextSelection::new(0, 1));
|
||||
h.event(egui::Event::PointerMoved(egui::pos2(10.0, 10.0)));
|
||||
h.ctx.memory_mut(|m| m.request_focus(egui::Id::unique("test-menu")));
|
||||
assert!(h.execute("edit.redo"), "Redo is enabled for the box's own step");
|
||||
@@ -1661,7 +1662,7 @@ fn delete_and_escape_under_a_dialog_leave_the_selected_added_text() {
|
||||
h.run_steps(3);
|
||||
assert_eq!(added(&h).len(), 1, "{key:?} under a dialog deletes nothing");
|
||||
assert_eq!(h.state().views[0].session.content.selected, Some((0, 0)), "{key:?}: still selected");
|
||||
assert_eq!(h.state().dialog.is_none(), key == egui::Key::Escape, "{key:?}: only Escape closes it");
|
||||
assert_eq!(!crate::support::dialog_open(&h), key == egui::Key::Escape, "{key:?}: only Escape closes it");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1704,7 +1705,7 @@ fn escape_closing_a_dialog_over_added_text_being_typed_keeps_the_typing() {
|
||||
crate::support::open_shortcuts_from_the_help_menu(&mut h);
|
||||
h.key_press(egui::Key::Escape);
|
||||
h.run_steps(3);
|
||||
assert!(h.state().dialog.is_none(), "Escape closes the dialog");
|
||||
assert!(!crate::support::dialog_open(&h), "Escape closes the dialog");
|
||||
let open = h.state().views[0].session.content.draft.as_ref().is_some_and(|d| d.text.contains("Reviewed"));
|
||||
let added = added(&h).iter().any(|a| matches!(&a.content, pdfcraft_engine::AddedContent::Text(t) if t.text.contains("Reviewed")));
|
||||
assert!(open || added, "the typing stays");
|
||||
|
||||
@@ -141,7 +141,7 @@ fn harness_on(app: PdfCraftApp, pages: usize, width: f32, scale: f32) -> (Harnes
|
||||
let mut h = Harness::builder().with_size(egui::vec2(width, 900.0)).with_pixels_per_point(scale).build_eframe(move |_cc| {
|
||||
let mut app = app;
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.attach_control(rx, None);
|
||||
app.attach_control(craft::automation::ControlChannel::new(rx), None);
|
||||
app.open_bytes(&egui::Context::default(), "doc.pdf", None, fixture(pages)).unwrap();
|
||||
app
|
||||
});
|
||||
@@ -604,7 +604,7 @@ fn moving_before_middle_button_release_keeps_scrolling_without_starting_page_too
|
||||
h.run_steps(8);
|
||||
assert_eq!(h.state().views[0].page_screen_rect(0).unwrap().top(), released, "no drift after releasing a held middle drag");
|
||||
assert!(h.state().views[0].crop_drag.is_none(), "the Crop tool must not receive a wheel drag");
|
||||
assert!(h.state().dialog.is_none());
|
||||
assert!(!crate::support::dialog_open(&h));
|
||||
assert!(!h.state().session.get(h.state().views[0].id).unwrap().dirty);
|
||||
|
||||
// Small movement within the dead zone before release still latches auto-scroll on.
|
||||
@@ -1485,7 +1485,7 @@ fn a_script_opened_panel_shows() {
|
||||
h.run_steps(3);
|
||||
assert!(h.query_by_label("This document has no bookmarks.").is_none());
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
h.state_mut().run_button_script(id, "", "app.execMenuItem('ShowHideBookmarks')");
|
||||
h.run_button_script(id, "", "app.execMenuItem('ShowHideBookmarks')");
|
||||
assert!(crate::support::step_until(&mut h, |h| h.query_by_label("This document has no bookmarks.").is_some()));
|
||||
}
|
||||
|
||||
@@ -1618,7 +1618,7 @@ fn control_open_of_an_already_open_file_replies_ok_and_focuses_its_tab() {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.attach_control(rx, None);
|
||||
app.attach_control(craft::automation::ControlChannel::new(rx), None);
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
@@ -1654,7 +1654,7 @@ fn control_open_replies_pending_while_the_worker_opens_and_focuses_once_it_has()
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.attach_control(rx, None);
|
||||
app.attach_control(craft::automation::ControlChannel::new(rx), None);
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
@@ -1879,7 +1879,7 @@ fn control_collapses_and_expands_a_pinned_folder() {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 900.0)).build_eframe(move |_cc| {
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.pin_folder(&pin);
|
||||
app.attach_control(rx, None);
|
||||
app.attach_control(craft::automation::ControlChannel::new(rx), None);
|
||||
app
|
||||
});
|
||||
let c = tx;
|
||||
|
||||
@@ -4,8 +4,9 @@ use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{AppInfo, Host, ManualJobs, Picked, ScriptedFiles};
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
use craft::host::{ManualJobs, Picked, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
|
||||
fn png() -> Vec<u8> {
|
||||
@@ -20,11 +21,9 @@ fn scripted(
|
||||
size: egui::Vec2,
|
||||
setup: impl FnOnce(&mut PdfCraftApp) + 'static,
|
||||
) -> Harness<'static, PdfCraftApp> {
|
||||
let host = Arc::new(Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" }).files(files).jobs(jobs).build());
|
||||
// PLAN: assumed `AppServices::new(wake, clipboard, recovery_dir, update_source, intake, watch)` (L-207, pdf-hub-w1)
|
||||
let services = pdfcraft_ui_egui::AppServices::new(craft::host::Wake::none(), None, None, None, None, None);
|
||||
let host = crate::support::host_with(jobs, files);
|
||||
Harness::builder().with_size(size).build_eframe(move |_cc| {
|
||||
let mut app = PdfCraftApp::with_host(host, services);
|
||||
let mut app = crate::support::test_app(host);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
setup(&mut app);
|
||||
app
|
||||
@@ -196,13 +195,13 @@ fn the_pdf_optimizer_dialog_picks_a_preset() {
|
||||
assert!(h.execute("optimize.advanced"));
|
||||
h.run_steps(2);
|
||||
h.get_by_value("Standard");
|
||||
assert_eq!(h.get_by_label("Merge image fragments").toggled(), Some(true));
|
||||
assert_eq!(h.get_by_label("Merge image fragments").accesskit_node().toggled(), Some(egui::accesskit::Toggled::True));
|
||||
h.get_by_value("Standard").click();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Mobile").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_value("Mobile");
|
||||
assert_eq!(h.get_by_label("Merge image fragments").toggled(), Some(false), "Mobile turns it off");
|
||||
assert_eq!(h.get_by_label("Merge image fragments").accesskit_node().toggled(), Some(egui::accesskit::Toggled::False), "Mobile turns it off");
|
||||
// Changing an option makes the settings custom.
|
||||
h.get_by_label("Merge image fragments").click();
|
||||
h.run_steps(2);
|
||||
|
||||
@@ -6,6 +6,7 @@ use egui::{Key, Modifiers, pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
use pdfcraft_ui_egui::settings::import_json;
|
||||
|
||||
const PDF: &[u8] = b"%PDF-1.7
|
||||
1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
|
||||
@@ -19,6 +20,11 @@ fn shows(h: &Harness<'static, PdfCraftApp>, text: &str) -> bool {
|
||||
h.query_all_by(|n| n.label().is_some_and(|l| l.contains(text)) || n.value().is_some_and(|v| v.contains(text))).next().is_some()
|
||||
}
|
||||
|
||||
/// What the Pattern box holds, valid or not.
|
||||
fn pattern(h: &Harness<'static, PdfCraftApp>) -> Option<String> {
|
||||
h.get_by_role_and_label(Role::TextInput, "Pattern").value()
|
||||
}
|
||||
|
||||
fn retype(h: &mut Harness<'static, PdfCraftApp>, text: &str) {
|
||||
// The preferences scroll; bring the field into view before clicking it.
|
||||
h.get_by_role_and_label(Role::TextInput, "Pattern").scroll_to_me();
|
||||
@@ -50,7 +56,7 @@ fn fill_and_sign_dates_follow_the_date_format_preference_and_it_is_remembered()
|
||||
retype(&mut h, "dd/mm HH");
|
||||
h.get_by_label_contains("is a time letter (H h M s t)");
|
||||
assert_eq!(h.state().session.date_format(), "d \\de mmmm yyyy");
|
||||
assert_eq!(h.state().date_format_draft.as_deref(), Some("dd/mm HH"));
|
||||
assert_eq!(pattern(&h).as_deref(), Some("dd/mm HH"));
|
||||
// Typed a key at a time, spaces stay where they are typed (the box isn't trimmed under the cursor).
|
||||
h.get_by_role_and_label(Role::TextInput, "Pattern").click();
|
||||
h.run_steps(1);
|
||||
@@ -59,7 +65,7 @@ fn fill_and_sign_dates_follow_the_date_format_preference_and_it_is_remembered()
|
||||
h.get_by_role_and_label(Role::TextInput, "Pattern").type_text(&c.to_string());
|
||||
h.run_steps(1);
|
||||
}
|
||||
assert_eq!(h.state().date_format_draft.as_deref(), Some("yyyy mm dd"));
|
||||
assert_eq!(pattern(&h).as_deref(), Some("yyyy mm dd"));
|
||||
assert_eq!(h.state().session.date_format(), "yyyy mm dd");
|
||||
// A letter group that isn't a date code is refused, not silently shortened.
|
||||
retype(&mut h, "yyyyyyyy");
|
||||
@@ -89,11 +95,11 @@ fn fill_and_sign_dates_follow_the_date_format_preference_and_it_is_remembered()
|
||||
|
||||
// It survives a restart; an unusable saved pattern keeps the default; the control channel checks it too.
|
||||
let mut restored = crate::control::new_app();
|
||||
restored.restore(&h.state().persist());
|
||||
restored.apply_settings(&h.state().settings_snapshot());
|
||||
assert_eq!(restored.session.date_format(), "yyyy.mm.dd.");
|
||||
let mut fresh = crate::control::new_app();
|
||||
fresh.restore(&format!(r#"{{"date_format": "{}"}}"#, "d".repeat(10_000)));
|
||||
fresh.restore(r#"{"date_format": "HH:MM"}"#);
|
||||
fresh.apply_settings(&import_json(&format!(r#"{{"date_format": "{}"}}"#, "d".repeat(10_000))).0);
|
||||
fresh.apply_settings(&import_json(r#"{"date_format": "HH:MM"}"#).0);
|
||||
assert_eq!(fresh.session.date_format(), "m/d/yyyy");
|
||||
assert!(fresh.set_option(&egui::Context::default(), "date-format", "Year").is_err());
|
||||
fresh.set_option(&egui::Context::default(), "date-format", "dd/mm/yyyy").unwrap();
|
||||
@@ -125,10 +131,10 @@ fn month_names_follow_the_date_language_or_else_the_interface_language() {
|
||||
|
||||
// Remembered; an unknown saved language is ignored; auto follows the interface again.
|
||||
let mut restored = crate::control::new_app();
|
||||
restored.restore(&h.state().persist());
|
||||
restored.apply_settings(&h.state().settings_snapshot());
|
||||
assert_eq!(restored.session.date_language(), Some("es"));
|
||||
let mut fresh = crate::control::new_app();
|
||||
fresh.restore(r#"{"date_language": "klingon"}"#);
|
||||
fresh.apply_settings(&import_json(r#"{"date_language": "klingon"}"#).0);
|
||||
assert_eq!(fresh.session.date_language(), None);
|
||||
assert!(fresh.set_option(&egui::Context::default(), "date-language", "klingon").is_err());
|
||||
h.set_option("date-language", "auto").unwrap();
|
||||
@@ -174,7 +180,6 @@ fn a_date_the_pdf_cannot_hold_is_refused_with_a_warning_first() {
|
||||
let s = h.state();
|
||||
assert!(s.session.get(s.views[0].id).unwrap().info.annotations.is_empty(), "nothing placed");
|
||||
}
|
||||
// PLAN: assumed shown_notice(&mut Harness) -> String (pdf-chrome-w9)
|
||||
let notice = crate::support::shown_notice(&mut h);
|
||||
let notice = crate::support::shown_notice(&h).unwrap_or_default();
|
||||
assert!(notice.contains("can't be written into the PDF yet"), "{notice}");
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{AppInfo, Host, ManualJobs, Picked, ScriptedFiles};
|
||||
use craft::host::{ManualJobs, Picked, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
@@ -21,10 +21,9 @@ trailer << /Root 1 0 R >>
|
||||
fn export_dialogs_write_images_and_text() {
|
||||
let files = Arc::new(ScriptedFiles::answering((0..3).map(|_| Picked::Paths(vec!["/out".into()]))));
|
||||
let jobs = Arc::new(ManualJobs::new());
|
||||
let host = Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" }).files(files.clone()).jobs(jobs.clone()).build();
|
||||
let host = crate::support::host_with(jobs.clone(), files.clone());
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
// PLAN: assumed `PdfCraftApp::with_host(host: Host) -> PdfCraftApp` (L-71)
|
||||
let mut app = PdfCraftApp::with_host(host);
|
||||
let mut app = crate::support::test_app(host);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "doc.pdf", None, FIXTURE.to_vec()).unwrap();
|
||||
app
|
||||
|
||||
@@ -38,8 +38,7 @@ fn form() -> Vec<u8> {
|
||||
|
||||
fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
||||
// PLAN: assumed `PdfCraftApp::with_host(Arc<Host>)` and `crate::support::host() -> Arc<Host>` (pdf-hub-w1, pdf-chrome-w9)
|
||||
let mut app = PdfCraftApp::with_host(crate::support::host());
|
||||
let mut app = crate::support::test_app(crate::support::host());
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.set_option(&egui::Context::default(), "left", "closed").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "triggers.pdf", None, form()).unwrap();
|
||||
|
||||
@@ -5,13 +5,13 @@ use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{ManualJobs, Picked, ScriptedFiles};
|
||||
use craft::ui::shell::PINNED_FILES_SHOWN;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
use pdfcraft_ui_egui::folders_ui::{MAX_PINNED, folder_name, location};
|
||||
use crate::support::AppHarness as _;
|
||||
|
||||
/// A one-page PDF.
|
||||
const FIXTURE: &[u8] = b"%PDF-1.7
|
||||
@@ -72,10 +72,7 @@ fn session(files: ScriptedFiles, setup: impl FnOnce(&mut PdfCraftApp) + 'static)
|
||||
let host_jobs = jobs.clone();
|
||||
let files = Arc::new(files);
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 1400.0)).build_eframe(move |_cc| {
|
||||
let info = craft::host::AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" };
|
||||
let host = craft::host::Host::builder(info).jobs(host_jobs).files(files).build();
|
||||
// PLAN: assumed `AppServices::detached()` (pdf-hub-w1): services with no clipboard, recovery directory, update source, intake or watch.
|
||||
let mut app = PdfCraftApp::with_host(Arc::new(host), pdfcraft_ui_egui::AppServices::detached());
|
||||
let mut app = crate::support::test_app(crate::support::host_with(host_jobs, files));
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
setup(&mut app);
|
||||
app
|
||||
@@ -107,8 +104,7 @@ fn a_pinned_folder_lists_its_newest_pdfs_on_home() {
|
||||
let picked = Picked::Paths(vec![PathBuf::from(&folder)]);
|
||||
let mut s = session(ScriptedFiles::answering([picked]), |_| {});
|
||||
s.h.get_by_label("Pin Folder…");
|
||||
let ctx = s.h.ctx.clone();
|
||||
assert!(s.h.execute(&ctx, "file.pin_folder"));
|
||||
assert!(s.h.execute("file.pin_folder"));
|
||||
s.settle();
|
||||
assert_eq!(s.h.state().pinned.folders, std::slice::from_ref(&folder));
|
||||
assert_eq!(listed(&s, &folder), ["newer.PDF", "older.pdf"], "newest first; no text files, hidden files or folders");
|
||||
@@ -206,7 +202,7 @@ fn a_pinned_folder_collapses_to_its_heading_and_stays_collapsed_after_a_restart(
|
||||
|
||||
// Settings are untrusted: only pinned folders, each once.
|
||||
let settings = serde_json::json!({ "pinned_folders": [a, b], "pinned_folders_collapsed": [b, b, "/not/pinned", 5] });
|
||||
restarted.apply_settings(&pdfcraft_ui_egui::import_json(&settings.to_string()).0);
|
||||
restarted.apply_settings(&pdfcraft_ui_egui::settings::import_json(&settings.to_string()).0);
|
||||
assert_eq!(restarted.pinned.collapsed, std::slice::from_ref(&b));
|
||||
restarted.unpin_folder(&b);
|
||||
assert!(restarted.pinned.collapsed.is_empty(), "unpinning forgets the folded state");
|
||||
@@ -249,7 +245,7 @@ fn pinned_folders_survive_a_restart() {
|
||||
b.apply_settings(&a.settings_snapshot());
|
||||
assert_eq!(b.pinned.folders, [folder]);
|
||||
for hostile in ["{\"pinned_folders\": [5, \"relative/path\"]}", "{not json"] {
|
||||
b.apply_settings(&pdfcraft_ui_egui::import_json(hostile).0);
|
||||
b.apply_settings(&pdfcraft_ui_egui::settings::import_json(hostile).0);
|
||||
assert!(b.pinned.folders.is_empty(), "only absolute folder paths are restored: {hostile}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ fn console_runs_scripts_against_the_document() {
|
||||
fn button_scripts_run_and_alert() {
|
||||
let mut h = harness();
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
h.state_mut().run_button_script(id, "hello", "getField('greeting').value = 'Hello from JavaScript'; app.alert('Filled in');");
|
||||
h.run_button_script(id, "hello", "getField('greeting').value = 'Hello from JavaScript'; app.alert('Filled in');");
|
||||
wait_for(&mut h, "Filled in");
|
||||
h.get_by_label("OK").click();
|
||||
wait_value(&mut h, "greeting", "Hello from JavaScript");
|
||||
@@ -235,10 +235,10 @@ fn document_scripts_and_preferences() {
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(2);
|
||||
assert!(!h.state().session.javascript());
|
||||
let saved = h.state().persist();
|
||||
let saved = h.state().settings_snapshot();
|
||||
let mut fresh = crate::control::new_app();
|
||||
fresh.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
fresh.restore(&saved);
|
||||
fresh.apply_settings(&saved);
|
||||
assert!(!fresh.session.javascript(), "the preference is remembered");
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ fn native_script_prompts_show_an_app_owned_caption() {
|
||||
] {
|
||||
let mut h = harness();
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
h.state_mut().run_button_script(id, "hello", script);
|
||||
h.run_button_script(id, "hello", script);
|
||||
wait_for(&mut h, body);
|
||||
assert!(h.query_by_label("This document's script is asking").is_some(), "{script}");
|
||||
assert_eq!(
|
||||
@@ -353,7 +353,7 @@ fn native_script_prompt_uses_the_german_catalog_when_available() {
|
||||
let mut h = harness();
|
||||
h.set_option("language", "de").unwrap();
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
h.state_mut().run_button_script(id, "hello", "app.response({cQuestion:'Test',bPassword:true});");
|
||||
h.run_button_script(id, "hello", "app.response({cQuestion:'Test',bPassword:true});");
|
||||
wait_for(&mut h, heading);
|
||||
assert!(h.query_by_label("Dokument: form.pdf").is_some());
|
||||
// The warning in the catalog's words, which translators may reword, and never the English.
|
||||
@@ -368,7 +368,7 @@ fn native_button_popup_and_response_resume_without_replaying_the_script() {
|
||||
for typed in [false, true] {
|
||||
let mut h = harness();
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
h.state_mut().run_button_script(id,"hello","var calls=typeof calls==='number'?calls:0;calls++;var choice=app.popUpMenuEx({cName:'Morning',cReturn:'08:00'});var extra=app.response({cTitle:'Manual time',cQuestion:'Suffix',cDefault:'x'});getField('greeting').value=choice+'/'+extra+'/'+calls;");
|
||||
h.run_button_script(id,"hello","var calls=typeof calls==='number'?calls:0;calls++;var choice=app.popUpMenuEx({cName:'Morning',cReturn:'08:00'});var extra=app.response({cTitle:'Manual time',cQuestion:'Suffix',cDefault:'x'});getField('greeting').value=choice+'/'+extra+'/'+calls;");
|
||||
wait_for(&mut h, "Morning");
|
||||
h.get_by_label("Morning").click();
|
||||
wait_for(&mut h, "Suffix");
|
||||
@@ -395,11 +395,11 @@ fn native_popup_cancellation_returns_null_and_preserves_the_single_invocation()
|
||||
let mut h = harness();
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
let script = "var calls=typeof calls==='number'?calls:0;calls++;var choice=app.popUpMenuEx({cName:'Choose',cReturn:'yes'});getField('greeting').value=String(choice)+'/'+calls;";
|
||||
h.state_mut().run_button_script(id, "hello", script);
|
||||
h.run_button_script(id, "hello", script);
|
||||
wait_for(&mut h, "Choose");
|
||||
h.get_by_label("Cancel").click();
|
||||
wait_value(&mut h, "greeting", "null/1");
|
||||
h.state_mut().run_button_script(id, "hello", script);
|
||||
h.run_button_script(id, "hello", script);
|
||||
wait_for(&mut h, "Choose");
|
||||
h.get_by_label("Cancel").click();
|
||||
wait_value(&mut h, "greeting", "null/2");
|
||||
@@ -413,7 +413,7 @@ fn native_popup_submenu_keeps_disabled_items_unselectable() {
|
||||
let script = "var calls=typeof calls==='number'?calls:0; calls++; \
|
||||
var choice=app.popUpMenuEx({cName:'Group',oSubMenu:[{cName:'Disabled',bEnabled:false}, \
|
||||
{cName:'Enabled',cReturn:'chosen'}]}); getField('greeting').value=choice+'/'+calls;";
|
||||
h.state_mut().run_button_script(id, "hello", script);
|
||||
h.run_button_script(id, "hello", script);
|
||||
wait_for(&mut h, "Group");
|
||||
h.get_by_label("Group").click();
|
||||
wait_for(&mut h, "Enabled");
|
||||
@@ -429,7 +429,7 @@ fn native_popup_submenu_keeps_disabled_items_unselectable() {
|
||||
fn native_popup_completion_is_discarded_after_the_document_is_edited() {
|
||||
let mut h = harness();
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
h.state_mut().run_button_script(id, "hello", "app.popUpMenuEx({cName:'Wait',cReturn:'yes'});getField('greeting').value='stale';");
|
||||
h.run_button_script(id, "hello", "app.popUpMenuEx({cName:'Wait',cReturn:'yes'});getField('greeting').value='stale';");
|
||||
wait_for(&mut h, "Wait");
|
||||
h.state_mut()
|
||||
.session
|
||||
@@ -457,7 +457,7 @@ fn native_button_events_match_headless_will_commit() {
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
let headless = h.state_mut().session.run_javascript(id, "String(event.willCommit);", Some("hello")).unwrap();
|
||||
assert_eq!(headless.result.as_deref(), Some("false"));
|
||||
h.state_mut().run_button_script(id, "hello", "getField('greeting').value=String(event.willCommit);");
|
||||
h.run_button_script(id, "hello", "getField('greeting').value=String(event.willCommit);");
|
||||
wait_value(&mut h, "greeting", "false");
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,9 @@ fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, P
|
||||
|
||||
fn harness_with(pdf: Vec<u8>, setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
// PLAN: assumed `crate::support::test_app(Arc<Host>) -> PdfCraftApp`, the shared harness (pdf-chrome-w9, w9-1).
|
||||
let host = Arc::new(craft::host::Host::builder(craft::host::AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" }).build());
|
||||
let mut app = crate::support::test_app(host);
|
||||
let mut app = crate::support::test_app(crate::support::host());
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes("layers.pdf", None, pdf).unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "layers.pdf", None, pdf).unwrap();
|
||||
app.set_option(&egui::Context::default(), "zoom", "150").unwrap();
|
||||
setup(&mut app);
|
||||
app
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
|
||||
use crate::support;
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{AppInfo, ManualJobs, Wake};
|
||||
use craft::host::ManualJobs;
|
||||
use craft::pages::ui::PageRangeOptions;
|
||||
use craft::pages::{PageRange, PageScope, Subset};
|
||||
use craft::platform::open::FileIntake;
|
||||
use craft::platform::watch::FileWatch;
|
||||
use craft::ui::dialog::{DialogId, dialog_id};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use pdfcraft_engine::MarkKind;
|
||||
use pdfcraft_ui_egui::{AppServices, PdfCraftApp};
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
use serde_json::json;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::Arc;
|
||||
@@ -83,13 +81,9 @@ impl Rig {
|
||||
}
|
||||
}
|
||||
|
||||
// PLAN: shared support helper (pdf-chrome-w9): the app on a host built over `ManualJobs`.
|
||||
/// The app on a host built over `ManualJobs`.
|
||||
fn app_on(jobs: Arc<ManualJobs>) -> PdfCraftApp {
|
||||
let info = AppInfo { id: "pdfcraft", name: "PdfCraft", version: env!("CARGO_PKG_VERSION") };
|
||||
let host = craft::host::Host::builder(info).jobs(jobs).build();
|
||||
let services =
|
||||
AppServices::new(Wake::none(), Box::new(support::RecordingClipboard::default()), None, None, FileIntake::for_tests(), FileWatch::inline());
|
||||
PdfCraftApp::with_host(Arc::new(host), services)
|
||||
support::held_app(jobs)
|
||||
}
|
||||
|
||||
fn harness() -> Rig {
|
||||
@@ -412,8 +406,7 @@ trailer << /Root 1 0 R >>
|
||||
}
|
||||
|
||||
/// The preview pager's position, read from its caption's accessible value: the shown page and the count.
|
||||
fn is_pager<'t>(n: &impl NodeT<'t>) -> bool {
|
||||
let ak = n.accesskit_node();
|
||||
fn is_pager(ak: &egui_kittest::kittest::AccessKitNode<'_>) -> bool {
|
||||
ak.role() != egui::accesskit::Role::SpinButton && ak.numeric_value().is_some() && ak.min_numeric_value() == Some(1.0)
|
||||
}
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ fn refusing_one_object_keeps_the_whole_group_and_its_selection() {
|
||||
drag(&mut h, a, b);
|
||||
assert_eq!(objects(&h), before);
|
||||
h.get_by_label("3 objects selected");
|
||||
assert!(h.state().toast.as_ref().unwrap().0.contains("Text used as a clipping path cannot be moved with this selection."));
|
||||
assert!(crate::support::shown_notice(&h).unwrap().contains("Text used as a clipping path cannot be moved with this selection."));
|
||||
assert!(!h.state().session.get(h.state().views[0].id).unwrap().dirty);
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ fn group_drag_respects_document_rotation_and_view_rotation() {
|
||||
let mut h = harness();
|
||||
let ctx_h = h.ctx.clone();
|
||||
assert!(h.state_mut().apply_edit(&ctx_h, Edit::RotatePages { pages: vec![0], degrees: document_rotation }));
|
||||
h.state_mut().views[0].rotate_view(true);
|
||||
crate::support::fire_menu(&mut h, "view.rotate.cw");
|
||||
h.run_steps(4);
|
||||
let before = objects(&h);
|
||||
let targets: Vec<_> = before.iter().filter(|o| o.text.as_deref() != Some("Keep here")).map(|o| o.target).collect();
|
||||
@@ -360,7 +360,7 @@ fn group_drags_cancel_on_focus_loss_tab_switch_home_and_modal_dialogs() {
|
||||
h.state_mut().open_bytes(&ctx_h, "other.pdf", None, fixture(false)).unwrap();
|
||||
}
|
||||
2 => h.state_mut().active = None,
|
||||
3 => h.state_mut().dialog = Some(pdfcraft_ui_egui::Dialog::About),
|
||||
3 => h.set_option("dialog", "about").unwrap(),
|
||||
_ => h.state_mut().request_document_url("https://example.invalid/", pdfcraft_ui_egui::LinkOrigin::Link),
|
||||
}
|
||||
h.run_steps(2);
|
||||
@@ -368,7 +368,7 @@ fn group_drags_cancel_on_focus_loss_tab_switch_home_and_modal_dialogs() {
|
||||
h.run_steps(2);
|
||||
h.input_mut().focused = true;
|
||||
h.state_mut().active = Some(0);
|
||||
h.state_mut().dialog = None;
|
||||
h.set_option("dialog", "none").unwrap();
|
||||
h.state_mut().pending_link = None;
|
||||
h.run_steps(4);
|
||||
assert_eq!(objects(&h), before, "cancelled gesture case {case}");
|
||||
@@ -417,7 +417,7 @@ fn a_shift_click_with_a_changed_paragraph_open_shows_the_notice_and_moves_nothin
|
||||
);
|
||||
h.run_steps(2);
|
||||
let notice = "Finish or discard the text being edited before selecting several objects.";
|
||||
assert!(h.state().toast.as_ref().is_some_and(|t| t.0.contains(notice)), "the notice says why");
|
||||
assert!(crate::support::shown_notice(&h).is_some_and(|t| t.contains(notice)), "the notice says why");
|
||||
for k in 1..=3 {
|
||||
h.hover_at(a + (b - a) * (k as f32 / 3.0));
|
||||
h.run_steps(2);
|
||||
@@ -653,9 +653,7 @@ fn a_picture_for_a_native_edit_paste_with_a_context_menu_open_lands_on_the_page(
|
||||
h.run_steps(2);
|
||||
assert!(egui::Popup::is_any_open(&h.ctx), "the context menu is open");
|
||||
let before = can_undo(&h, 0);
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().run_menu_command(&ctx, &craft_menu::CommandRef::new("edit.paste"));
|
||||
h.step();
|
||||
crate::support::fire_menu(&mut h, "edit.paste");
|
||||
assert!(crate::support::asked_for_the_clipboard(&h), "Edit ▸ Paste asked the platform for the clipboard");
|
||||
assert!(!egui::Popup::is_any_open(&h.ctx), "Edit ▸ Paste closed the context menu");
|
||||
h.event(egui::Event::PasteImage(std::sync::Arc::new(egui::ColorImage::filled([30, 20], egui::Color32::GRAY))));
|
||||
|
||||
@@ -4,18 +4,16 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{InlineJobs, Picked, ScriptedFiles, Wake};
|
||||
use craft::host::{InlineJobs, Picked, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_engine::ocr::{OcrPage, OcrSettings, PlacedWord};
|
||||
use pdfcraft_engine::{AddedText, Edit, Session, export};
|
||||
use pdfcraft_ui_egui::{AppServices, PdfCraftApp};
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
|
||||
/// The app on a host whose jobs run at once and whose pickers answer from `files`.
|
||||
fn app_on(files: Arc<ScriptedFiles>) -> PdfCraftApp {
|
||||
// PLAN: assumed `support::host(jobs, files) -> craft::host::Host` (pdf-shell-w13's test support) and `PdfCraftApp::with_host(host, AppServices)`.
|
||||
let host = crate::support::host(Arc::new(InlineJobs), files);
|
||||
PdfCraftApp::with_host(host, AppServices { wake: Wake::none(), ..Default::default() })
|
||||
crate::support::test_app(crate::support::host_with(Arc::new(InlineJobs), files))
|
||||
}
|
||||
|
||||
/// Sets a field of the open dialog as the user editing that control would.
|
||||
@@ -30,7 +28,7 @@ fn set_field(h: &mut Harness<'_, PdfCraftApp>, field: &str, value: serde_json::V
|
||||
/// Presses OK of the open Recognize Text dialog.
|
||||
fn confirm_recognize(h: &mut Harness<'_, PdfCraftApp>) {
|
||||
let ctx = h.ctx.clone();
|
||||
assert!(h.state_mut().dialogs.confirm::<craft_ui_patterns::HostedParamDialog>(&ctx), "OK was enabled");
|
||||
assert!(h.state_mut().dialogs.confirm::<craft::ui::patterns::form_dialogs::HostedParamDialog>(&ctx), "OK was enabled");
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
@@ -231,7 +229,8 @@ fn editing_a_scanned_page_recognizes_its_text_first_and_only_once() {
|
||||
assert!(h.state().ocr_run.is_none(), "finished");
|
||||
assert_eq!(h.state().session.get(id).unwrap().can_undo(), Some("Recognize text"));
|
||||
// Undo takes the text layer away and Edit does not put it back.
|
||||
h.state_mut().undo();
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().undo(&ctx);
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().session.get(id).unwrap().can_undo(), None);
|
||||
h.run_steps(4);
|
||||
|
||||
@@ -158,21 +158,21 @@ fn a_full_screen_document_shows_its_non_full_screen_panel_outside_full_screen()
|
||||
let mut h = harness(&format!("/PageMode /FullScreen /ViewerPreferences << /NonFullScreenPageMode /{mode} >>"));
|
||||
// The prompt (`ask_full_screen`) is on the dialog host, found by its question.
|
||||
h.get_by_label("Open in Full Screen mode?");
|
||||
assert_eq!(h.state().right, want, "{mode}: the panel behind the prompt");
|
||||
assert_eq!(crate::support::right(h.state()), want, "{mode}: the panel behind the prompt");
|
||||
// Declining it leaves that panel.
|
||||
h.get_by_label("Not now").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!((h.state().full_screen(), h.state().right), (false, want), "{mode}: declined");
|
||||
assert_eq!((h.state().full_screen(), crate::support::right(h.state())), (false, want), "{mode}: declined");
|
||||
// Entering and leaving full screen comes back to it.
|
||||
h.state_mut().apply_full_screen(true);
|
||||
h.state_mut().set_full_screen(true);
|
||||
h.run_steps(2);
|
||||
h.state_mut().apply_full_screen(false);
|
||||
h.state_mut().set_full_screen(false);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().right, want, "{mode}: after full screen");
|
||||
assert_eq!(crate::support::right(h.state()), want, "{mode}: after full screen");
|
||||
}
|
||||
// Without /PageMode /FullScreen the entry means nothing.
|
||||
let h = harness("/ViewerPreferences << /NonFullScreenPageMode /UseThumbs >>");
|
||||
assert_eq!(h.state().right, None);
|
||||
assert_eq!(crate::support::right(h.state()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -184,11 +184,11 @@ fn a_full_screen_document_with_an_outline_shows_it_only_when_it_asks_to() {
|
||||
("/ViewerPreferences << /NonFullScreenPageMode /UseOutlines >>", Some(RightPanel::Bookmarks)),
|
||||
] {
|
||||
let h = harness(&format!("/Outlines 9 0 R /PageMode /FullScreen {prefs}"));
|
||||
assert_eq!(h.state().right, want, "{prefs}");
|
||||
assert_eq!(crate::support::right(h.state()), want, "{prefs}");
|
||||
}
|
||||
// Not in full screen, a document with an outline still opens on it.
|
||||
let h = harness("/Outlines 9 0 R");
|
||||
assert_eq!(h.state().right, Some(RightPanel::Bookmarks));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Bookmarks));
|
||||
}
|
||||
|
||||
/// Named destinations for open parameters: `intro` (page 2) in the catalog's /Dests and
|
||||
@@ -230,7 +230,7 @@ fn a_file_named_with_open_parameters_opens_at_their_destination() {
|
||||
assert_eq!(h.state().views[0].current(), page, "{parameters}");
|
||||
let app = h.state();
|
||||
assert_eq!(app.session.get(app.views[0].id).and_then(|d| d.path.clone()).as_deref(), Some(path.as_str()), "{parameters}: the file itself");
|
||||
assert!(h.state().notices.posted().is_empty(), "{parameters}");
|
||||
assert!(crate::support::shown_notice(&h).is_none(), "{parameters}");
|
||||
}
|
||||
// A name the file doesn't define: it opens where it would have, and says so.
|
||||
let mut h = bare_window();
|
||||
@@ -238,7 +238,7 @@ fn a_file_named_with_open_parameters_opens_at_their_destination() {
|
||||
crate::support::wait_until(&mut h, "the manual", |app| app.views.len() == 1);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().views[0].current(), 2);
|
||||
assert!(!h.state().notices.posted().is_empty(), "the unapplied name is told");
|
||||
assert!(crate::support::shown_notice(&h).is_some(), "the unapplied name is told");
|
||||
// A path that names no file, before a `#` or as a whole, still fails as before.
|
||||
let mut h = bare_window();
|
||||
assert!(!matches!(h.state_mut().open_path(&format!("{path}.missing#page=2")), OpenOutcome::Opened | OpenOutcome::Focused));
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
//! The app's rules for one optimization at a time and the exclusion with Enhance scanned file, driven as a user fires the commands.
|
||||
//!
|
||||
//! PLAN: `mod optimize;` belongs in `tests/it/main.rs` (pdf-shell-w9's hunk). The held host is assumed
|
||||
//! `support::held_app(jobs: Arc<ManualJobs>) -> PdfCraftApp` (a `PdfCraftApp::with_host` over a host with `ManualJobs`, pdf-hub-w1 L-71) and
|
||||
//! `support::shown_notice(&Harness) -> Option<String>` (pdf-chrome-w9).
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::host::ManualJobs;
|
||||
use craft::host::{ManualJobs, Picked, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
|
||||
@@ -18,11 +14,12 @@ fn held() -> (Arc<ManualJobs>, Harness<'static, PdfCraftApp>) {
|
||||
let jobs = Arc::new(ManualJobs::new());
|
||||
let queue = jobs.clone();
|
||||
let out = std::env::temp_dir().join(format!("pdfcraft-optimize-held-{}.pdf", std::process::id()));
|
||||
// Every Reduce asks once where to save: each ask is answered with `out`.
|
||||
let files = Arc::new(ScriptedFiles::answering((0..4).map(|_| Picked::Paths(vec![out.clone()]))));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(move |_cc| {
|
||||
let mut app = support::held_app(queue);
|
||||
let mut app = support::test_app(support::host_with(queue, files));
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes("notes.txt", None, b"hello".to_vec()).unwrap();
|
||||
app.save_override = Some(out.to_string_lossy().into_owned());
|
||||
app.open_bytes(&egui::Context::default(), "notes.txt", None, b"hello".to_vec()).unwrap();
|
||||
app
|
||||
});
|
||||
h.run_steps(2);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! A document edit cancels an Organize drag before old page indices can be used.
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use egui::{Modifiers, PointerButton, Pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
@@ -99,7 +100,7 @@ fn check_undo_cancels_drag(copying: bool) {
|
||||
assert_eq!(page_texts(h.state()), ["Page 2", "Page 3", "Page 4", "Page 1"]);
|
||||
let (to, modifiers) = start_drag(&mut h, copying);
|
||||
// The source index now belongs to Page 2. Undo changes it back to Page 1.
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.run_steps(2);
|
||||
assert_eq!(page_texts(h.state()), ["Page 1", "Page 2", "Page 3", "Page 4"]);
|
||||
h.hover_at(to - egui::vec2(1.0, 0.0));
|
||||
@@ -109,10 +110,10 @@ fn check_undo_cancels_drag(copying: bool) {
|
||||
assert_eq!(page_texts(h.state()), expected, "releasing the old drag must not move or copy a different page");
|
||||
assert_eq!(h.state().session.get(h.state().views[0].id).unwrap().can_redo(), Some("Move page"), "the cancelled gesture leaves Redo available");
|
||||
assert_saved_order(&h, &expected);
|
||||
h.state_mut().redo();
|
||||
h.redo();
|
||||
h.run_steps(2);
|
||||
assert_eq!(page_texts(h.state()), ["Page 2", "Page 3", "Page 4", "Page 1"], "the preserved Redo still applies the original edit");
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.run_steps(2);
|
||||
assert_eq!(page_texts(h.state()), expected);
|
||||
|
||||
@@ -121,10 +122,10 @@ fn check_undo_cancels_drag(copying: bool) {
|
||||
release(&mut h, to, modifiers);
|
||||
let changed = if copying { vec!["Page 1", "Page 2", "Page 3", "Page 1", "Page 4"] } else { vec!["Page 2", "Page 3", "Page 1", "Page 4"] };
|
||||
assert_eq!(page_texts(h.state()), changed);
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.run_steps(2);
|
||||
assert_eq!(page_texts(h.state()), expected);
|
||||
h.state_mut().redo();
|
||||
h.redo();
|
||||
h.run_steps(2);
|
||||
assert_eq!(page_texts(h.state()), changed);
|
||||
assert_saved_order(&h, &changed);
|
||||
@@ -145,10 +146,10 @@ fn redo_cancels_an_organize_drag_before_pointer_release() {
|
||||
let mut h = organize();
|
||||
let ctx_h = h.ctx.clone();
|
||||
assert!(h.state_mut().apply_edit(&ctx_h, Edit::MovePages { pages: vec![0], to: 3 }));
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.run_steps(2);
|
||||
let (to, modifiers) = start_drag(&mut h, false);
|
||||
h.state_mut().redo();
|
||||
h.redo();
|
||||
h.run_steps(2);
|
||||
release(&mut h, to, modifiers);
|
||||
let expected = ["Page 2", "Page 3", "Page 4", "Page 1"];
|
||||
|
||||
@@ -241,7 +241,7 @@ fn every_panel_matches_its_snapshot() {
|
||||
let mut failures = Vec::new();
|
||||
for p in ALL {
|
||||
let (h, name) = open(p);
|
||||
assert_eq!(h.state().right, Some(p), "{name} opens its own panel");
|
||||
assert_eq!(crate::support::right(h.state()), Some(p), "{name} opens its own panel");
|
||||
if let Err(e) = check(&h, name) {
|
||||
failures.push(e);
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ fn removing_all_links_and_undo() {
|
||||
assert_eq!(links(&h).len(), 0);
|
||||
|
||||
// Undo restores the link
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.run_steps(3);
|
||||
assert_eq!(links(&h).len(), 1);
|
||||
}
|
||||
|
||||
@@ -655,7 +655,7 @@ fn a_late_startup_url_preserves_the_current_edit_workspace_and_save_target() {
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().apply_edit(&ctx_h, Edit::DeletePages { pages: vec![1] });
|
||||
h.state_mut().mode = Mode::Edit;
|
||||
h.state_mut().right = Some(RightPanel::Pages);
|
||||
h.set_option("panel", "pages").unwrap();
|
||||
h.state_mut().left = LeftPanel::AllTools;
|
||||
h.state_mut().left_open = false;
|
||||
h.state_mut().quick_tool = QuickTool::Hand;
|
||||
@@ -664,7 +664,7 @@ fn a_late_startup_url_preserves_the_current_edit_workspace_and_save_target() {
|
||||
|
||||
assert_eq!(h.state().active_ids().unwrap().1, active, "Save still targets the user's document");
|
||||
assert_eq!(h.state().mode, Mode::Edit);
|
||||
assert_eq!(h.state().right, Some(RightPanel::Pages));
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Pages));
|
||||
assert_eq!(h.state().left, LeftPanel::AllTools);
|
||||
assert!(!h.state().left_open);
|
||||
assert_eq!(h.state().quick_tool, QuickTool::Hand);
|
||||
@@ -769,7 +769,7 @@ fn a_startup_url_does_not_replace_another_documents_password_prompt() {
|
||||
assert_eq!(h.state().password_prompt.as_ref().unwrap().name, "local-encrypted.pdf");
|
||||
assert!(h.state().views.is_empty());
|
||||
assert!(h.query_by_label("late.pdf").is_none(), "the startup file waits for the prompt");
|
||||
h.state_mut().submit_password((!cancel).then(|| "test-password".into()));
|
||||
h.submit_password((!cancel).then(|| "test-password".into()));
|
||||
settle(&mut h, "local password completion and startup open", |app| {
|
||||
app.password_prompt.is_none() && app.views.len() == if cancel { 1 } else { 2 }
|
||||
});
|
||||
@@ -804,13 +804,13 @@ fn unlocking_a_late_startup_url_keeps_it_in_the_background() {
|
||||
h.steps(2);
|
||||
assert_eq!(h.state().active, Some(0));
|
||||
assert_eq!(h.state().password_prompt.as_ref().unwrap().name, "late-encrypted.pdf");
|
||||
h.state_mut().submit_password(Some("wrong-password".into()));
|
||||
h.submit_password(Some("wrong-password".into()));
|
||||
settle(&mut h, "startup wrong-password reply", |app| {
|
||||
app.password_prompt.as_ref().is_some_and(|p| p.name == "late-encrypted.pdf" && p.error.as_deref() == Some("Incorrect password. Try again."))
|
||||
});
|
||||
assert!(h.state().password_prompt.as_ref().unwrap().error.is_some());
|
||||
assert_eq!(h.state().active, Some(0));
|
||||
h.state_mut().submit_password(Some("test-password".into()));
|
||||
h.submit_password(Some("test-password".into()));
|
||||
settle(&mut h, "unlocked startup document", |app| app.password_prompt.is_none() && app.views.len() == 2);
|
||||
assert!(h.state().password_prompt.is_none());
|
||||
assert_eq!(h.state().active, Some(0));
|
||||
@@ -884,7 +884,7 @@ fn a_background_startup_forms_script_notice_waits_until_its_tab_is_selected() {
|
||||
fn a_background_forms_highlight_request_applies_at_once() {
|
||||
let mut h = harness(&[3]);
|
||||
// Highlighting is on by default: start from a user who turned it off.
|
||||
h.state_mut().view_defaults.highlight_fields = false;
|
||||
h.state_mut().apply_settings(&pdfcraft_ui_egui::settings::import_json(r#"{"highlight_fields": false}"#).0);
|
||||
h.state_mut().views[0].session.highlight_fields = false;
|
||||
h.steps(1);
|
||||
h.deliver("late-form.pdf", pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::layout_ready_template()));
|
||||
@@ -892,7 +892,7 @@ fn a_background_forms_highlight_request_applies_at_once() {
|
||||
assert_eq!(h.state().active, Some(0), "it opened behind the current document");
|
||||
assert!(h.state().views[1].session.highlight_fields, "the background form is highlighted");
|
||||
assert!(!h.state().views[0].session.highlight_fields, "the current document is left as it was");
|
||||
assert!(h.state().view_defaults.highlight_fields, "the next document opens highlighted");
|
||||
assert_eq!(h.state().settings_snapshot().behavior.highlight_fields, Some(true), "the next document opens highlighted");
|
||||
}
|
||||
|
||||
/// Embedded bytes and the PDF's original /UF name stay independent of the Save suggestion.
|
||||
|
||||
@@ -7,11 +7,7 @@ use pdfcraft_ui_egui::{LeftPanel, PdfCraftApp};
|
||||
|
||||
fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 1000.0)).build_eframe(move |_cc| {
|
||||
let info = craft::host::AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" };
|
||||
let jobs = std::sync::Arc::new(craft::host::ManualJobs::new());
|
||||
let host = craft::host::Host::builder(info).jobs(jobs).build();
|
||||
// PLAN: assumed `AppServices::detached()` (pdf-hub-w1): services with no clipboard, recovery directory, update source, intake or watch.
|
||||
let mut app = PdfCraftApp::with_host(std::sync::Arc::new(host), pdfcraft_ui_egui::AppServices::detached());
|
||||
let mut app = crate::support::held_app(std::sync::Arc::new(craft::host::ManualJobs::new()));
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
setup(&mut app);
|
||||
app
|
||||
@@ -79,7 +75,7 @@ fn persistence_round_trip_and_sanitization() {
|
||||
"pinned_tools": ["redact", "nonexistent_junk", "redact", "edit", "another_unknown", "protect"]
|
||||
})
|
||||
.to_string();
|
||||
restored.apply_settings(&pdfcraft_ui_egui::import_json(&malicious_or_corrupt).0);
|
||||
restored.apply_settings(&pdfcraft_ui_egui::settings::import_json(&malicious_or_corrupt).0);
|
||||
assert_eq!(restored.pinned_tools, vec!["redact", "edit", "protect"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,13 +165,12 @@ fn highlighted_checkbox_pdf() -> Vec<u8> {
|
||||
/// The services a pointer test gives the app: no wake-ups, a clipboard fed by paste events (a
|
||||
/// paste arrives in the pass that reads it, so its pass clock never needs to move) whose copies go
|
||||
/// nowhere, a recovery folder of the test process's own, and no update source.
|
||||
// PLAN: assumed `AppServices::new(wake, clipboard, recovery_dir, update_source, intake, watch)` (L-207).
|
||||
fn services() -> AppServices {
|
||||
let clipboard = EventClipboard::new(|| 0, |_| Ok(0));
|
||||
let clipboard = craft::platform::clipboard::Clipboard::new(EventClipboard::new(|| 0, |_| Ok(0)));
|
||||
let recovery = std::env::temp_dir().join(format!("pdfcraft-pointer-{}", std::process::id()));
|
||||
let (intake, _sender) = craft::platform::open::FileIntake::new(Wake::none());
|
||||
let watch = craft::platform::watch::FileWatch::new(Wake::none()).inline();
|
||||
AppServices::new(Wake::none(), clipboard, recovery, None, intake, watch)
|
||||
AppServices::new(Wake::none(), clipboard, Some(recovery), None, intake, watch)
|
||||
}
|
||||
|
||||
/// The app with `pdf` open at `zoom` percent and its first frames run. The left panel stays
|
||||
@@ -1362,7 +1361,7 @@ fn a_right_click_with_edit_text_on_added_text_unselects_the_comment() {
|
||||
/// where they touch, which lies on both.
|
||||
fn touching_pages(tool: impl FnOnce(&mut PdfCraftApp)) -> (Harness<'static, PdfCraftApp>, egui::Pos2) {
|
||||
let mut h = open(two_pages_pdf(), "100", false);
|
||||
h.state_mut().views[0].show_page_gaps = false;
|
||||
h.state_mut().views[0].view.page_gaps = false;
|
||||
tool(h.state_mut());
|
||||
h.run_steps(4);
|
||||
let (one, two) = {
|
||||
@@ -1468,7 +1467,7 @@ fn a_right_click_with_the_button_held_opens_the_selected_comments_menu() {
|
||||
#[test]
|
||||
fn a_shift_click_where_two_pages_touch_keeps_what_it_selected() {
|
||||
let mut h = open(bottom_line_pages_pdf(), "100", false);
|
||||
h.state_mut().views[0].show_page_gaps = false;
|
||||
h.state_mut().views[0].view.page_gaps = false;
|
||||
assert!(h.execute("edit.edit_text"));
|
||||
h.run_steps(4);
|
||||
let (one, two) = {
|
||||
@@ -1565,7 +1564,7 @@ fn with_edit_text_a_right_click_on_a_picture_under_a_link_selects_the_picture()
|
||||
#[test]
|
||||
fn a_drag_past_a_pages_edge_under_its_open_paragraph_is_the_next_pages() {
|
||||
let mut h = open(bottom_line_pages_pdf(), "100", false);
|
||||
h.state_mut().views[0].show_page_gaps = false;
|
||||
h.state_mut().views[0].view.page_gaps = false;
|
||||
h.state_mut().quick_tool = QuickTool::EditText;
|
||||
h.run_steps(4);
|
||||
let (one, two) = {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{AppInfo, Host, ManualJobs, ScriptedFiles};
|
||||
use craft::host::{ManualJobs, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
@@ -78,10 +78,7 @@ fn harness_with(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> (Harness<'sta
|
||||
let parts = Mutex::new(Some((jobs.clone(), setup)));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let (jobs, setup) = parts.lock().unwrap().take().unwrap();
|
||||
// PLAN: `AppInfo` fields assumed (pdf-hub-w1, L-71).
|
||||
let host =
|
||||
Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" }).jobs(jobs).files(Arc::new(ScriptedFiles::held())).build();
|
||||
let mut app = PdfCraftApp::with_host(Arc::new(host));
|
||||
let mut app = crate::support::test_app(crate::support::host_with(jobs, Arc::new(ScriptedFiles::held())));
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
setup(&mut app);
|
||||
app
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
//! does (`ui.dialog.set`, its action ids, its OK) and reads the result through its `State`.
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{AppInfo, FileIntake, FileWatch, Host, ManualJobs, Picked, ScriptedFiles, Wake};
|
||||
use craft::host::{ManualJobs, Picked, ScriptedFiles};
|
||||
use craft::print::ui::{Destination, HostedPrint};
|
||||
use craft_ui::dialog::{DialogId, HeldOk};
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use pdfcraft_engine::print::spool;
|
||||
use pdfcraft_ui_egui::{AppServices, PdfCraftApp};
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
use serde_json::json;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -54,8 +54,7 @@ pub(crate) fn rig_on(files: ScriptedFiles, setup: impl FnOnce(&mut PdfCraftApp)
|
||||
let files = Arc::new(files);
|
||||
let (host_jobs, host_files) = (jobs.clone(), files.clone());
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let host = Host::builder(AppInfo { id: "pdfcraft", name: "PdfCraft", version: "test" }).jobs(host_jobs).files(host_files).build();
|
||||
let mut app = PdfCraftApp::with_host(Arc::new(host), AppServices::new(Wake::none(), FileIntake::new(Wake::none()), FileWatch::inline()));
|
||||
let mut app = crate::support::test_app(crate::support::host_with(host_jobs, host_files));
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
setup(&mut app);
|
||||
app
|
||||
@@ -936,7 +935,7 @@ fn print_restricted_documents_say_so_before_the_dialog() {
|
||||
assert!(!h.execute("print.dialog"));
|
||||
h.run_steps(2);
|
||||
assert!(!h.is_open());
|
||||
assert_eq!(h.state().toast.as_ref().map(|t| t.0.as_str()), Some("The document's security settings don't allow printing"));
|
||||
assert_eq!(crate::support::shown_notice(&h).as_deref(), Some("The document's security settings don't allow printing"));
|
||||
}
|
||||
|
||||
/// With no document open the top bar's Print button is disabled too, but not for security
|
||||
@@ -975,8 +974,8 @@ fn paper_choice_survives_cancel_and_settings_restore() {
|
||||
assert!(!h.is_open());
|
||||
assert_eq!(h.state().print_draft, before_cancel, "cancel keeps the existing draft behavior");
|
||||
let snapshot = h.state().settings_snapshot();
|
||||
assert_eq!(snapshot.print.paper.as_deref(), Some("A4"), "store the canonical name, not its position");
|
||||
assert!(snapshot.print.paper_overridden, "explicitly chosen paper records override flag");
|
||||
assert_eq!(snapshot.print.print_paper.as_deref(), Some("A4"), "store the canonical name, not its position");
|
||||
assert_eq!(snapshot.print.print_paper_overridden, Some(true), "explicitly chosen paper records override flag");
|
||||
let saved = saved_json(h.state());
|
||||
let mut app = crate::control::new_app();
|
||||
restore(&mut app, &saved);
|
||||
@@ -1007,7 +1006,7 @@ fn paper_choice_survives_cancel_and_settings_restore() {
|
||||
restarted.set("paper", json!("US Letter"));
|
||||
restarted.close();
|
||||
let saved = saved_json(restarted.state());
|
||||
assert_eq!(restarted.state().settings_snapshot().print.paper.as_deref(), Some("US Letter"));
|
||||
assert_eq!(restarted.state().settings_snapshot().print.print_paper.as_deref(), Some("US Letter"));
|
||||
let mut again = harness_with_settings(Some(saved));
|
||||
again.open();
|
||||
assert_eq!(again.state().print_draft.paper, letter);
|
||||
@@ -1021,7 +1020,7 @@ fn paper_restore_accepts_canonical_names_and_ignores_invalid_settings() {
|
||||
restore(&mut app, &json!({"print_paper": name}).to_string());
|
||||
assert_eq!(app.print_draft.paper, index);
|
||||
assert!(!app.print_draft.paper_overridden);
|
||||
assert_eq!(app.settings_snapshot().print.paper.as_deref(), Some(*name));
|
||||
assert_eq!(app.settings_snapshot().print.print_paper.as_deref(), Some(*name));
|
||||
}
|
||||
for invalid in [
|
||||
"not JSON",
|
||||
@@ -1049,7 +1048,7 @@ fn paper_restore_accepts_canonical_names_and_ignores_invalid_settings() {
|
||||
}
|
||||
let mut app = crate::control::new_app();
|
||||
app.print_draft.paper = usize::MAX;
|
||||
assert_eq!(app.settings_snapshot().print.paper, None);
|
||||
assert_eq!(app.settings_snapshot().print.print_paper, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -55,8 +55,8 @@ fn protecting_for_viewing_requires_matching_passwords_and_saves_encrypted() {
|
||||
assert!(s.open("p.pdf", None, bytes, Some("Open-Sesame-42")).is_ok());
|
||||
// Remove security is now offered, and undo also takes the protection back.
|
||||
assert!(h.execute("protect.remove"));
|
||||
h.state_mut().undo();
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.undo();
|
||||
assert!(!h.state().session.get(id).unwrap().info.encrypted);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ fn restore(app: &mut PdfCraftApp, json: &str) {
|
||||
app.apply_settings(&import_json(json).0);
|
||||
}
|
||||
|
||||
/// The recent list the app would write to its settings.
|
||||
fn saved_recent(app: &PdfCraftApp) -> Vec<RecentFile> {
|
||||
app.settings_snapshot().recent.recent.as_deref().map(|text| serde_json::from_str(text).expect("the saved list reads back")).unwrap_or_default()
|
||||
}
|
||||
|
||||
const PDF: &[u8] = include_bytes!("../data/form.pdf");
|
||||
|
||||
fn recent_file(name: &str) -> RecentFile {
|
||||
@@ -67,7 +72,7 @@ fn at_zero_opening_a_file_records_nothing() {
|
||||
app.recent_limit = 0;
|
||||
open(&mut app, "first.pdf");
|
||||
assert!(app.recent.is_empty());
|
||||
assert!(app.settings_snapshot().recent.is_empty(), "and the saved list is empty"); // PLAN: assumed `recent` field of the snapshot (pdf-shell-w9)
|
||||
assert!(saved_recent(&app).is_empty(), "and the saved list is empty");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -91,7 +96,7 @@ fn at_zero_the_menu_and_the_palette_have_nothing_to_open() {
|
||||
support::open_menu(&mut h, "File");
|
||||
assert!(h.query_by(|n| n.label().as_deref() == Some("Open Recent") && n.is_disabled()).is_some(), "Open Recent is disabled");
|
||||
assert!(h.execute("file.open_recent"));
|
||||
assert!(h.state().toast.as_ref().is_some_and(|(m, _)| m.contains("No recent files")));
|
||||
assert!(support::shown_notice(&h).is_some_and(|m| m.contains("No recent files")));
|
||||
assert!(h.state().views.is_empty(), "and nothing opened");
|
||||
}
|
||||
|
||||
@@ -133,7 +138,7 @@ fn the_longest_list_scrolls_in_the_smallest_window_down_to_clear() {
|
||||
fn settings_saved_while_preferences_is_open_already_leave_the_rest_out() {
|
||||
let mut app = app_with(&["first.pdf", "second.pdf"]);
|
||||
app.recent_limit = 1;
|
||||
let saved: Vec<String> = app.settings_snapshot().recent.iter().map(|r| r.name.clone()).collect();
|
||||
let saved: Vec<String> = saved_recent(&app).iter().map(|r| r.name.clone()).collect();
|
||||
assert_eq!(saved, ["first.pdf"]);
|
||||
}
|
||||
|
||||
@@ -184,9 +189,8 @@ fn restoring_settings_does_not_check_recent_files_and_a_frame_drops_the_gone_one
|
||||
assert_eq!(paths, [here.as_str(), gone.as_str()], "restoring keeps every entry without asking whether its file exists");
|
||||
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 1600.0)).build_eframe(move |_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
let mut app = support::inline_app();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.run_inline = true;
|
||||
restore(&mut app, &json);
|
||||
app
|
||||
});
|
||||
|
||||
@@ -108,7 +108,7 @@ fn crashed_session(dir: &Path, bytes: Vec<u8>, password: Option<&str>, path: Opt
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().open_bytes(&ctx_h, "work.pdf", path.map(str::to_string), bytes).unwrap();
|
||||
if let Some(pw) = password {
|
||||
h.state_mut().submit_password(Some(pw.to_string()));
|
||||
h.submit_password(Some(pw.to_string()));
|
||||
}
|
||||
settle(&mut h, &rig, "the document opening", |app| app.views.len() == 1);
|
||||
let ctx_h = h.ctx.clone();
|
||||
@@ -352,7 +352,7 @@ fn a_cancelled_recovery_password_does_not_attach_to_the_next_unlocked_document()
|
||||
|
||||
let app = h.state_mut();
|
||||
app.open_bytes(&egui::Context::default(), "B.pdf", Some("/docs/B.pdf".into()), encrypted(fixture(1), "pw-b")).unwrap();
|
||||
app.submit_password(Some("pw-b".into()));
|
||||
app.submit_password(&egui::Context::default(), Some("pw-b".into()));
|
||||
settle(&mut h, &rig, "unlocked B", |app| app.views.len() == 1);
|
||||
let app = h.state();
|
||||
let b = app.session.get(app.views[0].id).unwrap();
|
||||
|
||||
@@ -2,19 +2,26 @@
|
||||
//! image…), so what the menu does is about that tab's area; leaving Snapshot puts away the area in
|
||||
//! every tab, not only the one on screen.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::support::AppHarness as _;
|
||||
use craft::host::{Picked, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::{PdfCraftApp, QuickTool};
|
||||
|
||||
/// Two tabs, a.pdf (0) and b.pdf (1), with Snapshot chosen and the system clipboard left alone.
|
||||
fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
harness_with(Arc::new(ScriptedFiles::new()))
|
||||
}
|
||||
|
||||
/// [`harness`] whose file picks `files` answers.
|
||||
fn harness_with(files: Arc<ScriptedFiles>) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = crate::control::app_with_files(files);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "a.pdf", None, crate::support::fixtures::pdf_pages(2)).unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "b.pdf", None, crate::support::fixtures::pdf_pages(2)).unwrap();
|
||||
// PLAN: the injected clipboard of pdf-shell-w17 replaces `system_clipboard`.
|
||||
app
|
||||
});
|
||||
crate::support::settle(&mut h);
|
||||
@@ -27,7 +34,7 @@ fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
fn snapshot_in(h: &mut Harness<'static, PdfCraftApp>, index: usize, area: [f32; 4]) -> (u32, u32, Vec<u8>) {
|
||||
h.state_mut().active = Some(index);
|
||||
h.run_steps(2);
|
||||
h.state_mut().snapshot(index, 0, area).expect("a snapshot");
|
||||
h.snapshot(index, 0, area).expect("a snapshot");
|
||||
h.state_mut().views[index].session.area_pick = Some((0, area));
|
||||
h.run_steps(2);
|
||||
let (w, hgt, px) = h.state().last_snapshot.clone().expect("kept");
|
||||
@@ -38,7 +45,10 @@ fn snapshot_in(h: &mut Harness<'static, PdfCraftApp>, index: usize, area: [f32;
|
||||
/// snapshot B took last.
|
||||
#[test]
|
||||
fn save_as_image_writes_this_tabs_area() {
|
||||
let mut h = harness();
|
||||
let dir = std::env::temp_dir().join(format!("pdfcraft-snapshot-tabs-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let file = dir.join("a area.png");
|
||||
let mut h = harness_with(Arc::new(ScriptedFiles::answering([Picked::Paths(vec![file.clone()])])));
|
||||
// Areas of different shapes, so their pictures can't be mistaken for each other.
|
||||
let (wa, ha, pa) = snapshot_in(&mut h, 0, [10.0, 130.0, 150.0, 170.0]);
|
||||
let (wb, hb, _) = snapshot_in(&mut h, 1, [20.0, 20.0, 60.0, 140.0]);
|
||||
@@ -47,11 +57,6 @@ fn save_as_image_writes_this_tabs_area() {
|
||||
h.state_mut().active = Some(0);
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().views[0].session.area_pick, Some((0, [10.0, 130.0, 150.0, 170.0])));
|
||||
let dir = std::env::temp_dir().join(format!("pdfcraft-snapshot-tabs-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let file = dir.join("a area.png");
|
||||
// PLAN: `save_override` goes (pdf-shell-w16): answer the pick through `ScriptedFiles` on the host given to `with_host`.
|
||||
h.state_mut().save_override = Some(file.to_string_lossy().into_owned());
|
||||
h.get_by_label("Save as image…").click();
|
||||
h.run_steps(3);
|
||||
let png = std::fs::read(&file).expect("written");
|
||||
|
||||
@@ -24,10 +24,9 @@ fn page_size(s: &PdfCraftApp, i: usize) -> Option<egui::Vec2> {
|
||||
/// The label of the unsaved-changes dialog's "don't keep the changes" answer on this OS, as the
|
||||
/// framework words it.
|
||||
fn dont_save() -> String {
|
||||
// PLAN: assumed paths `craft::ui::dialog::DialogWords` and `craft::i18n::WordSet`; the fields display as their English text.
|
||||
use craft::i18n::WordSet as _;
|
||||
let words = craft::ui::dialog::DialogWords::english();
|
||||
if cfg!(target_os = "macos") { words.unsaved_dont_save } else { words.unsaved_no }.to_string()
|
||||
if cfg!(target_os = "macos") { words.unsaved_dont_save } else { words.unsaved_no }.as_str().to_owned()
|
||||
}
|
||||
|
||||
/// `pages` portrait pages (300 × 400) with a line of text each.
|
||||
@@ -58,8 +57,7 @@ fn fixture(pages: usize) -> Vec<u8> {
|
||||
|
||||
fn harness(names: &'static [&'static str]) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
app.run_inline = true;
|
||||
let mut app = crate::support::inline_app();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
for name in names {
|
||||
app.open_bytes(&egui::Context::default(), name, None, fixture(3)).unwrap();
|
||||
@@ -287,7 +285,7 @@ fn the_pane_last_clicked_is_the_one_menus_and_keys_act_on() {
|
||||
let at = h.state().views[left].viewport_rect().center();
|
||||
click_at(&mut h, at);
|
||||
assert_eq!(h.state().active, Some(left));
|
||||
h.state_mut().run_command("page.rotate");
|
||||
crate::support::fire_menu(&mut h, "page.rotate");
|
||||
h.run_steps(2);
|
||||
assert!(h.state().session.get(lid).unwrap().dirty);
|
||||
assert!(!h.state().session.get(rid).unwrap().dirty);
|
||||
@@ -295,7 +293,7 @@ fn the_pane_last_clicked_is_the_one_menus_and_keys_act_on() {
|
||||
let at = h.state().views[right].viewport_rect().center();
|
||||
click_at(&mut h, at);
|
||||
assert_eq!(h.state().active, Some(right));
|
||||
h.state_mut().run_command("page.rotate");
|
||||
crate::support::fire_menu(&mut h, "page.rotate");
|
||||
h.run_steps(2);
|
||||
assert!(h.state().session.get(rid).unwrap().dirty);
|
||||
// The main strip still marks the tab its pane shows, and the window title names it.
|
||||
|
||||
@@ -2,14 +2,21 @@
|
||||
//! the other pane, even when that click changes the document too.
|
||||
|
||||
use egui::{Key, Modifiers, Pos2};
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::host::{Host, InlineJobs, Picked, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
use pdfcraft_ui_egui::panes::Place;
|
||||
|
||||
fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
app.run_inline = true;
|
||||
harness_over(crate::support::host_with(Arc::new(InlineJobs), Arc::new(ScriptedFiles::new())))
|
||||
}
|
||||
|
||||
/// [`harness`] on `host`: its jobs run at once, and its file service answers the pickers.
|
||||
fn harness_over(host: Arc<Host>) -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = crate::support::test_app(host);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "form.pdf", None, include_bytes!("../data/form.pdf").to_vec()).unwrap();
|
||||
app.set_option(&egui::Context::default(), "left", "closed").unwrap();
|
||||
@@ -91,8 +98,8 @@ fn save_in_the_second_pane_keeps_its_typing() {
|
||||
let dir = std::env::temp_dir().join(format!("pdfcraft-split-save-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let out = dir.join("out.pdf");
|
||||
let mut h = harness();
|
||||
h.state_mut().save_override = Some(out.to_string_lossy().into_owned());
|
||||
let files = ScriptedFiles::answering([Picked::Paths(vec![out.clone()])]);
|
||||
let mut h = harness_over(crate::support::host_with(Arc::new(InlineJobs), Arc::new(files)));
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::Backslash);
|
||||
h.run_steps(4);
|
||||
let second = 1;
|
||||
|
||||
@@ -9,8 +9,7 @@ use pdfcraft_ui_egui::PdfCraftApp;
|
||||
|
||||
fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
app.run_inline = true;
|
||||
let mut app = crate::support::inline_app();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "form.pdf", None, include_bytes!("../data/form.pdf").to_vec()).unwrap();
|
||||
app.set_option(&egui::Context::default(), "left", "closed").unwrap();
|
||||
@@ -32,10 +31,12 @@ fn each_panes_find_input_has_its_own_id() {
|
||||
h.state_mut().views[1].open_find();
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.get_all_by_label("Find text").count(), 2, "one find field per pane");
|
||||
let mut fields = h.get_all_by_label("Find text");
|
||||
let (first, second) = (fields.next().unwrap(), fields.next().unwrap());
|
||||
assert!(second.accesskit_node().is_focused(), "the focus is in the pane that asked last");
|
||||
assert!(!first.accesskit_node().is_focused(), "the other pane's field does not share it");
|
||||
{
|
||||
let mut fields = h.get_all_by_label("Find text");
|
||||
let (first, second) = (fields.next().unwrap(), fields.next().unwrap());
|
||||
assert!(second.accesskit_node().is_focused(), "the focus is in the pane that asked last");
|
||||
assert!(!first.accesskit_node().is_focused(), "the other pane's field does not share it");
|
||||
}
|
||||
|
||||
// Typing goes to one query only.
|
||||
h.event(egui::Event::Text("abc".into()));
|
||||
|
||||
@@ -9,8 +9,7 @@ use pdfcraft_ui_egui::PdfCraftApp;
|
||||
|
||||
fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
app.run_inline = true;
|
||||
let mut app = crate::support::inline_app();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "form.pdf", None, include_bytes!("../data/form.pdf").to_vec()).unwrap();
|
||||
app
|
||||
|
||||
@@ -131,10 +131,10 @@ fn creating_placing_and_keeping_custom_stamps() {
|
||||
assert!(((r[2] - r[0]) / (r[3] - r[1]) - 3.0).abs() < 0.05, "keeps the picture's shape: {r:?}");
|
||||
assert_eq!(doc.can_undo(), Some("Add stamp"));
|
||||
// The library is kept with the app's settings.
|
||||
let saved = s.persist();
|
||||
let saved = s.settings_snapshot();
|
||||
let mut again = crate::control::new_app();
|
||||
again.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
again.restore(&saved);
|
||||
again.apply_settings(&saved);
|
||||
assert_eq!(again.custom_stamps.len(), 1);
|
||||
assert_eq!((again.custom_stamps[0].category.as_str(), again.custom_stamps[0].name.as_str()), ("Company", "logo"));
|
||||
assert_eq!(again.custom_stamps[0].data, s.custom_stamps[0].data);
|
||||
@@ -198,6 +198,6 @@ fn a_dynamic_custom_stamp_keeps_its_line_and_fills_it_in_when_placed() {
|
||||
// A band under the 3:1 picture (so less wide than 3:1), at least as wide as the picture.
|
||||
assert!(aspect > 3.0 * (1.0 - 0.22) - 0.05 && aspect < 3.0 - 0.05, "a band under the 3:1 picture: {r:?}");
|
||||
let mut again = crate::control::new_app();
|
||||
again.restore(&s.persist());
|
||||
again.apply_settings(&s.settings_snapshot());
|
||||
assert_eq!(again.custom_stamps[0].line, s.custom_stamps[0].line, "kept with the library");
|
||||
}
|
||||
|
||||
@@ -4,15 +4,19 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use egui::FontId;
|
||||
use egui::epaint::text::{Fonts, TextOptions};
|
||||
use egui_kittest::Harness;
|
||||
use craft::host::{AppInfo, Files, Host, InlineJobs, Jobs, ManualJobs, ScriptedFiles, Wake};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::platform::clipboard::{Clipboard, ClipboardBackend, ClipboardError, ClipboardImage, Flavor, TEXT};
|
||||
use craft::platform::open::FileIntake;
|
||||
use craft::platform::watch::FileWatch;
|
||||
use craft::ui::runtime::commands::{FireSource, fire};
|
||||
use craft::ui::runtime::env::WindowKey;
|
||||
use craft::ui::runtime::toast;
|
||||
use craft::host::{Host, Wake};
|
||||
use craft::keymap::CommandRef;
|
||||
use pdfcraft_ui_egui::{AppServices, FileIntake, FileWatch, PdfCraftApp, i18n};
|
||||
use egui::FontId;
|
||||
use egui::epaint::text::{Fonts, TextOptions};
|
||||
use egui_kittest::Harness;
|
||||
use pdfcraft_ui_egui::{AppServices, PdfCraftApp, RightPanel, i18n};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod fixtures;
|
||||
pub mod input;
|
||||
@@ -65,43 +69,140 @@ pub fn fire_menu(h: &mut Harness<'static, PdfCraftApp>, command: impl Into<Comma
|
||||
}
|
||||
|
||||
/// The text of the first notice card the main window shows, if any.
|
||||
pub fn shown_notice(h: &mut Harness<'static, PdfCraftApp>) -> Option<String> {
|
||||
pub fn shown_notice(h: &Harness<'_, PdfCraftApp>) -> Option<String> {
|
||||
toast::cards(&h.ctx, &WindowKey::main()).first().map(|card| card.toast.message.as_str().to_owned())
|
||||
}
|
||||
|
||||
/// An app built over `host`, with no wake, an inline file watch and a test file intake: the one way a
|
||||
/// test gives the app a host, so jobs and picked files run when the test steps.
|
||||
pub fn host_harness(host: Arc<Host>, clipboard: RecordingClipboard) -> Harness<'static, PdfCraftApp> {
|
||||
// PLAN: assumed `AppServices::new(wake, clipboard, recovery_dir, update_source, intake, watch)`,
|
||||
// `FileIntake::for_tests()`, `FileWatch::inline()` and `PdfCraftApp::with_host(Arc<Host>, AppServices)` (pdf-hub-w1, L-207)
|
||||
let services = AppServices::new(Wake::none(), Box::new(clipboard), None, None, FileIntake::for_tests(), FileWatch::inline());
|
||||
let app = PdfCraftApp::with_host(host, services);
|
||||
Harness::new_ui_state(|ui, app: &mut PdfCraftApp| app.ui(ui), app)
|
||||
/// The services the tests give the app: no wake, no autosave folder, the GitHub update source, a fresh
|
||||
/// file intake and an inline file watch, over `clipboard`.
|
||||
pub fn services(clipboard: RecordingClipboard) -> AppServices {
|
||||
let (intake, _sender) = FileIntake::new(Wake::none());
|
||||
AppServices::new(Wake::none(), Clipboard::new(clipboard), None, None, intake, FileWatch::new(Wake::none()).inline())
|
||||
}
|
||||
|
||||
/// A clipboard backend the tests share: what the app copies is read back through the clone the test keeps.
|
||||
fn app_info() -> AppInfo {
|
||||
AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" }
|
||||
}
|
||||
|
||||
/// A host whose threads run its jobs and whose pickers answer Cancelled.
|
||||
pub fn host() -> Arc<Host> {
|
||||
Arc::new(Host::builder(app_info()).build())
|
||||
}
|
||||
|
||||
/// A host over `jobs` and `files`, for a test that scripts either.
|
||||
pub fn host_with(jobs: Arc<dyn Jobs>, files: Arc<dyn Files>) -> Arc<Host> {
|
||||
Arc::new(Host::builder(app_info()).jobs(jobs).files(files).build())
|
||||
}
|
||||
|
||||
/// A host whose pickers answer from `files`.
|
||||
pub fn host_with_files(files: impl Into<Arc<ScriptedFiles>>) -> Arc<Host> {
|
||||
let files: Arc<ScriptedFiles> = files.into();
|
||||
Arc::new(Host::builder(app_info()).files(files).build())
|
||||
}
|
||||
|
||||
/// The app over `host` with the tests' services.
|
||||
pub fn test_app(host: Arc<Host>) -> PdfCraftApp {
|
||||
PdfCraftApp::with_host(host, services(RecordingClipboard::default()))
|
||||
}
|
||||
|
||||
/// The app over a host whose jobs wait in `jobs` until the test runs them.
|
||||
pub fn held_app(jobs: Arc<ManualJobs>) -> PdfCraftApp {
|
||||
test_app(Arc::new(Host::builder(app_info()).jobs(jobs).build()))
|
||||
}
|
||||
|
||||
/// The app over a host whose jobs run at once, where they are queued.
|
||||
pub fn inline_app() -> PdfCraftApp {
|
||||
test_app(Arc::new(Host::builder(app_info()).jobs(Arc::new(InlineJobs)).build()))
|
||||
}
|
||||
|
||||
/// The app over the default host and a clipboard the test keeps a clone of.
|
||||
pub fn app_with_clipboard(clipboard: RecordingClipboard) -> PdfCraftApp {
|
||||
PdfCraftApp::with_host(host(), services(clipboard))
|
||||
}
|
||||
|
||||
/// An app built over `host`, with the tests' services: the one way a test gives the app a host, so
|
||||
/// jobs and picked files run when the test steps.
|
||||
pub fn host_harness(host: Arc<Host>, clipboard: RecordingClipboard) -> Harness<'static, PdfCraftApp> {
|
||||
let app = PdfCraftApp::with_host(host, services(clipboard));
|
||||
Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| app)
|
||||
}
|
||||
|
||||
/// A clipboard backend the tests share: what the app writes is read back through the clone the test keeps.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct RecordingClipboard {
|
||||
text: Arc<Mutex<Option<String>>>,
|
||||
state: Arc<Mutex<Recorded>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Recorded {
|
||||
writes: Vec<Vec<Flavor>>,
|
||||
held: Option<String>,
|
||||
refused: Option<&'static str>,
|
||||
refuse_all: bool,
|
||||
}
|
||||
|
||||
impl RecordingClipboard {
|
||||
/// A clipboard that refuses a write offering a flavour of `mime`; the attempt is recorded.
|
||||
pub fn refusing(mime: &'static str) -> Self {
|
||||
let clipboard = Self::default();
|
||||
clipboard.lock().refused = Some(mime);
|
||||
clipboard
|
||||
}
|
||||
|
||||
/// A clipboard with no system behind it: every write is refused (and recorded).
|
||||
pub fn refusing_all() -> Self {
|
||||
let clipboard = Self::default();
|
||||
clipboard.lock().refuse_all = true;
|
||||
clipboard
|
||||
}
|
||||
|
||||
/// The text the app last copied.
|
||||
pub fn copied(&self) -> Option<String> {
|
||||
self.text.lock().ok().and_then(|text| text.clone())
|
||||
self.lock().held.clone()
|
||||
}
|
||||
|
||||
/// Every write the app attempted, refused or not, each as its flavours.
|
||||
pub fn writes(&self) -> Vec<Vec<Flavor>> {
|
||||
self.lock().writes.clone()
|
||||
}
|
||||
|
||||
fn lock(&self) -> std::sync::MutexGuard<'_, Recorded> {
|
||||
self.state.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
}
|
||||
}
|
||||
|
||||
// PLAN: assumed `ClipboardBackend` with `get_text` and `set_text` (craft::platform::clipboard)
|
||||
impl craft::platform::clipboard::ClipboardBackend for RecordingClipboard {
|
||||
fn get_text(&self) -> Option<String> {
|
||||
self.copied()
|
||||
impl ClipboardBackend for RecordingClipboard {
|
||||
fn write(&mut self, flavors: &[Flavor]) -> Result<usize, ClipboardError> {
|
||||
let mut state = self.lock();
|
||||
state.writes.push(flavors.to_vec());
|
||||
if state.refuse_all {
|
||||
return Err(ClipboardError::Unavailable);
|
||||
}
|
||||
if let Some(mime) = state.refused
|
||||
&& flavors.iter().any(|f| f.mime == mime)
|
||||
{
|
||||
return Err(ClipboardError::NoFormat);
|
||||
}
|
||||
let written = flavors.iter().position(|f| f.mime == TEXT).unwrap_or(0);
|
||||
state.held = flavors.get(written).filter(|f| f.mime == TEXT).map(|f| String::from_utf8_lossy(&f.data).into_owned());
|
||||
Ok(written)
|
||||
}
|
||||
|
||||
fn set_text(&self, text: &str) {
|
||||
if let Ok(mut held) = self.text.lock() {
|
||||
*held = Some(text.to_owned());
|
||||
}
|
||||
fn read(&mut self, mimes: &[&str], _limit: u64) -> Result<Option<Flavor>, ClipboardError> {
|
||||
let held = self.lock().held.clone();
|
||||
Ok(held.filter(|_| mimes.contains(&TEXT)).map(|text| Flavor::text(&text)))
|
||||
}
|
||||
|
||||
fn read_image(&mut self, _limit: u64) -> Result<Option<ClipboardImage>, ClipboardError> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn read_files(&mut self, _limit: usize) -> Result<Option<Vec<PathBuf>>, ClipboardError> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn has(&mut self, mimes: &[&str]) -> bool {
|
||||
mimes.contains(&TEXT) && self.lock().held.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,8 +261,8 @@ pub fn skip_without_glyphs(name: &str, language: &str, text: &str) -> bool {
|
||||
let catalogs: Vec<&str> = i18n::Lang::from_code(language).into_iter().flat_map(i18n::Lang::catalog_texts).collect();
|
||||
let translations = catalogs.iter().flat_map(|c| c.lines()).filter(|l| !l.starts_with('#')).filter_map(|l| l.split('\t').nth(2));
|
||||
let chars: BTreeSet<char> = std::iter::once(text).chain(translations).flat_map(str::chars).filter(|c| !c.is_control()).collect();
|
||||
// PLAN: assumed `fonts::ui_fonts(language)` (pdf-shell-w10); `fonts` must be `pub mod` for tests.
|
||||
let defs: egui::FontDefinitions = pdfcraft_ui_egui::fonts::ui_fonts(language).stack().flat_definitions();
|
||||
let defs: egui::FontDefinitions =
|
||||
pdfcraft_ui_egui::fonts::ui_fonts(i18n::Lang::from_code(language).unwrap_or(i18n::Lang::EN)).stack().flat_definitions();
|
||||
let families: Vec<FontId> = defs.families.keys().map(|f| FontId::new(13.0, f.clone())).collect();
|
||||
let mut fonts = Fonts::new(TextOptions::default(), defs);
|
||||
let missing = chars.iter().copied().find(|c| families.iter().any(|id| !fonts.has_glyphs(id, &c.to_string())));
|
||||
@@ -188,7 +289,22 @@ pub fn open_shortcuts_from_the_help_menu(h: &mut Harness<'static, PdfCraftApp>)
|
||||
open_menu(h, "Help");
|
||||
h.get_by(|n| n.role() == egui::accesskit::Role::MenuItem && n.label().is_some_and(|l| l.starts_with("Keyboard shortcuts"))).click();
|
||||
h.run_steps(4);
|
||||
assert!(h.state().dialog.is_some(), "Keyboard shortcuts is open");
|
||||
assert!(dialog_open(h), "Keyboard shortcuts is open");
|
||||
}
|
||||
|
||||
/// The right panel the dock has open, as the control channel's `ui.state` reports it (`side_panels::state`).
|
||||
pub fn right(app: &PdfCraftApp) -> Option<RightPanel> {
|
||||
use RightPanel::*;
|
||||
let state = pdfcraft_ui_egui::side_panels::state(app);
|
||||
let name = state["side_panel"].as_str()?;
|
||||
[Comments, Bookmarks, Pages, Fields, Layers, Attachments, Signatures, Accessibility, Tags, Search, Compare]
|
||||
.into_iter()
|
||||
.find(|panel| format!("{panel:?}") == name)
|
||||
}
|
||||
|
||||
/// Whether the dialog host holds a dialog.
|
||||
pub fn dialog_open(h: &Harness<'_, PdfCraftApp>) -> bool {
|
||||
!h.state().dialogs.is_empty()
|
||||
}
|
||||
|
||||
/// The app's command and option entry points, called with the harness's own context (L-208: they take the
|
||||
@@ -196,6 +312,13 @@ pub fn open_shortcuts_from_the_help_menu(h: &mut Harness<'static, PdfCraftApp>)
|
||||
pub trait AppHarness {
|
||||
fn execute(&mut self, id: &str) -> bool;
|
||||
fn set_option(&mut self, key: &str, value: &str) -> Result<(), String>;
|
||||
fn undo(&mut self);
|
||||
fn redo(&mut self);
|
||||
fn run_command(&mut self, id: &str);
|
||||
fn submit_password(&mut self, password: Option<String>);
|
||||
fn run_button_script(&mut self, id: pdfcraft_engine::DocId, field: &str, script: &str);
|
||||
fn snapshot(&mut self, index: usize, page: usize, view_rect: [f32; 4]) -> Result<(u32, u32), String>;
|
||||
fn start_signing(&mut self, page: usize, rect: Option<[f64; 4]>, field: Option<String>, certify: Option<u8>);
|
||||
}
|
||||
|
||||
impl AppHarness for Harness<'_, PdfCraftApp> {
|
||||
@@ -208,4 +331,39 @@ impl AppHarness for Harness<'_, PdfCraftApp> {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().set_option(&ctx, key, value)
|
||||
}
|
||||
|
||||
fn undo(&mut self) {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().undo(&ctx);
|
||||
}
|
||||
|
||||
fn redo(&mut self) {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().redo(&ctx);
|
||||
}
|
||||
|
||||
fn run_command(&mut self, id: &str) {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().run_command(&ctx, id);
|
||||
}
|
||||
|
||||
fn submit_password(&mut self, password: Option<String>) {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().submit_password(&ctx, password);
|
||||
}
|
||||
|
||||
fn run_button_script(&mut self, id: pdfcraft_engine::DocId, field: &str, script: &str) {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().run_button_script(&ctx, id, field, script);
|
||||
}
|
||||
|
||||
fn snapshot(&mut self, index: usize, page: usize, view_rect: [f32; 4]) -> Result<(u32, u32), String> {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().snapshot(&ctx, index, page, view_rect)
|
||||
}
|
||||
|
||||
fn start_signing(&mut self, page: usize, rect: Option<[f64; 4]>, field: Option<String>, certify: Option<u8>) {
|
||||
let ctx = self.ctx.clone();
|
||||
self.state_mut().start_signing(&ctx, page, rect, field, certify);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ fn selected_text_copy_floating_button_honours_permissions() {
|
||||
let mut app = app_on(RecordingClipboard::default());
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "no-copy.pdf", None, bytes).unwrap();
|
||||
app.submit_password(Some(password.into()));
|
||||
app.submit_password(&egui::Context::default(), Some(password.into()));
|
||||
app.set_option(&egui::Context::default(), "left", "closed").unwrap();
|
||||
app
|
||||
});
|
||||
@@ -342,7 +342,7 @@ fn selected_text_copy_with_formatting_honours_permissions() {
|
||||
.unwrap();
|
||||
let bytes = pdfcraft_cos::write_full(&doc, &Default::default()).unwrap();
|
||||
let clipboard = RecordingClipboard::default();
|
||||
let (mut h, at) = harness_clip(bytes, clipboard.clone(), |app| app.submit_password(Some("pw".into())));
|
||||
let (mut h, at) = harness_clip(bytes, clipboard.clone(), |app| app.submit_password(&egui::Context::default(), Some("pw".into())));
|
||||
click(&mut h, at);
|
||||
click(&mut h, at);
|
||||
assert_eq!(h.state().views[0].selected_text().as_deref(), Some("quick"));
|
||||
@@ -534,7 +534,7 @@ fn a_selection_across_pages_is_marked_on_every_page_in_one_step() {
|
||||
assert_eq!(marks(&h), [(0, "Underline".to_string()), (1, "Underline".to_string())]);
|
||||
assert!(h.state().views[0].selected_text().is_none(), "the selection is consumed");
|
||||
assert!(h.state().views[0].session.comments.primary().is_some_and(|(page, _)| page == 1), "its last part is selected, as one markup is");
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.run_steps(3);
|
||||
assert_eq!(marks(&h), [], "one undo removes both");
|
||||
}
|
||||
@@ -557,7 +557,7 @@ fn full_screen_link_click_cancels_the_pending_page_turn() {
|
||||
)
|
||||
.into_bytes();
|
||||
let (mut h, _) = harness_with(four_pages, |_| {});
|
||||
h.state_mut().apply_full_screen(true);
|
||||
h.state_mut().set_full_screen(true);
|
||||
crate::support::wait_until(&mut h, "the page in full screen", |app| app.views[0].glyph_screen_pos(0, 5).is_some() && !app.render_pending());
|
||||
let r = h.state().views[0].page_screen_rect(0).expect("page 1 on screen");
|
||||
let at = |x: f32, y: f32| egui::pos2(r.left() + x / 300.0 * r.width(), r.top() + (200.0 - y) / 200.0 * r.height());
|
||||
@@ -589,7 +589,7 @@ fn full_screen_double_click_selects_a_word_and_stays_on_the_page() {
|
||||
)
|
||||
.into_bytes();
|
||||
let (mut h, _) = harness_with(two_pages, |_| {});
|
||||
h.state_mut().apply_full_screen(true);
|
||||
h.state_mut().set_full_screen(true);
|
||||
crate::support::wait_until(&mut h, "the page in full screen", |app| app.views[0].glyph_screen_pos(0, 5).is_some() && !app.render_pending());
|
||||
let at = h.state().views[0].glyph_screen_pos(0, 5).expect("text layer");
|
||||
h.hover_at(at);
|
||||
@@ -604,8 +604,8 @@ fn full_screen_double_click_selects_a_word_and_stays_on_the_page() {
|
||||
|
||||
// A single click turns it once the double-click time is over.
|
||||
// Entering full screen again clears the selection.
|
||||
h.state_mut().apply_full_screen(false);
|
||||
h.state_mut().apply_full_screen(true);
|
||||
h.state_mut().set_full_screen(false);
|
||||
h.state_mut().set_full_screen(true);
|
||||
h.run_steps(30);
|
||||
click(&mut h, at);
|
||||
h.run_steps(30);
|
||||
@@ -615,7 +615,7 @@ fn full_screen_double_click_selects_a_word_and_stays_on_the_page() {
|
||||
h.state_mut().views[0].go_to_page(0);
|
||||
h.run_steps(30);
|
||||
click(&mut h, at);
|
||||
h.state_mut().apply_full_screen(false);
|
||||
h.state_mut().set_full_screen(false);
|
||||
h.run_steps(30);
|
||||
assert_eq!(h.state().views[0].current(), 0, "no page turn after leaving");
|
||||
}
|
||||
@@ -675,7 +675,7 @@ fn markup_tools_mark_a_selection_across_pages_on_every_page() {
|
||||
drag(&mut h, from, to);
|
||||
h.run_steps(3);
|
||||
assert_eq!(marks(&h), both(kind), "{command}: dragged with the tool");
|
||||
h.state_mut().undo();
|
||||
h.undo();
|
||||
h.run_steps(3);
|
||||
assert_eq!(marks(&h), [], "{command}: one undo step");
|
||||
// Selecting first, then picking the tool.
|
||||
|
||||
@@ -21,7 +21,7 @@ fn harness_with(settings: Option<&'static str>, system: Option<egui::Theme>, run
|
||||
if let Some(json) = settings {
|
||||
app.apply_settings(&import_json(json).0);
|
||||
}
|
||||
app.attach_control(rx, None);
|
||||
app.attach_control(craft::automation::ControlChannel::new(rx), None);
|
||||
app
|
||||
});
|
||||
h.input_mut().system_theme = system;
|
||||
@@ -180,12 +180,9 @@ fn commands_and_options_apply_before_the_first_frame() {
|
||||
#[test]
|
||||
fn restored_system_tracks_native_input_without_rewriting_saved_preference() {
|
||||
let (mut h, c) = harness_with(Some(r#"{"theme":"system"}"#), None, true);
|
||||
for (input, expected) in [
|
||||
(Some(egui::Theme::Dark), "Dark"),
|
||||
(Some(egui::Theme::Light), "Light"),
|
||||
(None, "Light"),
|
||||
(Some(egui::Theme::Dark), "Dark"),
|
||||
] {
|
||||
for (input, expected) in
|
||||
[(Some(egui::Theme::Dark), "Dark"), (Some(egui::Theme::Light), "Light"), (None, "Light"), (Some(egui::Theme::Dark), "Dark")]
|
||||
{
|
||||
h.input_mut().system_theme = input;
|
||||
h.run_steps(3);
|
||||
assert_theme(&mut h, &c, "System", expected);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
//! self-signed root) differs from its `certificate` (the signer); the click must trust the signer.
|
||||
|
||||
use crate::support;
|
||||
use crate::support::AppHarness as _;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_engine::SignatureStatus;
|
||||
@@ -30,13 +31,14 @@ fn dir() -> std::path::PathBuf {
|
||||
}
|
||||
|
||||
fn harness(dir: std::path::PathBuf) -> Harness<'static, PdfCraftApp> {
|
||||
// The signed copy is saved where the pick answers: the test's own folder.
|
||||
let files =
|
||||
std::sync::Arc::new(craft::host::ScriptedFiles::answering((0..4).map(|_| craft::host::Picked::Paths(vec![dir.join("contract_signed.pdf")]))));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = crate::control::new_app();
|
||||
let mut app = crate::control::app_with_files(files);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "contract.pdf", None, FIXTURE.to_vec()).expect("opens");
|
||||
app.set_option(&egui::Context::default(), "left", "closed").unwrap();
|
||||
app.export_dir_override = Some(dir.to_string_lossy().into_owned());
|
||||
app.save_override = Some(dir.join("contract_signed.pdf").to_string_lossy().into_owned());
|
||||
app
|
||||
});
|
||||
h.run_steps(6);
|
||||
@@ -51,7 +53,7 @@ fn one_click_trust_stores_the_displayed_signer_not_the_embedded_root() {
|
||||
let p12 = concat!(env!("CARGO_MANIFEST_DIR"), "/../sign/tests/data/chain.p12");
|
||||
let id = pdfcraft_engine::sign::pkcs12::open(&std::fs::read(p12).unwrap(), "test").unwrap();
|
||||
let entry = h.state_mut().add_digital_id(p12, &id.certificate);
|
||||
h.state_mut().start_signing(0, None, None, None);
|
||||
h.start_signing(0, None, None, None);
|
||||
{
|
||||
let d = h.state_mut().sign_draft.as_mut().unwrap();
|
||||
d.selected = Some(entry);
|
||||
|
||||
@@ -109,7 +109,8 @@ fn a_reloaded_document_keeps_its_interface() {
|
||||
let mut h = harness(|_| {}, &["/ViewerPreferences << /HideToolbar true >>"]);
|
||||
let reload = |h: &mut Harness<'static, PdfCraftApp>| {
|
||||
let info = h.state().session.get(h.state().views[0].id).unwrap().info.clone();
|
||||
h.state_mut().views[0].document_replaced(&info);
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().views[0].document_replaced(&ctx, &info);
|
||||
h.run_steps(3);
|
||||
};
|
||||
reload(&mut h);
|
||||
|
||||
@@ -239,7 +239,7 @@ fn messages_from_scripts_run_on_open_show_right_away() {
|
||||
let mut h = open(pdfcraft_xfa::fixtures::shell(&tpl));
|
||||
h.run_steps(2);
|
||||
assert!(h.query_by_label_contains("Welcome to the form").is_some(), "script console: {:?}", h.state().js_console.log);
|
||||
assert_eq!(h.state().dialog, None, "an initialize script can't open the Print dialog");
|
||||
assert!(!crate::support::dialog_open(&h), "an initialize script can't open the Print dialog");
|
||||
let id = h.state().views[0].id;
|
||||
assert!(h.state_mut().session.take_js_output(id).is_empty(), "nothing waits for the next edit");
|
||||
}
|
||||
@@ -362,7 +362,7 @@ fn opening_another_document_keeps_the_highlight_the_one_in_front_reads() {
|
||||
let mut h = open(pdfcraft_xfa::fixtures::shell(&xdp));
|
||||
let app = h.state_mut();
|
||||
// The document in front has Highlight fields on; the remembered setting is off.
|
||||
app.view_defaults.highlight_fields = false;
|
||||
app.apply_settings(&pdfcraft_ui_egui::settings::import_json(r#"{"highlight_fields": false}"#).0);
|
||||
app.views[0].session.highlight_fields = true;
|
||||
h.run_steps(2);
|
||||
let app = h.state_mut();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
use pdfcraft_ui_egui::settings::{PdfCraftSettings, import_json};
|
||||
|
||||
/// Whether some pixel of the viewport outside every page rectangle differs between the two frames:
|
||||
/// the shadow band round the pages.
|
||||
@@ -66,16 +67,15 @@ fn checkbox_and_multiple_documents_do_not_edit_pdf_state() {
|
||||
.collect();
|
||||
h.set_option("dialog", "preferences").unwrap();
|
||||
h.run_steps(3);
|
||||
// PLAN: assumed `PdfCraftSettings::show_page_edge_shadows` (pdf-shell-w9's typed settings)
|
||||
assert!(h.state().settings_snapshot().show_page_edge_shadows);
|
||||
assert_eq!(h.state().settings_snapshot().behavior.show_page_edge_shadows, Some(true));
|
||||
let checkbox = h.get_by_label("Show Page Edge Shadows");
|
||||
checkbox.click();
|
||||
h.run_steps(2);
|
||||
assert!(!h.state().settings_snapshot().show_page_edge_shadows, "a click turns it off");
|
||||
assert_eq!(h.state().settings_snapshot().behavior.show_page_edge_shadows, Some(false), "a click turns it off");
|
||||
h.get_by_label("Show Page Edge Shadows").focus();
|
||||
h.key_press(egui::Key::Space);
|
||||
h.run_steps(2);
|
||||
assert!(h.state().settings_snapshot().show_page_edge_shadows, "Space turns it on");
|
||||
assert_eq!(h.state().settings_snapshot().behavior.show_page_edge_shadows, Some(true), "Space turns it on");
|
||||
h.set_option("show_page_edge_shadows", "false").unwrap();
|
||||
h.run_steps(2);
|
||||
h.set_option("dialog", "none").unwrap();
|
||||
@@ -149,7 +149,7 @@ fn harness(theme: &str) -> Harness<'static, PdfCraftApp> {
|
||||
app.session = app.session.with_clock(|| 1_700_000_000);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.set_option(&egui::Context::default(), "theme", &theme).unwrap();
|
||||
app.open_bytes("pages.pdf", None, pdf()).unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "pages.pdf", None, pdf()).unwrap();
|
||||
app.set_option(&egui::Context::default(), "zoom", "100").unwrap();
|
||||
app
|
||||
});
|
||||
@@ -190,24 +190,25 @@ fn pdf() -> Vec<u8> {
|
||||
#[test]
|
||||
fn page_shadow_preference_round_trips_and_ignores_invalid_settings() {
|
||||
let mut app = new_app();
|
||||
let enabled = |app: &PdfCraftApp| serde_json::from_str::<serde_json::Value>(&app.persist()).unwrap()["show_page_edge_shadows"].clone();
|
||||
assert_eq!(enabled(&app), true);
|
||||
app.restore("{}");
|
||||
assert_eq!(enabled(&app), true);
|
||||
let enabled = |app: &PdfCraftApp| app.settings_snapshot().behavior.show_page_edge_shadows;
|
||||
let restore_json = |app: &mut PdfCraftApp, json: &str| app.apply_settings(&import_json(json).0);
|
||||
assert_eq!(enabled(&app), Some(true));
|
||||
app.apply_settings(&PdfCraftSettings::default());
|
||||
assert_eq!(enabled(&app), Some(true));
|
||||
for value in [false, true] {
|
||||
app.set_option(&egui::Context::default(), "show_page_edge_shadows", if value { "true" } else { "false" }).unwrap();
|
||||
let mut restored = new_app();
|
||||
restored.restore(&app.persist());
|
||||
assert_eq!(enabled(&restored), value);
|
||||
restored.apply_settings(&app.settings_snapshot());
|
||||
assert_eq!(enabled(&restored), Some(value));
|
||||
}
|
||||
for invalid in ["null", "0", "\"false\"", "[]", "{}"] {
|
||||
app.restore(&format!("{{\"show_page_edge_shadows\":{invalid}}}"));
|
||||
assert_eq!(enabled(&app), true);
|
||||
restore_json(&mut app, &format!("{{\"show_page_edge_shadows\":{invalid}}}"));
|
||||
assert_eq!(enabled(&app), Some(true));
|
||||
}
|
||||
app.restore("not json");
|
||||
assert_eq!(enabled(&app), true);
|
||||
restore_json(&mut app, "not json");
|
||||
assert_eq!(enabled(&app), Some(true));
|
||||
assert!(app.set_option(&egui::Context::default(), "show_page_edge_shadows", "maybe").is_err());
|
||||
assert_eq!(enabled(&app), true);
|
||||
assert_eq!(enabled(&app), Some(true));
|
||||
}
|
||||
|
||||
/// An app on the default host with test services: no wake-ups, no autosave folder, the GitHub update
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//! script on a small and a large document, from the component runs the framework counts, so a slow or busy machine
|
||||
//! cannot fail it and a regression cannot hide behind a fast one. Rendering runs on worker threads and is not counted.
|
||||
|
||||
use craft::pages::ui::view::GoTo;
|
||||
use craft::ui::testing::last_pass_runs;
|
||||
use egui_kittest::Harness;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
@@ -64,7 +65,7 @@ fn harness(bytes: Vec<u8>, options: &'static [(&'static str, &'static str)]) ->
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_eframe(move |_cc| {
|
||||
let mut app = new_app();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes("work.pdf", None, bytes).expect("opens");
|
||||
app.open_bytes(&egui::Context::default(), "work.pdf", None, bytes).expect("opens");
|
||||
for (key, value) in options {
|
||||
app.set_option(&egui::Context::default(), key, value).unwrap();
|
||||
}
|
||||
@@ -138,7 +139,7 @@ fn a_folded_page_builds_no_comment_cards_and_an_open_one_builds_only_the_rows_in
|
||||
fn jumping_through_pages_builds_only_the_pages_in_view() {
|
||||
let work = |n: usize| {
|
||||
let mut h = harness(big(n), &[]);
|
||||
most_work(&mut h, None, 60, |h, f| h.state_mut().views[0].goto = Some(((f * 5) / 2 % 50, 0.3)))
|
||||
most_work(&mut h, None, 60, |h, f| h.state_mut().views[0].view.go_to = Some(GoTo::Top { page: (f * 5) / 2 % 50, fraction: 0.3 }))
|
||||
};
|
||||
let (small, large) = (work(50), work(500));
|
||||
assert!(small.0 > 0, "the frames build something");
|
||||
@@ -182,7 +183,7 @@ fn panels_build_only_the_rows_in_view() {
|
||||
for (panel, row, builds) in [("comments", "CommentRow", true), ("pages", "Tile", true), ("fields", "ListRow", false)] {
|
||||
let work = |n: usize| {
|
||||
let mut h = harness(big(n), &[("panel", panel)]);
|
||||
most_work(&mut h, Some(row), 60, |h, f| h.state_mut().views[0].goto = Some(((f * 5) % 50, 0.3))).0
|
||||
most_work(&mut h, Some(row), 60, |h, f| h.state_mut().views[0].view.go_to = Some(GoTo::Top { page: (f * 5) % 50, fraction: 0.3 })).0
|
||||
};
|
||||
let (small, large) = (work(50), work(500));
|
||||
if builds {
|
||||
|
||||
@@ -340,7 +340,7 @@ fn open_letter(name: &str, content: &str, desk: &Desk) -> Harness<'static, PdfCr
|
||||
let mut h = Harness::builder().with_size(egui::vec2(desk.width, desk.height)).build_eframe(move |_cc| {
|
||||
let mut app = new_app();
|
||||
let _ = app.set_option(&egui::Context::default(), "language", "en");
|
||||
let _ = app.open_bytes(&title, None, bytes);
|
||||
let _ = app.open_bytes(&egui::Context::default(), &title, None, bytes);
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
|
||||
Reference in New Issue
Block a user