mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:42:44 +00:00
Fix the PDF page options OK footer
This commit is contained in:
@@ -372,14 +372,11 @@ impl ImportPdfDialog {
|
||||
if self.held.refusal().is_some_and(|(_, refused)| *refused != self.s) {
|
||||
self.held.clear_refusal();
|
||||
}
|
||||
match (out.accepted, out.closed) {
|
||||
(Some(_), _) => {
|
||||
self.ok();
|
||||
None
|
||||
}
|
||||
(None, Some(_)) => Some(DialogResult::Cancel),
|
||||
(None, None) => None,
|
||||
if out.picked == Some(0) && !waiting {
|
||||
self.ok();
|
||||
return None;
|
||||
}
|
||||
out.closed.map(|_| DialogResult::Cancel)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The Import PDF dialog: opening and placing multi-page and password-protected PDFs.
|
||||
|
||||
use craft::ui::dialog::{HeldOk, StackDialog};
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
use vectorcraft_doc::NodeKind;
|
||||
use vectorcraft_engine::Session;
|
||||
@@ -72,6 +73,37 @@ fn artboard_widths(app: &VectorcraftApp) -> Vec<f64> {
|
||||
app.session.active().unwrap().doc.artboards.iter().map(|a| a.rect.width()).collect()
|
||||
}
|
||||
|
||||
fn click_page_footer_ok(app: VectorcraftApp) -> egui_kittest::Harness<'static, VectorcraftApp> {
|
||||
let mut fonts = false;
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(900.0, 700.0)).build_ui_state(
|
||||
move |ui, app: &mut VectorcraftApp| {
|
||||
if !std::mem::replace(&mut fonts, true) {
|
||||
crate::testing::install(ui.ctx());
|
||||
return;
|
||||
}
|
||||
app.dialogs().unwrap().with(|host| host.run(ui));
|
||||
super::import_pdf::pump(app, ui.ctx());
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(4);
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(4);
|
||||
assert!(!is_open(h.state()));
|
||||
h
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pdf_page_footer_ok_opens_the_chosen_range() {
|
||||
let mut app = app();
|
||||
io::open_bytes(&mut app, "three.pdf", &three_pages(), None).unwrap();
|
||||
set(&mut app, "allPages", json!(false));
|
||||
set(&mut app, "range", json!("2-3"));
|
||||
|
||||
let h = click_page_footer_ok(app);
|
||||
assert_eq!(artboard_widths(h.state()), [200.0, 300.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_a_multi_page_pdf_asks_for_the_pages() {
|
||||
let mut app = app();
|
||||
@@ -228,6 +260,18 @@ fn place(app: &mut VectorcraftApp, bytes: &[u8], extra: serde_json::Value) -> Re
|
||||
crate::place::run(app, &p)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pdf_page_footer_ok_places_the_chosen_page() {
|
||||
let mut app = app();
|
||||
place(&mut app, &three_pages(), json!({"at": [100, 120], "link": false})).unwrap();
|
||||
set(&mut app, "page", json!(2));
|
||||
set(&mut app, "cropTo", json!("art"));
|
||||
|
||||
let h = click_page_footer_ok(app);
|
||||
let (_, bounds) = placed(h.state());
|
||||
assert_eq!((bounds.width(), bounds.height()), (50.0, 60.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placing_a_pdf_page_asks_for_the_page_and_crop_box() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in New Issue
Block a user