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)

moppeeera769513826a9
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index ef4814347..dc13b83ed 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -186,40 +186,6 @@ fn color_theme(app: &DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {
mod color_theme_tests {
use super::*;
- /// The title stays readable beside the style selector after the grid settles.
- #[test]
- fn toc_title_field_shows_the_whole_default_title() {
- let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
- app.run("file.newSample", json!({})).unwrap();
- open_toc(&mut app);
- 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![]);
- let title_row = |labels: &[(String, egui::Rect, egui::Rect)]| {
- let y = visible_label(labels, screen, "Title:").center().y;
- labels.iter().filter(|(_, rect, _)| (rect.center().y - y).abs() < 2.0).cloned().collect::<Vec<_>>()
- };
- visible_label(&title_row(&labels), screen, "Contents");
- app.ui.dialog.as_mut().unwrap().fields.insert("title".into(), json!("Table of Contents"));
- let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
- visible_label(&title_row(&labels), screen, "Table of Contents");
- // A small window: the title narrows and the style selector beside it stays in view.
- let small = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(450.0, 280.0));
- for _ in 0..3 {
- dialog_frame(&mut app, &ctx, small, vec![]);
- }
- let labels = dialog_frame(&mut app, &ctx, small, vec![]);
- let y = visible_label(&labels, small, "Title:").center().y;
- let row: Vec<_> = labels.iter().filter(|(_, rect, _)| (rect.center().y - y).abs() < 2.0).cloned().collect();
- let style = visible_label(&row, small, "TOC Title");
- // The selector is 200 pt wide from just before its text: all of it is in the dialog body.
- let (_, _, body) = row.iter().find(|(text, _, _)| text == "Style:").unwrap();
- assert!(style.min.x - 4.0 + 200.0 <= body.max.x, "the style selector fits the dialog: {style:?} in {body:?}");
- }
-
#[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 3d1ef0acc..7415066fb 100644
--- a/crates/ui-egui/src/dialogs/tests.rs
+++ b/crates/ui-egui/src/dialogs/tests.rs
@@ -3521,3 +3521,37 @@ 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));
}
+
+/// The title stays readable beside the style selector after the grid settles.
+#[test]
+fn toc_title_field_shows_the_whole_default_title() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.newSample", json!({})).unwrap();
+ open_toc(&mut app);
+ 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![]);
+ let title_row = |labels: &[(String, egui::Rect, egui::Rect)]| {
+ let y = visible_label(labels, screen, "Title:").center().y;
+ labels.iter().filter(|(_, rect, _)| (rect.center().y - y).abs() < 2.0).cloned().collect::<Vec<_>>()
+ };
+ visible_label(&title_row(&labels), screen, "Contents");
+ app.ui.dialog.as_mut().unwrap().fields.insert("title".into(), json!("Table of Contents"));
+ let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
+ visible_label(&title_row(&labels), screen, "Table of Contents");
+ // A small window: the title narrows and the style selector beside it stays in view.
+ let small = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(450.0, 280.0));
+ for _ in 0..3 {
+ dialog_frame(&mut app, &ctx, small, vec![]);
+ }
+ let labels = dialog_frame(&mut app, &ctx, small, vec![]);
+ let y = visible_label(&labels, small, "Title:").center().y;
+ let row: Vec<_> = labels.iter().filter(|(_, rect, _)| (rect.center().y - y).abs() < 2.0).cloned().collect();
+ let style = visible_label(&row, small, "TOC Title");
+ // The selector is 200 pt wide from just before its text: all of it is in the dialog body.
+ let (_, _, body) = row.iter().find(|(text, _, _)| text == "Style:").unwrap();
+ assert!(style.min.x - 4.0 + 200.0 <= body.max.x, "the style selector fits the dialog: {style:?} in {body:?}");
+}