53 lines
1.9 KiB
Rust
53 lines
1.9 KiB
Rust
//! The Print dialog in the real shell (egui_kittest): settings, preview sheets, Save as PDF.
|
|
|
|
use egui_kittest::Harness;
|
|
use egui_kittest::kittest::Queryable;
|
|
use printcraft_ui_egui::{Dialog, PrintCraftApp};
|
|
|
|
fn harness() -> Harness<'static, PrintCraftApp> {
|
|
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
|
let mut app = PrintCraftApp::new();
|
|
app.open_bytes("form.pdf", None, include_bytes!("data/form.pdf").to_vec()).unwrap();
|
|
app
|
|
});
|
|
h.run_steps(4);
|
|
h
|
|
}
|
|
|
|
#[test]
|
|
fn print_dialog_lays_out_sheets_and_saves_a_pdf() {
|
|
let mut h = harness();
|
|
assert!(h.state_mut().execute("print.dialog"));
|
|
h.run_steps(3);
|
|
assert_eq!(h.state().dialog, Some(Dialog::Print));
|
|
h.get_by_label("Pages to Print".to_uppercase().as_str());
|
|
h.get_by_label("Sheet 1 of 1");
|
|
// Two copies of the one page, as a 2-up poster-free layout: Multiple.
|
|
h.get_by_label("Multiple").click();
|
|
h.run_steps(2);
|
|
h.get_by_label("Sheet 1 of 1");
|
|
// No printer on a test machine: Save as PDF.
|
|
let out = std::env::temp_dir().join(format!("printcraft-print-test-{}.pdf", std::process::id()));
|
|
h.state_mut().save_override = Some(out.to_string_lossy().into_owned());
|
|
h.state_mut().print_draft.printer = None;
|
|
h.run_steps(1);
|
|
h.get_by_label("Save as PDF").click();
|
|
h.run_steps(3);
|
|
assert_eq!(h.state().dialog, None);
|
|
let bytes = std::fs::read(&out).expect("saved");
|
|
let doc = printcraft_cos::Document::open(std::sync::Arc::new(bytes)).unwrap();
|
|
assert_eq!(printcraft_model::pages(&doc).len(), 1);
|
|
let _ = std::fs::remove_file(out);
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_ranges_are_explained_in_the_preview() {
|
|
let mut h = harness();
|
|
h.state_mut().execute("print.dialog");
|
|
h.run_steps(2);
|
|
h.state_mut().print_draft.which = printcraft_ui_egui::PrintWhich::Range;
|
|
h.state_mut().print_draft.range = "7".into();
|
|
h.run_steps(2);
|
|
h.get_by_label_contains("out of range");
|
|
}
|