mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-19 08:55:26 +00:00
1 parent
aeb9704d82
commit
d7215f4441
3 files changed
+78
-6
No files matched your search
@@ -30,10 +30,16 @@ fn page_number_type_is_kept_even_when_it_only_repeats_the_defaults() {
|
||||
|
||||
#[test]
|
||||
fn page_number_type_with_a_start_and_format_still_round_trips() {
|
||||
let body = r#"<w:p><w:r><w:t>One</w:t></w:r></w:p><w:sectPr><w:pgNumType w:fmt="upperRoman" w:start="3"/></w:sectPr>"#;
|
||||
let d = wordcraft_docx::read(&docx(body)).unwrap();
|
||||
let xml = document_xml(&wordcraft_docx::write(&d).unwrap());
|
||||
assert!(xml.contains(r#"w:fmt="upperRoman""#) && xml.contains(r#"w:start="3""#), "{xml}");
|
||||
for (format, start) in [("decimal", 0), ("upperRoman", 3)] {
|
||||
let page_number_type = format!(r#"<w:pgNumType w:fmt="{format}" w:start="{start}"/>"#);
|
||||
let body = format!(r#"<w:p><w:r><w:t>One</w:t></w:r></w:p><w:sectPr>{page_number_type}</w:sectPr>"#);
|
||||
let d = wordcraft_docx::read(&docx(&body)).unwrap();
|
||||
assert_eq!(d.last_section.page_num_start, Some(start));
|
||||
let saved = wordcraft_docx::write(&d).unwrap();
|
||||
let xml = document_xml(&saved);
|
||||
assert!(xml.contains(&page_number_type), "{xml}");
|
||||
assert_eq!(wordcraft_docx::read(&saved).unwrap().last_section.page_num_start, Some(start));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -240,7 +240,7 @@ impl PageNumbersForm {
|
||||
section: wordcraft_engine::cmd::page::section_index_of_focus(&app.session),
|
||||
format: sp.page_num_format.ooxml().to_string(),
|
||||
cont: sp.page_num_start.is_none(),
|
||||
start: sp.page_num_start.unwrap_or(1).clamp(1, 100_000),
|
||||
start: sp.page_num_start.unwrap_or(1).min(100_000),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ pub(super) fn page_numbers_ui(app: &mut WordApp, ui: &mut Ui, f: &mut PageNumber
|
||||
ui.radio_value(&mut f.cont, true, tl!("Continue from previous section"));
|
||||
ui.horizontal(|ui| {
|
||||
ui.radio_value(&mut f.cont, false, tl!("Start at:"));
|
||||
ui.add_enabled(!f.cont, egui::DragValue::new(&mut f.start).range(1..=100_000));
|
||||
ui.add_enabled(!f.cont, egui::DragValue::new(&mut f.start).range(0..=100_000));
|
||||
});
|
||||
});
|
||||
let (ok, cancel) = buttons(ui, "OK", true);
|
||||
|
||||
@@ -93,6 +93,72 @@ fn page_numbers_dialog_sets_the_format_and_start() {
|
||||
assert_eq!((f.section, f.format.as_str(), f.start), (1, "lowerRoman", 9));
|
||||
}
|
||||
|
||||
/// #4911: zero is an explicit start, distinct from continuing the previous section.
|
||||
#[test]
|
||||
fn page_numbers_dialog_preserves_zero_and_continue() {
|
||||
let mut a = app();
|
||||
a.run("ui.dialog", json!({"name": "pageNumbers"})).unwrap();
|
||||
let LayoutDialog::PageNumbers(f) = form(&mut a) else { panic!("page numbers") };
|
||||
assert!(f.cont);
|
||||
assert_eq!(f.start, 1, "unspecified numbering still defaults to one");
|
||||
for start in [0, 1, 100_000] {
|
||||
a.run("layout.pageNumberFormat", json!({"start": start})).unwrap();
|
||||
assert_eq!(a.session.doc.last_section.page_num_start, Some(start));
|
||||
a.run("ui.dialog", json!({"name": "pageNumbers"})).unwrap();
|
||||
let LayoutDialog::PageNumbers(f) = form(&mut a) else { panic!("page numbers") };
|
||||
assert!(!f.cont);
|
||||
assert_eq!(f.start, start);
|
||||
assert_eq!(f.params()["start"], json!(start));
|
||||
a.run("layout.pageNumberFormat", f.params()).unwrap();
|
||||
assert_eq!(a.session.doc.last_section.page_num_start, Some(start));
|
||||
a.run("ui.dialog", json!({"name": "pageNumbers"})).unwrap();
|
||||
let LayoutDialog::PageNumbers(mut f) = form(&mut a) else { panic!("page numbers") };
|
||||
assert!(!f.cont);
|
||||
assert_eq!(f.start, start, "reopening preserves the explicit start");
|
||||
f.cont = true;
|
||||
assert_eq!(f.params()["start"], serde_json::Value::Null);
|
||||
a.run("layout.pageNumberFormat", f.params()).unwrap();
|
||||
assert_eq!(a.session.doc.last_section.page_num_start, None);
|
||||
a.run("ui.dialog", json!({"name": "pageNumbers"})).unwrap();
|
||||
let LayoutDialog::PageNumbers(f) = form(&mut a) else { panic!("page numbers") };
|
||||
assert!(f.cont);
|
||||
assert_eq!(f.start, 1, "continuing does not become an explicit zero");
|
||||
}
|
||||
}
|
||||
|
||||
/// #4911: typing zero in Start at and pressing OK restarts numbering from zero.
|
||||
#[test]
|
||||
fn page_numbers_dialog_accepts_typed_zero() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
let mut a = app();
|
||||
a.run("ui.language", json!({"value": "en"})).unwrap();
|
||||
a.run("ui.dialog", json!({"name": "pageNumbers"})).unwrap();
|
||||
// The dialog's existing numeric input and format picker lack accessible names.
|
||||
let mut h = egui_kittest::Harness::builder().with_accessibility_check(false).with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
app.logic(&ui.ctx().clone());
|
||||
app.ui(ui);
|
||||
},
|
||||
a,
|
||||
);
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Start at:").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_role(Role::SpinButton).click();
|
||||
h.run_steps(2);
|
||||
h.get_by_role(Role::SpinButton).type_text("0");
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().session.doc.last_section.page_num_start, None, "typing does not apply before OK");
|
||||
|
||||
h.get_by_role_and_label(Role::Button, "OK").click();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().dialog.is_none(), "OK closes the dialog");
|
||||
assert_eq!(h.state().session.doc.last_section.page_num_start, Some(0));
|
||||
}
|
||||
|
||||
/// #755: the Line Numbers "From text" distance and the Hyphenation zone follow the
|
||||
/// File › Options unit (centimeters here); `params` sends points whatever the unit.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user