Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Tests: the branch's dialog tests beside main's dialog test helpers (dialogs/tests.rs)

moppeeer788061a9ae83
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index cdcccc954..85ad65dce 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -186,64 +186,6 @@ fn color_theme(app: &DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {
mod color_theme_tests {
use super::*;
- /// Collapsing advanced TOC controls changes visibility without discarding their values.
- #[test]
- fn toc_more_options_preserves_hidden_settings() {
- let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
- app.run("file.newSample", json!({})).unwrap();
- open_toc(&mut app);
- app.ui.dialog.as_mut().unwrap().fields.insert(
- "included".into(),
- json!([{
- "style": "Headline", "level": 3, "separator": " ^t", "pageNumber": "before",
- "pageNumberStyle": "Accent", "separatorStyle": "Emphasis", "sort": true
- }]),
- );
- let before = toc_params(&app, app.ui.dialog.as_ref().unwrap());
- let revision = app.session.doc().unwrap().revision;
- let ctx = dialog_context("en");
- let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0));
- for _ in 0..3 {
- dialog_frame(&mut app, &ctx, screen, vec![]);
- }
- let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
- visible_label(&labels, screen, "Between Entry and Number:");
- click_dialog(&mut app, &ctx, screen, visible_label(&labels, screen, "Fewer Options").center());
- let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
- assert!(!labels.iter().any(|(text, _, _)| text == "Between Entry and Number:"));
- visible_label(&labels, screen, "Entry Style:");
- assert_eq!(toc_params(&app, app.ui.dialog.as_ref().unwrap()), before);
- click_dialog(&mut app, &ctx, screen, visible_label(&labels, screen, "More Options").center());
- for _ in 0..3 {
- dialog_frame(&mut app, &ctx, screen, vec![]);
- }
- let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
- visible_label(&labels, screen, "Between Entry and Number:");
- assert_eq!(toc_params(&app, app.ui.dialog.as_ref().unwrap()), before);
- assert_eq!(app.session.doc().unwrap().revision, revision);
- }
-
- /// Enter on the focused Fewer Options / More Options button toggles the options; it doesn't
- /// also make the table of contents.
- #[test]
- fn enter_on_the_toc_options_toggle_only_toggles() {
- use egui_kittest::{Harness, kittest::Queryable};
- let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
- app.run("file.newSample", json!({})).unwrap();
- open_toc(&mut app);
- let revision = app.session.doc().unwrap().revision;
- let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(|ui, app: &mut DesignApp| show(app, ui.ctx()), app);
- h.run_steps(3);
- h.get_by_label("Fewer Options").focus();
- h.run_steps(2);
- h.key_press(egui::Key::Enter);
- h.run_steps(3);
- let d = h.state().ui.dialog.as_ref().expect("the dialog stays open");
- assert_eq!((d.id.as_str(), d.b("moreOptions")), (TOC, false), "the options are fewer");
- assert_eq!(h.state().session.doc().unwrap().revision, revision, "no table of contents made");
- assert!(h.query_by_label("More Options").is_some());
- }
-
#[test]
fn color_theme_cancel_is_read_only_and_confirm_adds_the_preview() {
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs
index 84cbf3bea..549b9b6dc 100644
--- a/crates/ui-egui/src/dialogs/tests.rs
+++ b/crates/ui-egui/src/dialogs/tests.rs
@@ -3521,3 +3521,61 @@ fn character_style_options_set_the_digits() {
assert_eq!(ctl(&mut app, "ui.dialog.confirm", json!({}))["ok"], true);
assert_eq!(char_style(&app, "Emphasis").unwrap().chars.digits, Some(designcraft_doc::Digits::Farsi));
}
+
+/// Collapsing advanced TOC controls changes visibility without discarding their values.
+#[test]
+fn toc_more_options_preserves_hidden_settings() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.newSample", json!({})).unwrap();
+ open_toc(&mut app);
+ app.ui.dialog.as_mut().unwrap().fields.insert(
+ "included".into(),
+ json!([{
+ "style": "Headline", "level": 3, "separator": " ^t", "pageNumber": "before",
+ "pageNumberStyle": "Accent", "separatorStyle": "Emphasis", "sort": true
+ }]),
+ );
+ let before = toc_params(&app, app.ui.dialog.as_ref().unwrap());
+ let revision = app.session.doc().unwrap().revision;
+ let ctx = dialog_context("en");
+ let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0));
+ for _ in 0..3 {
+ dialog_frame(&mut app, &ctx, screen, vec![]);
+ }
+ let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
+ visible_label(&labels, screen, "Between Entry and Number:");
+ click_dialog(&mut app, &ctx, screen, visible_label(&labels, screen, "Fewer Options").center());
+ let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
+ assert!(!labels.iter().any(|(text, _, _)| text == "Between Entry and Number:"));
+ visible_label(&labels, screen, "Entry Style:");
+ assert_eq!(toc_params(&app, app.ui.dialog.as_ref().unwrap()), before);
+ click_dialog(&mut app, &ctx, screen, visible_label(&labels, screen, "More Options").center());
+ for _ in 0..3 {
+ dialog_frame(&mut app, &ctx, screen, vec![]);
+ }
+ let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
+ visible_label(&labels, screen, "Between Entry and Number:");
+ assert_eq!(toc_params(&app, app.ui.dialog.as_ref().unwrap()), before);
+ assert_eq!(app.session.doc().unwrap().revision, revision);
+}
+
+/// Enter on the focused Fewer Options / More Options button toggles the options; it doesn't
+/// also make the table of contents.
+#[test]
+fn enter_on_the_toc_options_toggle_only_toggles() {
+ use egui_kittest::{Harness, kittest::Queryable};
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.newSample", json!({})).unwrap();
+ open_toc(&mut app);
+ let revision = app.session.doc().unwrap().revision;
+ let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(|ui, app: &mut DesignApp| show(app, ui.ctx()), app);
+ h.run_steps(3);
+ h.get_by_label("Fewer Options").focus();
+ h.run_steps(2);
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ let d = h.state().ui.dialog.as_ref().expect("the dialog stays open");
+ assert_eq!((d.id.as_str(), d.b("moreOptions")), (TOC, false), "the options are fewer");
+ assert_eq!(h.state().session.doc().unwrap().revision, revision, "no table of contents made");
+ assert!(h.query_by_label("More Options").is_some());
+}