mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 02:37:17 +00:00
Port tests follow L-304: production's save prompt wording and buttons, marks preview pager reachable (Don't save label, pager sized with the dialog)
This commit is contained in:
@@ -918,7 +918,7 @@ impl PdfCraftApp {
|
||||
let heading = title(kind, replace);
|
||||
// Passed inline: a closure made apart from the call gets one lifetime for its argument and result.
|
||||
// PLAN: assumed `self.dialogs: DialogHost`, `self.host`/`self.wake` (pdf-hub-w1 note 11)
|
||||
let dialog = HostedParamDialog::new(ctx, dialog_key(kind), fields, move |fields: &mut DialogFields| {
|
||||
let mut dialog = HostedParamDialog::new(ctx, dialog_key(kind), fields, move |fields: &mut DialogFields| {
|
||||
let mut draft = base.clone();
|
||||
read_fields(&mut draft, fields, kind, &units);
|
||||
let has_file = fields.text("file.path").is_some_and(|p| !p.is_empty());
|
||||
@@ -953,6 +953,8 @@ impl PdfCraftApp {
|
||||
}
|
||||
dialog
|
||||
});
|
||||
// The pager row is there from the first pass, so the dialog is sized with its row.
|
||||
dialog.set_preview_pager(Some(PanePager { shown: current + 1, count, shown_label: None, back: false, next: false, unit: PagerUnit::Page }));
|
||||
self.dialogs.open(dialog);
|
||||
self.marks_preview = Some(MarksPreview::new(kind, self.host.jobs_shared().clone(), self.wake.clone()));
|
||||
}
|
||||
|
||||
@@ -277,6 +277,7 @@ impl PdfCraftApp {
|
||||
.title(crate::i18n::fmt(template, &[("name", &shown)]))
|
||||
.message(tl!("Your changes will be lost if you don't save them."))
|
||||
.icon(craft::behavior::IconId::new("save"))
|
||||
.dont_save_label(tl!("Don't save"))
|
||||
};
|
||||
self.close_guard_dialog = Some(self.dialogs.open(dialog));
|
||||
}
|
||||
|
||||
@@ -126,9 +126,9 @@ mod tests {
|
||||
use craft::i18n::WordSet as _;
|
||||
let dialog = craft::ui::dialog::DialogWords::english();
|
||||
let common = craft::ui::runtime::words::CommonWords::english();
|
||||
// The app words the question as a document app does on every platform (document_wording).
|
||||
let dont_save = dialog.unsaved_dont_save;
|
||||
(dont_save.as_str().to_string(), common.cancel.as_str().to_string())
|
||||
// The app words the question as production does on every platform: "Don't save", in lower case.
|
||||
let _ = dialog;
|
||||
("Don't save".to_string(), common.cancel.as_str().to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -50,14 +50,14 @@ fn scripted_app() -> PdfCraftApp {
|
||||
crate::control::app_with_files(FILES.with(std::sync::Arc::clone))
|
||||
}
|
||||
|
||||
/// The unsaved-changes question's Save answer in the platform's words (the framework dialog asks Yes and No off macOS).
|
||||
/// The unsaved-changes question's Save answer in the platform's words (production's wording, on every platform).
|
||||
fn save_answer() -> &'static str {
|
||||
if cfg!(target_os = "macos") { "Save" } else { "Yes" }
|
||||
"Save"
|
||||
}
|
||||
|
||||
/// The unsaved-changes question's Don't Save answer in the platform's words.
|
||||
fn dont_save() -> &'static str {
|
||||
if cfg!(target_os = "macos") { "Don't Save" } else { "No" }
|
||||
"Don't save"
|
||||
}
|
||||
|
||||
/// The next Save's picker answers `path`.
|
||||
@@ -544,7 +544,7 @@ fn closing_a_dirty_tab_asks_and_cancel_keeps_it() {
|
||||
h.run_steps(3);
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::W);
|
||||
h.run_steps(3);
|
||||
h.get_by_label_contains("save the changes you made to “doc.pdf”");
|
||||
assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some());
|
||||
h.get_by_label("Cancel").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().views.len(), 1, "cancel keeps the document open");
|
||||
@@ -568,7 +568,7 @@ fn closing_a_dirty_tab_can_save_first() {
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().request_close_tab(&ctx_h, 0);
|
||||
h.run_steps(2);
|
||||
h.get_by_label(save_answer()).click();
|
||||
h.query_all_by_label(save_answer()).last().expect("the prompt's Save button").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().views.is_empty());
|
||||
let saved = pdfcraft_render::inspect(std::sync::Arc::new(saved_file(&out)), None).unwrap();
|
||||
@@ -578,15 +578,15 @@ fn closing_a_dirty_tab_can_save_first() {
|
||||
|
||||
#[test]
|
||||
fn the_save_prompt_answers_to_the_keyboard() {
|
||||
// Issue #8: Enter saves; ⌘D / Ctrl+D and, off macOS, Alt+N (the button's letter) don't save;
|
||||
// Issue #8: Enter saves; ⌘D / Ctrl+D and Alt+D (the Don't save button's letter) don't save;
|
||||
// Escape cancels. While the prompt is open, ⌘D is not Document properties.
|
||||
for (m, key) in [(Modifiers::COMMAND, Key::D), (Modifiers::ALT, Key::N)] {
|
||||
for (m, key) in [(Modifiers::COMMAND, Key::D), (Modifiers::ALT, Key::D)] {
|
||||
let mut h = organize(2);
|
||||
h.get_by_label("Rotate clockwise").click();
|
||||
h.run_steps(3);
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::W);
|
||||
h.run_steps(3);
|
||||
h.get_by_label_contains("save the changes you made to “doc.pdf”");
|
||||
assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some());
|
||||
h.key_press_modifiers(m, key);
|
||||
h.run_steps(3);
|
||||
assert!(h.state().views.is_empty(), "{m:?}+{key:?} doesn't save and closes");
|
||||
@@ -621,7 +621,7 @@ fn dirty_prompt() -> Harness<'static, PdfCraftApp> {
|
||||
h.run_steps(3);
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::W);
|
||||
h.run_steps(3);
|
||||
h.get_by_label_contains("save the changes you made to “doc.pdf”");
|
||||
assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some());
|
||||
h
|
||||
}
|
||||
|
||||
@@ -703,7 +703,7 @@ fn keys_leave_the_document_under_a_dialog_alone() {
|
||||
assert_eq!(h.state().views[0].target_pages(), [1], "Escape went to the dialog, not the page selection");
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::W);
|
||||
h.run_steps(3);
|
||||
h.get_by_label_contains("save the changes you made to “doc.pdf”"); // with the dialog closed, ⌘W asks to close the file again
|
||||
assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some()); // with the dialog closed, ⌘W asks to close the file again
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -729,10 +729,10 @@ fn quitting_with_unsaved_changes_asks_for_each_document() {
|
||||
}
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::Q);
|
||||
h.run_steps(3);
|
||||
h.get_by_label_contains("save the changes you made to “doc.pdf”");
|
||||
assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some());
|
||||
h.get_by_label(dont_save()).click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label_contains("save the changes you made to “second.pdf”");
|
||||
assert!(h.query_all_by_label_contains("Save changes to “second.pdf”").next().is_some());
|
||||
h.get_by_label(dont_save()).click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().views.is_empty());
|
||||
@@ -997,11 +997,11 @@ fn save_prompt_stays_inside_the_screen_for_a_long_filename() {
|
||||
h.run_steps(4);
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1365.0, 719.0));
|
||||
let inside = |r: egui::Rect| screen.contains(r.min) && screen.contains(r.max);
|
||||
let title = h.get_by_label_contains("save the changes you made to");
|
||||
let title = h.query_all_by_label_contains("Save changes to").last().expect("the prompt's title");
|
||||
let title_rect = title.rect();
|
||||
assert!(inside(title_rect), "the title rect {title_rect:?} leaves the screen");
|
||||
for button in [save_answer(), "Cancel", dont_save()] {
|
||||
let rect = h.get_by_label(button).rect();
|
||||
let rect = h.query_all_by_label(button).last().unwrap_or_else(|| panic!("no {button} button")).rect();
|
||||
assert!(inside(rect), "the {button} button rect {rect:?} leaves the screen");
|
||||
}
|
||||
}
|
||||
@@ -1039,16 +1039,16 @@ fn save_prompt_fits_the_smallest_window_whatever_the_name() {
|
||||
h.run_steps(4);
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, size);
|
||||
let inside = |r: egui::Rect| screen.contains(r.min) && screen.contains(r.max);
|
||||
let title = h.get_by_label_contains("save the changes you made to");
|
||||
let title = h.query_all_by_label_contains("Save changes to").last().expect("the prompt's title");
|
||||
let title_rect = title.rect();
|
||||
assert!(inside(title_rect), "{start}…: the title rect {title_rect:?} leaves the screen");
|
||||
let opening = format!("Do you want to save the changes you made to “{start}");
|
||||
let opening = format!("Save changes to “{start}");
|
||||
assert!(
|
||||
h.query_by(|n| n.value().is_some_and(|l| l.starts_with(&opening) && l.contains('…') && l.contains(".pdf” before closing?"))).is_some(),
|
||||
h.query_all_by(|n| n.label().or(n.value()).is_some_and(|l| l.starts_with(&opening) && l.contains('…') && l.contains(".pdf” before closing?"))).next().is_some(),
|
||||
"{start}…: the title keeps the start and the extension"
|
||||
);
|
||||
for button in [save_answer(), "Cancel", dont_save()] {
|
||||
let rect = h.get_by_label(button).rect();
|
||||
let rect = h.query_all_by_label(button).last().unwrap_or_else(|| panic!("no {button} button")).rect();
|
||||
assert!(inside(rect), "{start}…: the {button} button rect {rect:?} leaves the screen");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,12 +67,12 @@ fn card_count(h: &Harness<'static, PdfCraftApp>) -> usize {
|
||||
|
||||
/// Whether the "Save changes?" prompt is on screen.
|
||||
fn asks_to_save(h: &Harness<'static, PdfCraftApp>) -> bool {
|
||||
h.query_by_role_and_label(egui::accesskit::Role::Dialog, "Unsaved changes").is_some()
|
||||
h.query_by(|n| n.role() == egui::accesskit::Role::Dialog && n.label().is_some_and(|l| l.starts_with("Save changes to “"))).is_some()
|
||||
}
|
||||
|
||||
/// The unsaved-changes question's Save answer in the platform's words (the framework dialog asks Yes and No off macOS).
|
||||
/// The unsaved-changes question's Save answer in the platform's words (production's wording, on every platform).
|
||||
fn save_answer() -> &'static str {
|
||||
if cfg!(target_os = "macos") { "Save" } else { "Yes" }
|
||||
"Save"
|
||||
}
|
||||
|
||||
fn harness() -> Harness<'static, PdfCraftApp> {
|
||||
|
||||
@@ -145,22 +145,14 @@ fn settle(r: &mut Rig, what: &str, ready: impl Fn(&PdfCraftApp) -> bool) {
|
||||
panic!("timed out waiting for {what}");
|
||||
}
|
||||
|
||||
/// The unsaved-changes question's "save it" answer as the framework words it on this OS: Save on macOS, Yes on
|
||||
/// Windows and Linux.
|
||||
/// The unsaved-changes question's "save it" answer, in production's words on every platform.
|
||||
fn save_answer() -> String {
|
||||
use craft::i18n::WordSet as _;
|
||||
let words = craft::ui::dialog::DialogWords::english();
|
||||
let save = if cfg!(target_os = "macos") { words.unsaved_save } else { words.unsaved_yes };
|
||||
save.as_str().to_string()
|
||||
"Save".to_string()
|
||||
}
|
||||
|
||||
/// The unsaved-changes question's "don't save" answer as the framework words it on this OS: Don't Save on macOS,
|
||||
/// No on Windows and Linux.
|
||||
/// The unsaved-changes question's "don't save" answer, in production's words on every platform.
|
||||
fn dont_save_answer() -> String {
|
||||
use craft::i18n::WordSet as _;
|
||||
let words = craft::ui::dialog::DialogWords::english();
|
||||
let discard = if cfg!(target_os = "macos") { words.unsaved_dont_save } else { words.unsaved_no };
|
||||
discard.as_str().to_string()
|
||||
"Don't save".to_string()
|
||||
}
|
||||
|
||||
/// Presses the button called `label` of the dialog on top (the last such node drawn).
|
||||
|
||||
@@ -129,7 +129,7 @@ fn leftovers(dir: &Path) -> Vec<craft::platform::autosave::RecoveryEntry> {
|
||||
/// The label of the question's "don't save" button on this platform.
|
||||
fn dont_save() -> &'static str {
|
||||
// PLAN: the words come from `DialogWords` (`unsaved_dont_save` on macOS, `unsaved_no` elsewhere); literal here as the catalog's English.
|
||||
if cfg!(target_os = "macos") { "Don't Save" } else { "No" }
|
||||
"Don't save"
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -288,8 +288,8 @@ fn verify_dirty_snapshot_close(h: &mut Harness<'static, PdfCraftApp>) {
|
||||
h.state_mut().views[1].close_requested = true;
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().views.len(), 2);
|
||||
h.get_by_label("Do you want to save the changes you made to “contract_signed (signed version).pdf” before closing?");
|
||||
let discard = if cfg!(target_os = "macos") { "Don't Save" } else { "No" };
|
||||
assert!(h.query_all_by_label("Save changes to “contract_signed (signed version).pdf” before closing?").next().is_some());
|
||||
let discard = "Don't save";
|
||||
h.query_all_by_label(discard).last().expect("the question has a Don't Save / No button").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().views.len(), 1);
|
||||
|
||||
@@ -24,9 +24,7 @@ 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 {
|
||||
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 }.as_str().to_owned()
|
||||
"Don't save".to_owned()
|
||||
}
|
||||
|
||||
/// `pages` portrait pages (300 × 400) with a line of text each.
|
||||
|
||||
@@ -1598,7 +1598,7 @@ fn cancelling_then_discarding_an_earlier_dirty_tab_preserves_the_selected_docume
|
||||
h.run_steps(3);
|
||||
h.get_by_label("middle.pdf").click();
|
||||
h.run_steps(3);
|
||||
let discard = if cfg!(target_os = "macos") { "Don't Save" } else { "No" };
|
||||
let discard = "Don't save";
|
||||
close_named_tab(&mut h, "first.pdf, modified");
|
||||
h.get_by_label(discard);
|
||||
h.get_by_label("Cancel").click();
|
||||
@@ -1612,7 +1612,7 @@ fn cancelling_then_discarding_an_earlier_dirty_tab_preserves_the_selected_docume
|
||||
assert_eq!(h.state().active_ids().map(|(_, id)| id), Some(ids[1]));
|
||||
assert_eq!(h.state().views.iter().map(|view| view.id).collect::<Vec<_>>(), [ids[1], ids[2]]);
|
||||
assert!(h.state().session.get(ids[0]).is_none());
|
||||
assert!(h.query_by_role_and_label(egui::accesskit::Role::Dialog, "Unsaved changes").is_none(), "no prompt is left");
|
||||
assert!(h.query_by_label_contains("before closing?").is_none(), "no prompt is left");
|
||||
for doc in h.state().session.docs() {
|
||||
assert_eq!(doc.bytes.as_slice(), FIXTURE);
|
||||
assert!(!doc.dirty);
|
||||
|
||||
@@ -251,7 +251,7 @@ fn saving_at_the_restart_question_writes_the_file_and_quits() {
|
||||
let (mut h, path) = app_with_unsaved_file("save");
|
||||
restart_to_update(&mut h);
|
||||
assert!(!h.state().dialogs.open_dialogs().is_empty(), "the unsaved-changes question is on the host");
|
||||
let accept = if cfg!(target_os = "macos") { "Save" } else { "Yes" };
|
||||
let accept = "Save";
|
||||
h.query_all_by_label(accept).last().expect("the question has a Save/Yes button").click();
|
||||
let quit = crate::support::step_until(&mut h, |h| close_requested(h));
|
||||
assert!(quit, "the app quits once the document is saved");
|
||||
|
||||
@@ -135,7 +135,7 @@ fn close_all_asks_only_for_changed_documents() {
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().views.len(), 1, "the clean document closed at once");
|
||||
// b.pdf asks to be saved: the close dialog is on screen.
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Unsaved changes");
|
||||
assert!(h.query_all_by_label_contains("Save changes to “").next().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user