From 83ea3039077ec546e6b9ac505eec5650658213e4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 04:30:11 +0000 Subject: [PATCH] Merge production main into the port: tests-a area Resolve the 23 tests-a files to the port side. Production's only edit to them is the minimal-port harness plumbing (with_context_setup( crate::framework::install_headless) around build_ui_state), which the port's test_harness already covers by building the window through SlideApp::new with the runtime installed. Drop production's new eyedropper test space_on_the_focused_slide_picks_no_colour from the app: in the port the pick is the framework DropperTool under ToolHost, and Space on the canvas is the framework's momentary Hand, so the behaviour is the framework's; it is reported as a framework trial. find_dialog_tests.rs and ribbon/add_animation_menu_tests.rs stay deleted. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/animpane_tests.rs | 16 - crates/ui-egui/src/backstage/tests.rs | 77 -- crates/ui-egui/src/browsetheme_tests.rs | 16 - crates/ui-egui/src/canvas/guides_tests.rs | 17 - crates/ui-egui/src/canvas/ruler_tests.rs | 48 -- crates/ui-egui/src/canvas/tests.rs | 24 - crates/ui-egui/src/compare_tests.rs | 15 - crates/ui-egui/src/datetime_tests.rs | 12 - .../src/dialogs/columns_dialog_tests.rs | 15 - .../ui-egui/src/dialogs/font_dialog_tests.rs | 16 - .../src/dialogs/paragraph_dialog_tests.rs | 15 - .../ui-egui/src/dialogs/photo_album_tests.rs | 19 - .../ui-egui/src/dialogs/preferences_tests.rs | 16 - .../src/dialogs/size_position_tests.rs | 9 - crates/ui-egui/src/dialogs/spelling_tests.rs | 52 -- crates/ui-egui/src/dialogs/tests.rs | 83 -- .../ui-egui/src/dialogs/theme_colors_tests.rs | 17 - .../ui-egui/src/dialogs/theme_fonts_tests.rs | 12 - crates/ui-egui/src/eyedropper_tests.rs | 36 - crates/ui-egui/src/field_frame_tests.rs | 16 - crates/ui-egui/src/huge_deck_tests.rs | 10 - crates/ui-egui/src/ime_tests.rs | 814 ------------------ crates/ui-egui/src/last_color_tests.rs | 12 - 23 files changed, 1367 deletions(-) diff --git a/crates/ui-egui/src/animpane_tests.rs b/crates/ui-egui/src/animpane_tests.rs index 22afa3798..856b1627b 100644 --- a/crates/ui-egui/src/animpane_tests.rs +++ b/crates/ui-egui/src/animpane_tests.rs @@ -19,7 +19,6 @@ fn harness() -> Harness<'static, SlideApp> { s.execute("edit.select", &json!({"ids": [id]})).unwrap(); s.execute("animation.add", &json!({"effect": effect, "start": start, "duration": dur})).unwrap(); } -<<<<<<< HEAD let mut h = crate::test_harness::harness_with( s, Services::default(), @@ -28,21 +27,6 @@ fn harness() -> Harness<'static, SlideApp> { ); // The command opens Pane::Task("animation") through the editor's pane host. h.state_mut().run("view.pane", json!({"pane": "animation"})).unwrap(); -======= - let mut app = SlideApp::new(s, Services::default()); - app.ui.pane = Some("animation".into()); - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1400.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h } diff --git a/crates/ui-egui/src/backstage/tests.rs b/crates/ui-egui/src/backstage/tests.rs index 3244da79e..1797a177a 100644 --- a/crates/ui-egui/src/backstage/tests.rs +++ b/crates/ui-egui/src/backstage/tests.rs @@ -15,22 +15,12 @@ use serde_json::json; use crate::backstage::{Backstage, Page, PrintScope, SAVE_TYPES, print_page_size, print_params, print_slides}; use crate::{Services, SlideApp}; -<<<<<<< HEAD fn harness(session: Session, files: Arc) -> Harness<'static, SlideApp> { let mut h = crate::test_harness::harness_with( session, Services::default(), Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0), |platform| platform.host = platform.host.with_files(files), -======= -fn harness(app: SlideApp) -> Harness<'static, SlideApp> { - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 ); h.run_steps(3); h @@ -140,7 +130,6 @@ fn every_page_renders() { /// The New page heads its starter templates as production did, with a plain heading: nothing folds them away. #[test] -<<<<<<< HEAD fn the_new_pages_templates_have_no_fold() { let mut h = new_app(); h.state_mut().run("app.backstage", json!({"page": Page::New.id()})).unwrap(); @@ -150,15 +139,6 @@ fn the_new_pages_templates_have_no_fold() { assert!( view.query_all_by_label("Templates").all(|node| node.accesskit_node().data().is_expanded().is_none()), "the templates heading opens and closes nothing" -======= -fn new_tiles_keep_the_right_margin_in_a_narrow_window() { - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1000.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - new_app(), ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 ); page_choice(&h, "Briefing"); } @@ -651,60 +631,3 @@ fn print_slides_follow_the_settings() { bs.print_layout = "slides"; assert_eq!(print_page_size(&bs, &doc), (doc.slide_size.width as f32, doc.slide_size.height as f32), "slides print slide-shaped"); } -<<<<<<< HEAD -======= - -/// Options in the File tab opens the Preferences dialog, and Cancel closes it (#782, #752). -#[test] -fn options_in_backstage_opens_preferences_and_cancel_closes_it() { - let mut h = harness(new_app()); - h.get_by_label("File").click(); - h.run_steps(3); - assert!(h.state().backstage_open()); - h.get_by_label("Options").click(); - h.run_steps(3); - assert!(h.state().dialog.is_some(), "Options opens Preferences dialog"); - assert_eq!(h.state().dialog.as_ref().map(|d| d.id.as_str()), Some("preferences")); - h.query_all_by_role_and_label(Role::Button, "Cancel").next().expect("Cancel button").click_accesskit(); - h.run_steps(3); - assert!(h.state().dialog.is_none(), "Cancel closes Preferences dialog"); - assert!(h.state().backstage_open(), "Backstage remains open"); -} - -/// About replaces the account entry and still opens the credits dialog. -#[test] -fn about_has_product_links_and_credits_without_account_controls() { - let mut h = harness(new_app()); - h.get_by_label("File").click(); - h.run_steps(3); - assert!(h.query_by_label("Account").is_none()); - click_nav(&h, "About"); - h.run_steps(3); - assert_eq!(page(&h), Some(Page::About)); - assert!(h.query_by_label("User Information").is_none()); - assert!(h.query_by_label("Source on GitHub").is_some()); - assert!(h.query_by_label("Join our community on Discord").is_some()); - assert!(h.query_all_by_label("Appearance").next().is_some()); - click_on_page(&h, "Credits"); - h.run_steps(3); - assert!(h.state().dialog.is_some()); - assert!(h.query_by_label("Contributors").is_some()); - assert!(h.query_by_label("Models").is_some()); -} - -/// At the 900-point minimum window width the About columns stack and Appearance stays on the page. -#[test] -fn about_appearance_stays_on_the_page_at_minimum_width() { - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(900.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - new_app(), - ); - h.state_mut().run("app.backstage", json!({"page": "about"})).unwrap(); - h.run_steps(3); - let r = h.query_all_by_role_and_label(Role::ComboBox, "Appearance").next().expect("Appearance selector").rect(); - assert!(r.right() <= 900.0, "Appearance selector ends at {}, inside the window", r.right()); -} ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 diff --git a/crates/ui-egui/src/browsetheme_tests.rs b/crates/ui-egui/src/browsetheme_tests.rs index e73b1d963..2c9095f56 100644 --- a/crates/ui-egui/src/browsetheme_tests.rs +++ b/crates/ui-egui/src/browsetheme_tests.rs @@ -19,26 +19,10 @@ fn browse_button_applies_the_picked_files_theme() { let files = Arc::new(ScriptedFiles::answering([Picked::Contents(vec![("Brand.pptx".into(), bytes)])]).hosted()); let mut s = Session::with_new(); s.execute("slide.new", &json!({"layout": "title", "title": "Hello"})).unwrap(); -<<<<<<< HEAD let mut h = crate::test_harness::harness_with(s, Services::default(), Harness::builder().with_size(egui::vec2(1600.0, 900.0)), |p| { p.host = p.host.clone().with_files(files.clone()) }); h.state_mut().ui.tab = "Design".into(); -======= - let mut app = SlideApp::new(s, services); - app.ui.tab = "Design".into(); - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1600.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h.get_by_label("Browse for Themes…").click(); h.run_steps(3); diff --git a/crates/ui-egui/src/canvas/guides_tests.rs b/crates/ui-egui/src/canvas/guides_tests.rs index d9df32d4d..56d82fb49 100644 --- a/crates/ui-egui/src/canvas/guides_tests.rs +++ b/crates/ui-egui/src/canvas/guides_tests.rs @@ -26,7 +26,6 @@ fn drag(h: &mut Harness<'_, SlideApp>, from: Pos2, to: Pos2) { #[test] fn turn_guides_on_drag_one_and_drop_it_off_the_slide() { let _gpu = crate::gpu_lock::gpu_lock(); -<<<<<<< HEAD let mut session = Session::with_new(); session.execute("slide.new", &json!({"layout": "blank"})).unwrap(); session.prefs.snap_to_grid = true; @@ -47,22 +46,6 @@ fn turn_guides_on_drag_one_and_drop_it_off_the_slide() { } }), ); -======= - let mut s = Session::with_new(); - s.execute("slide.new", &json!({"layout": "blank"})).unwrap(); - let app = SlideApp::new(s, Services::default()); - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1400.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); let words = words.get().unwrap(); h.state_mut().run("view.guides", json!({"on": true})).unwrap(); diff --git a/crates/ui-egui/src/canvas/ruler_tests.rs b/crates/ui-egui/src/canvas/ruler_tests.rs index 7617ff4aa..b34fe7de4 100644 --- a/crates/ui-egui/src/canvas/ruler_tests.rs +++ b/crates/ui-egui/src/canvas/ruler_tests.rs @@ -44,7 +44,6 @@ fn ruler(h: &mut Harness<'_, SlideApp>) -> serde_json::Value { #[test] fn drag_indents_add_move_and_remove_tabs_on_the_ruler() { let _gpu = crate::gpu_lock::gpu_lock(); -<<<<<<< HEAD let mut h = editing_harness(); let words = Arc::new(OnceLock::new()); let resolved_words = words.clone(); @@ -60,32 +59,6 @@ fn drag_indents_add_move_and_remove_tabs_on_the_ruler() { let (slide, scale) = (h.state().slide_rect().unwrap(), h.state().canvas_scale()); let x0 = initial["x"].as_f64().unwrap() as f32; let rx = |q: f32| slide.min.x + (x0 + q) * scale; -======= - let mut s = Session::with_new(); - s.execute("slide.new", &json!({"layout": "blank"})).unwrap(); - let id = s.execute("insert.textBox", &json!({"rect": [100, 150, 500, 40]})).unwrap()["id"].as_u64().unwrap(); - s.execute("text.edit", &json!({"id": id})).unwrap(); - s.execute("text.insert", &json!({"text": "Name\tRole\tTeam"})).unwrap(); - let mut app = SlideApp::new(s, Services::default()); - app.ui.ruler = true; - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1400.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); - h.run_steps(3); - let (slide, k) = (h.state().slide_rect.unwrap(), h.state().canvas_scale); - let x0 = ruler(&mut h)["x"].as_f64().unwrap() as f32; - // The horizontal ruler runs along the top of the canvas. - let top = h.state().canvas_rect.unwrap().min.y; - let rx = |q: f32| slide.min.x + (x0 + q) * k; ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 let first = h.get_by_label(words.first_line_indent.as_str()).rect().center(); drag(&mut h, first, Pos2::new(rx(36.0), first.y)); @@ -142,7 +115,6 @@ fn drag_indents_add_move_and_remove_tabs_on_the_ruler() { } fn editing_harness() -> Harness<'static, SlideApp> { -<<<<<<< HEAD let mut session = Session::with_new(); session.execute("slide.new", &json!({"layout": "blank"})).unwrap(); let id = session.execute("insert.textBox", &json!({"rect": [100, 150, 500, 40]})).unwrap()["id"].as_u64().unwrap(); @@ -163,26 +135,6 @@ fn editing_harness() -> Harness<'static, SlideApp> { } }), ); -======= - let mut s = Session::with_new(); - s.execute("slide.new", &json!({"layout": "blank"})).unwrap(); - let id = s.execute("insert.textBox", &json!({"rect": [100, 150, 500, 40]})).unwrap()["id"].as_u64().unwrap(); - s.execute("text.edit", &json!({"id": id})).unwrap(); - s.execute("text.insert", &json!({"text": "Item\t9.50"})).unwrap(); - let mut app = SlideApp::new(s, Services::default()); - app.ui.ruler = true; - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1400.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h } diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 1f3962415..1034c8ff2 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -86,18 +86,8 @@ fn a_placeholder_that_inherits_its_box_has_a_resize_cursor() { } fn harness() -> Harness<'static, SlideApp> { -<<<<<<< HEAD let mut h = crate::test_harness::harness_with(Session::with_new(), Services::default(), Harness::builder().with_size(vec2(1200.0, 800.0)), |_| {}); -======= - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(Session::with_new(), Services::default()), - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h } @@ -214,23 +204,9 @@ fn app_with_table() -> (Harness<'static, SlideApp>, deckcraft_model::ShapeId) { let r = s.execute("insert.table", &json!({"rows": 2, "cols": 2, "rect": [100.0, 100.0, 400.0, 80.0], "data": data})).unwrap(); let id = deckcraft_model::ShapeId(r["id"].as_u64().unwrap() as u32); s.execute("edit.deselect", &json!({})).unwrap(); -<<<<<<< HEAD let mut h = crate::test_harness::harness_with(s, Services::default(), Harness::builder().with_size(vec2(1200.0, 800.0)), |_| {}); h.run_steps(2); (h, id) -======= - let mut harness = - egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1200.0, 800.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(s, Services::default()), - ); - // The app keeps requesting repaints, so step frames instead of run(). - harness.run_steps(2); - (harness, id) ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 } /// Screen position of slide point (x, y). diff --git a/crates/ui-egui/src/compare_tests.rs b/crates/ui-egui/src/compare_tests.rs index e7802258d..aec10b30f 100644 --- a/crates/ui-egui/src/compare_tests.rs +++ b/crates/ui-egui/src/compare_tests.rs @@ -21,22 +21,7 @@ fn harness() -> (Harness<'static, SlideApp>, usize) { s.close_document(1); s.set_active(0); s.execute("review.compare", &json!({"name": "Q3 review.deckcraft", "data": rev})).unwrap(); -<<<<<<< HEAD let mut h = crate::test_harness::harness(s, Services::default()); -======= - let app = SlideApp::new(s, Services::default()); - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1400.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(4); (h, n) } diff --git a/crates/ui-egui/src/datetime_tests.rs b/crates/ui-egui/src/datetime_tests.rs index ef6be0f3a..de6c84b74 100644 --- a/crates/ui-egui/src/datetime_tests.rs +++ b/crates/ui-egui/src/datetime_tests.rs @@ -9,20 +9,8 @@ use serde_json::json; use crate::{Services, SlideApp}; fn harness() -> Harness<'static, SlideApp> { -<<<<<<< HEAD let builder = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)).with_step_dt(1.0 / 60.0); let mut h = crate::test_harness::harness_with(Session::with_new(), Services::default(), builder, |_| {}); -======= - let mut app = SlideApp::new(Session::with_new(), Services::default()); - app.ui.tab = "Insert".into(); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h } diff --git a/crates/ui-egui/src/dialogs/columns_dialog_tests.rs b/crates/ui-egui/src/dialogs/columns_dialog_tests.rs index 4bfaf00b3..6f1ba2fcd 100644 --- a/crates/ui-egui/src/dialogs/columns_dialog_tests.rs +++ b/crates/ui-egui/src/dialogs/columns_dialog_tests.rs @@ -29,22 +29,7 @@ fn two_boxes() -> Harness<'static, SlideApp> { } fn harness_of(s: Session) -> Harness<'static, SlideApp> { -<<<<<<< HEAD let mut h: Harness<'static, SlideApp> = crate::test_harness::harness(s, Services::default()); -======= - let app = SlideApp::new(s, Services::default()); - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1440.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(4); h } diff --git a/crates/ui-egui/src/dialogs/font_dialog_tests.rs b/crates/ui-egui/src/dialogs/font_dialog_tests.rs index 6476d5b91..52f875b8e 100644 --- a/crates/ui-egui/src/dialogs/font_dialog_tests.rs +++ b/crates/ui-egui/src/dialogs/font_dialog_tests.rs @@ -12,25 +12,9 @@ fn harness() -> Harness<'static, SlideApp> { let mut s = Session::with_new(); s.execute("shape.insert", &json!({"preset": "rect", "rect": [80.0, 80.0, 320.0, 80.0], "text": "Hello"})).unwrap(); // A selected shape, not a caret: the dialog then formats the text that is already there. -<<<<<<< HEAD s.execute("text.exit", &json!({})).unwrap(); let builder = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0); let mut h = crate::test_harness::harness_with(s, Services::default(), builder, |_| {}); -======= - let _ = s.execute("text.exit", &json!({})); - let app = SlideApp::new(s, Services::default()); - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1440.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(4); h } diff --git a/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs b/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs index bd7d0da21..b38a8b89c 100644 --- a/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs +++ b/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs @@ -12,22 +12,7 @@ fn harness() -> Harness<'static, SlideApp> { let mut s = Session::with_new(); s.execute("shape.insert", &json!({"preset": "rect", "rect": [80.0, 80.0, 320.0, 80.0], "text": "Hello"})).unwrap(); let _ = s.execute("text.exit", &json!({})); -<<<<<<< HEAD let mut h = crate::test_harness::harness(s, Services::default()); -======= - let app = SlideApp::new(s, Services::default()); - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1440.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(4); h } diff --git a/crates/ui-egui/src/dialogs/photo_album_tests.rs b/crates/ui-egui/src/dialogs/photo_album_tests.rs index 7873d3a5a..14fb5fd43 100644 --- a/crates/ui-egui/src/dialogs/photo_album_tests.rs +++ b/crates/ui-egui/src/dialogs/photo_album_tests.rs @@ -21,25 +21,6 @@ fn png() -> Vec { ] } -<<<<<<< HEAD -======= -fn harness(app: SlideApp) -> Harness<'static, SlideApp> { - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1600.0, 1200.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); - h.run_steps(3); - h -} - ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 fn slides(h: &Harness<'_, SlideApp>) -> usize { h.state().session.active().map(|d| d.doc.slides.len()).unwrap_or(0) } diff --git a/crates/ui-egui/src/dialogs/preferences_tests.rs b/crates/ui-egui/src/dialogs/preferences_tests.rs index d37940286..f256724f8 100644 --- a/crates/ui-egui/src/dialogs/preferences_tests.rs +++ b/crates/ui-egui/src/dialogs/preferences_tests.rs @@ -20,22 +20,6 @@ fn interface_size<'a>(h: &'a Harness<'_, SlideApp>) -> Node<'a> { slider } -<<<<<<< HEAD -======= -fn harness() -> Harness<'static, SlideApp> { - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(Session::with_new(), Services::default()), - ); - // The app keeps asking for frames, so step instead of run(). - h.run_steps(3); - h -} - ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 fn open_options(h: &mut Harness<'_, SlideApp>) { h.state_mut().open_dialog("preferences", json!({})); h.run_steps(3); diff --git a/crates/ui-egui/src/dialogs/size_position_tests.rs b/crates/ui-egui/src/dialogs/size_position_tests.rs index a3f7270a2..4fe325beb 100644 --- a/crates/ui-egui/src/dialogs/size_position_tests.rs +++ b/crates/ui-egui/src/dialogs/size_position_tests.rs @@ -7,20 +7,11 @@ use serde_json::json; use crate::{Services, SlideApp}; fn harness() -> Harness<'static, SlideApp> { -<<<<<<< HEAD let mut h = crate::test_harness::harness_with( deckcraft_engine::Session::with_new(), Services::default(), Harness::builder().with_size(egui::vec2(1600.0, 900.0)).with_step_dt(1.0 / 60.0), |_| {}, -======= - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1600.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(deckcraft_engine::Session::with_new(), Services::default()), ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 ); h.run_steps(2); h diff --git a/crates/ui-egui/src/dialogs/spelling_tests.rs b/crates/ui-egui/src/dialogs/spelling_tests.rs index cb42688bc..57d86cf2e 100644 --- a/crates/ui-egui/src/dialogs/spelling_tests.rs +++ b/crates/ui-egui/src/dialogs/spelling_tests.rs @@ -15,7 +15,6 @@ fn spelling_dialog_changes_and_ignores_words() { let aff = "SET UTF-8\nTRY esianrtolcdugmphbyfvkwzxjq\nSFX S Y 1\nSFX S 0 s .\n"; let dic = "6\nthe/S\nslide/S\nquarter/S\nplan/S\nour\nfor\n"; deckcraft_engine::spell::install("en-US", deckcraft_engine::spell::Dictionary::parse(aff.as_bytes(), dic.as_bytes())); -<<<<<<< HEAD let mut session = Session::with_new(); session.execute("slide.layout", &json!({"layout": "blank"})).unwrap(); let original = "our plan\n— Our plna for teh quarter"; @@ -23,18 +22,6 @@ fn spelling_dialog_changes_and_ignores_words() { session.execute("shape.insert", &json!({"preset": "rect", "rect": [100, 100, 500, 120], "text": original})).unwrap()["id"].as_u64().unwrap(); let mut h = harness_with(session, Services::default(), Harness::builder().with_size(egui::vec2(1100.0, 700.0)), |_| {}); h.state_mut().open_dialog("spelling", json!({})); -======= - let mut app = SlideApp::new(Session::with_new(), Services::default()); - app.session.execute("shape.insert", &json!({"preset": "rect", "rect": [100, 100, 500, 120], "text": "Our plna for teh quarter"})).unwrap(); - app.dialog = Some(crate::dialogs::Dialog::new("spelling")); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 700.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); let words = h.state().host.words().set::(); let count = |h: &Harness<'_, SlideApp>| super::inspect(&h.ctx)[0]["fields"]["count"].as_u64().unwrap(); @@ -101,22 +88,8 @@ fn squiggles_mark_misspelt_words_in_the_background() { Ok(()) }) .unwrap(); -<<<<<<< HEAD session.execute("edit.select", &json!({"ids": []})).unwrap(); let mut h = harness_with(session, Services::default(), Harness::builder().with_size(egui::vec2(1100.0, 700.0)), |_| {}); -======= - app.session.execute("edit.select", &json!({"ids": []})).unwrap(); - let st = app.session.active().unwrap().clone(); - let lines = app.squiggles.settle(&st); - assert_eq!(lines.len(), 3, "{lines:?}"); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 700.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(4); if let (Ok(path), Ok(img)) = (std::env::var("DECKCRAFT_PNG_OUT_SQUIGGLES"), h.render()) { let _ = img.save(path); @@ -193,7 +166,6 @@ fn squiggles_in_table_cells_and_notes_and_on_the_ui_thread() { assert_eq!(lines.len(), 2, "Regoin and Soth: {lines:?}"); // Each under its own cell: the first in the top-left one, the second in the bottom-right one. assert!(lines[0].0.x < 380.0 && lines[0].0.y < 160.0 && lines[1].0.x > 380.0 && lines[1].0.y > 160.0, "{lines:?}"); -<<<<<<< HEAD let flags = h.state_mut().squiggles.settle_notes(note_source, "xx-TB"); let end = note_source.chars().count(); let first_end = note_source.split_whitespace().next().unwrap().chars().count(); @@ -201,17 +173,6 @@ fn squiggles_in_table_cells_and_notes_and_on_the_ui_thread() { assert_eq!(flags, vec![(0, first_end), (last_start, end)]); let flagged: Vec = flags.iter().map(|&(start, end)| note_source.chars().skip(start).take(end - start).collect()).collect(); assert_eq!(flagged, vec![note_source.split_whitespace().next().unwrap(), note_source.split_whitespace().last().unwrap()]); -======= - assert_eq!(app.squiggles.settle_notes("Remmeber to show the totl", "xx-TB"), vec![(0, 8), (21, 25)]); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 760.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); - h.run_steps(6); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 if let (Ok(path), Ok(img)) = (std::env::var("DECKCRAFT_PNG_OUT_TABLE"), h.render()) { let _ = img.save(path); } @@ -276,21 +237,8 @@ fn notes_menu_language_dialog_and_repeated_words() { Ok(()) }) .unwrap(); -<<<<<<< HEAD let mut h = harness_with(session, Services::default(), Harness::builder().with_size(egui::vec2(1100.0, 760.0)), |_| {}); h.state_mut().ui.notes = true; -======= - let st = app.session.active().unwrap().clone(); - // "is is" is flagged as repeated, "wrok" as misspelt. - assert_eq!(app.squiggles.settle(&st).len(), 2); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1100.0, 760.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(8); let st = h.state().session.active().unwrap().clone(); // "is is" is flagged as repeated, "wrok" as misspelt. diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index 2b5cdd2d0..707d10de2 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -63,18 +63,7 @@ fn header_footer_apply_keeps_an_existing_date_format() { }) .collect() }; -<<<<<<< HEAD let mut harness = crate::test_harness::harness_with(session, Services::default(), Harness::builder().with_size(vec2(1200.0, 900.0)), |_| {}); -======= - let mut harness = - egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(session, crate::Services::default()), - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 harness.run_steps(2); assert_eq!(date_fields(harness.state()), vec!["datetime4".to_string()]); harness.state_mut().run("app.dialog", json!({"id": "headerFooter"})).unwrap(); @@ -90,7 +79,6 @@ fn export_dialog_writes_an_animated_gif() { let files = Arc::new(ScriptedFiles::new().saving_suggested()); let mut session = deckcraft_engine::Session::with_new(); session.execute("slide.new", &json!({})).unwrap(); -<<<<<<< HEAD let mut h = export_harness(session, files.clone()); h.run_steps(2); h.state_mut().run("app.exportDialog", json!({})).unwrap(); @@ -121,40 +109,6 @@ fn export_dialog_writes_an_animated_gif() { let path = &written[0]; assert_eq!(path.extension().unwrap(), "gif"); let bytes = files.file(path).unwrap(); -======= - let mut harness = - egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(session, services), - ); - harness.run_steps(2); - harness.state_mut().run("app.exportDialog", json!({})).unwrap(); - harness.run_steps(2); - harness.get_by_label("Animated GIF (.gif)").click_accesskit(); - harness.run_steps(2); - assert_eq!(harness.state().dialog.as_ref().and_then(|d| d.fields.get("fmt")).map(String::as_str), Some("gif")); - harness.get_by_label("Seconds per slide:"); - harness.get_by_label("Loop forever").click_accesskit(); - harness.run_steps(2); - // A range outside the deck keeps the dialog open with a message, and nothing is written. - harness.state_mut().dialog.as_mut().unwrap().fields.insert("gifTo".into(), "9".into()); - harness.run_steps(2); - harness.key_press(egui::Key::Enter); - harness.run_steps(2); - assert!(harness.state().dialog.is_some()); - assert!(harness.state().status.as_ref().is_some_and(|(m, _)| m.contains("Slides")), "{:?}", harness.state().status); - assert!(!path.exists()); - harness.state_mut().dialog.as_mut().unwrap().fields.insert("gifTo".into(), "2".into()); - harness.run_steps(2); - harness.key_press(egui::Key::Enter); - harness.run_steps(2); - assert!(harness.state().dialog.is_none(), "the dialog closes after exporting"); - assert!(suggested.borrow().ends_with(".gif"), "{}", suggested.borrow()); - let bytes = std::fs::read(&path).unwrap(); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 assert!(bytes.starts_with(b"GIF89a")); assert_eq!(u16::from_le_bytes([bytes[6], bytes[7]]), 960, "medium by default"); assert!(!bytes.windows(11).any(|w| w == b"NETSCAPE2.0"), "Loop forever unticked: plays once"); @@ -163,7 +117,6 @@ fn export_dialog_writes_an_animated_gif() { /// The transparent PNG option omits the slide background from the exported pixels. #[test] fn export_dialog_writes_a_png_with_a_transparent_background() { -<<<<<<< HEAD let files = Arc::new(ScriptedFiles::new().saving_suggested()); let mut h = export_harness(deckcraft_engine::Session::with_new(), files.clone()); h.run_steps(2); @@ -177,42 +130,6 @@ fn export_dialog_writes_a_png_with_a_transparent_background() { let written = files.written(); assert_eq!(written.len(), 1); let img = deckcraft_render::decode_image(&files.file(&written[0]).unwrap()).unwrap(); -======= - use egui::vec2; - use egui_kittest::kittest::Queryable as _; - use serde_json::json; - - use crate::SlideApp; - let dir = std::env::temp_dir().join(format!("deckcraft-ui-png-clear-{}", std::process::id())); - std::fs::create_dir_all(&dir).unwrap(); - let path = dir.join("slide.png"); - let picked = path.to_string_lossy().to_string(); - let services = crate::Services { pick_save: Some(Box::new(move |_: &str| Some(picked.clone()))), ..Default::default() }; - let mut harness = - egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(vec2(1200.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(deckcraft_engine::Session::with_new(), services), - ); - harness.run_steps(2); - harness.state_mut().run("app.exportDialog", json!({})).unwrap(); - harness.run_steps(2); - assert!(harness.query_by_label("Transparent background").is_none(), "PDF has no transparent background"); - harness.get_by_label("JPEG image (current slide)").click_accesskit(); - harness.run_steps(2); - assert!(harness.query_by_label("Transparent background").is_none(), "nor has JPEG"); - harness.get_by_label("PNG images (current slide)").click_accesskit(); - harness.run_steps(2); - harness.get_by_label("Transparent background").click_accesskit(); - harness.run_steps(2); - assert_eq!(harness.state().dialog.as_ref().and_then(|d| d.fields.get("pngTransparent")).map(String::as_str), Some("true")); - harness.key_press(egui::Key::Enter); - harness.run_steps(2); - assert!(harness.state().dialog.is_none(), "the dialog closes after exporting"); - let img = deckcraft_render::decode_image(&std::fs::read(&path).unwrap()).unwrap(); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 assert_eq!(img.get_pixel(2, 2).0[3], 0, "the background is left out"); } diff --git a/crates/ui-egui/src/dialogs/theme_colors_tests.rs b/crates/ui-egui/src/dialogs/theme_colors_tests.rs index 0a5d4e747..e85067295 100644 --- a/crates/ui-egui/src/dialogs/theme_colors_tests.rs +++ b/crates/ui-egui/src/dialogs/theme_colors_tests.rs @@ -9,23 +9,6 @@ use serde_json::json; use crate::test_harness::harness_with; use crate::{Services, SlideApp}; -<<<<<<< HEAD -======= -fn harness() -> Harness<'static, SlideApp> { - let mut app = SlideApp::new(Session::with_new(), Services::default()); - app.ui.tab = "Design".into(); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); - h.run_steps(3); - h -} - ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 fn scheme(h: &Harness<'_, SlideApp>) -> deckcraft_color::ColorScheme { h.state().session.active().unwrap().doc.masters[0].theme.colors.clone() } diff --git a/crates/ui-egui/src/dialogs/theme_fonts_tests.rs b/crates/ui-egui/src/dialogs/theme_fonts_tests.rs index f27c6e497..65094c017 100644 --- a/crates/ui-egui/src/dialogs/theme_fonts_tests.rs +++ b/crates/ui-egui/src/dialogs/theme_fonts_tests.rs @@ -8,20 +8,8 @@ use serde_json::json; use crate::{Services, SlideApp}; fn harness() -> Harness<'static, SlideApp> { -<<<<<<< HEAD let builder = Harness::builder().with_size(egui::vec2(1800.0, 1100.0)); let mut h = crate::test_harness::harness_with(Session::with_new(), Services::default(), builder, |_| {}); -======= - let mut app = SlideApp::new(Session::with_new(), Services::default()); - app.ui.tab = "Design".into(); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 1100.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h } diff --git a/crates/ui-egui/src/eyedropper_tests.rs b/crates/ui-egui/src/eyedropper_tests.rs index 8d64e33a3..2c1e39972 100644 --- a/crates/ui-egui/src/eyedropper_tests.rs +++ b/crates/ui-egui/src/eyedropper_tests.rs @@ -20,20 +20,9 @@ fn harness() -> Harness<'static, SlideApp> { let mut session = Session::with_new(); session.execute("slide.new", &json!({"layout": "blank"})).unwrap(); session.execute("shape.insert", &json!({"preset": "rect", "rect": [100, 100, 200, 100]})).unwrap(); -<<<<<<< HEAD session.execute("shape.fill", &json!({"color": RED.hex()})).unwrap(); let mut h = crate::test_harness::harness_with(session, Services::default(), Harness::builder().with_size(egui::vec2(1400.0, 900.0)), |_| {}); rerun_input_passes(&h); -======= - session.execute("shape.fill", &json!({"color": "#ff0000"})).unwrap(); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(session, Services::default()), - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(4); h } @@ -81,19 +70,6 @@ fn selection(h: &Harness<'static, SlideApp>) -> Vec { h.state().session.doc().unwrap().selection.shapes.iter().map(|s| s.0).collect() } -#[test] -fn space_on_the_focused_slide_picks_no_colour() { - let mut h = harness(); - ask(&mut h); - let on_shape = at(&h, 150.0, 150.0); - h.input_mut().events.push(Event::PointerMoved(on_shape)); - h.run_steps(3); - assert!(h.ctx.memory(|m| m.has_focus(crate::framework::document_id()))); - h.key_press(egui::Key::Space); - h.run_steps(3); - assert!(h.state().eyedropper.is_some() && !result_waits_for(&h.ctx, menu())); -} - #[test] fn a_click_on_the_slide_takes_the_colour_under_it_and_nothing_else_happens() { let mut h = harness(); @@ -167,21 +143,9 @@ fn set_transparent_color_takes_the_colour_clicked_in_the_picture() { session.execute("slide.new", &json!({"layout": "blank"})).unwrap(); let data = deckcraft_engine::cmd::base64_encode(&png); session.execute("insert.picture", &json!({"data": data, "name": "a.png", "rect": [100, 100, 400, 200]})).unwrap(); -<<<<<<< HEAD let mut h = crate::test_harness::harness_with(session, Services::default(), Harness::builder().with_size(egui::vec2(1600.0, 1200.0)), |_| {}); h.state_mut().ui.tab = "Picture Format".into(); rerun_input_passes(&h); -======= - let mut app = SlideApp::new(session, Services::default()); - app.ui.tab = "Picture Format".into(); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1600.0, 1200.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(4); h.get_by_label("Color").click(); h.run_steps(3); diff --git a/crates/ui-egui/src/field_frame_tests.rs b/crates/ui-egui/src/field_frame_tests.rs index 1024ae615..2250f965b 100644 --- a/crates/ui-egui/src/field_frame_tests.rs +++ b/crates/ui-egui/src/field_frame_tests.rs @@ -12,25 +12,9 @@ use serde_json::json; use crate::{Services, SlideApp}; -<<<<<<< HEAD fn harness() -> Harness<'static, SlideApp> { let mut h = crate::test_harness::harness(Session::with_new(), Services::default()); h.state_mut().ui.brightness = Default::default(); -======= -fn harness(app: SlideApp) -> Harness<'static, SlideApp> { - let mut h = Harness::builder() - .with_context_setup(crate::framework::install_headless) - .with_size(egui::vec2(1400.0, 900.0)) - .with_step_dt(1.0 / 60.0) - .build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); - // The app keeps asking for frames, so step instead of run(). ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h } diff --git a/crates/ui-egui/src/huge_deck_tests.rs b/crates/ui-egui/src/huge_deck_tests.rs index 016c2d4a5..de1b7e40e 100644 --- a/crates/ui-egui/src/huge_deck_tests.rs +++ b/crates/ui-egui/src/huge_deck_tests.rs @@ -13,7 +13,6 @@ fn harness(n: usize) -> egui_kittest::Harness<'static, SlideApp> { for _ in 1..n { s.execute("slide.new", &json!({})).unwrap(); } -<<<<<<< HEAD crate::test_harness::harness(s, Services::default()) } @@ -29,15 +28,6 @@ fn step_uploads(h: &mut egui_kittest::Harness<'_, SlideApp>, frames: usize) -> u let before = renders(h); h.run_steps(frames); renders(h) - before -======= - egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1400.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(s, Services::default()), - ) ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 } /// Outline view of 2000 slides lays out the slides in view (and the current one), not all 2000 diff --git a/crates/ui-egui/src/ime_tests.rs b/crates/ui-egui/src/ime_tests.rs index 2b2ea24b6..cf6ff4d38 100644 --- a/crates/ui-egui/src/ime_tests.rs +++ b/crates/ui-egui/src/ime_tests.rs @@ -8,21 +8,8 @@ use crate::{Services, SlideApp}; use deckcraft_engine::Session; fn harness(session: Session) -> egui_kittest::Harness<'static, SlideApp> { -<<<<<<< HEAD let builder = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)); let mut h = crate::test_harness::harness_with(session, Services::default(), builder, |_| {}); -======= - let mut h = - egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1280.0, 800.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SlideApp::new(session, Services::default()), - ); - crate::install_ime_pass_hooks(&h.ctx); - // The app keeps requesting repaints, so step frames instead of run(). ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); h } @@ -81,808 +68,7 @@ fn japanese_conversion_shows_the_active_part() { h.state_mut().run("text.edit", json!({"id": title})).unwrap(); // The platform composes only after a frame's output turned the input method on. h.run_steps(2); -<<<<<<< HEAD assert!(h.output().platform_output.ime.is_some()); -======= - let u = deckcraft_engine::cmd::text::composition_underlines(h.state().session.active().unwrap()); - assert_eq!(u.iter().filter(|x| x.2).count(), 1, "{u:?}"); - let undo0 = undo_len(h.state()); - // kittest runs one frame per queued event. Assert the key-down frame itself: the platform - // composition must be cancelled there, not one frame later after the key-up releases it. - h.key_down(egui::Key::End); - h.run_steps(1); - let interrupted = h.output().platform_output.ime.clone().expect("still editing"); - assert!(interrupted.should_interrupt_composition, "the platform composition is interrupted"); - assert_eq!(title_text(h.state()), "日本ご"); - assert!(h.state().session.active().unwrap().composition.is_none()); - assert_eq!(undo_len(h.state()), undo0 + 1); - h.key_up(egui::Key::End); - h.run_steps(1); - // The published interrupt is the platform reset boundary; the tombstone for the settled - // generation ends there, so a later commit-only event is treated as a new platform - // generation rather than being dropped for the rest of the session. - assert!(h.state().ime_cancelled.is_none(), "the published interrupt retired the settled tombstone"); -} - -/// A composition the application settled (here an End key) drops the platform pre-edit and commit -/// already queued in the same input batch, so the conversion is typed once. The published -/// interrupt is the explicit boundary: after it the next pre-edit is a new generation. A commit -/// the platform queues after that reset is indistinguishable from a legitimate direct commit -/// (egui's events carry no generation), so the bounded tombstone does not pretend otherwise. -#[test] -fn settled_composition_drops_queued_preedit_and_same_batch_commit() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.event(preedit("日本")); - h.run_steps(1); - let undo0 = undo_len(h.state()); - - // One RawInput: the key settles the composition and the platform's queued pre-edit/commit - // arrive after it in the same pass. None of them may be applied. Force an extra discarded - // pass too: the interrupt may only be consumed by the settled pass the platform sees. - h.ctx.request_discard("ime interrupt through a discarded pass"); - h.input_mut().events.push(Event::Key { key: egui::Key::End, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }); - h.input_mut().events.push(preedit("日本")); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("日本".into()))); - h.input_mut().events.push(Event::Key { key: egui::Key::End, physical_key: None, pressed: false, repeat: false, modifiers: Default::default() }); - h.run_steps(1); - assert_eq!(title_text(h.state()), "日本", "the stale pre-edit and commit do not restart the cancelled composition"); - assert!(h.state().session.active().unwrap().composition.is_none()); - assert_eq!(undo_len(h.state()), undo0 + 1, "the settled composition is one undo step"); - let interrupted = h.output().platform_output.ime.clone().expect("still editing"); - assert!(interrupted.should_interrupt_composition, "the settled platform composition is interrupted"); - assert!(h.state().ime_cancelled.is_none(), "the settled pass published the interrupt and retired the tombstone"); - let reset = interrupted.reset_request.expect("the settled pass carries the opaque reset request"); - - // A real new composition is admitted only by the exact ordered completion. - h.input_mut().events.extend([reset_completed(reset), preedit("新")]); - h.run_steps(1); - assert_eq!(title_text(h.state()), "日本新", "a legitimate new pre-edit starts a new generation"); - assert!(h.state().session.active().unwrap().composition.is_some()); - h.event(Event::Ime(ImeEvent::Commit("新".into()))); - h.run_steps(1); - assert_eq!(title_text(h.state()), "日本新"); -} - -/// A commit-only event in the settling batch is stale (it belongs to the composition the key -/// ended). After the published interrupt, a later commit-only event is a legitimate direct input -/// method commit and must not be swallowed by a permanent tombstone. -#[test] -fn stale_commit_in_the_settling_batch_is_rejected_and_a_later_direct_commit_is_accepted() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.event(preedit("日本")); - h.run_steps(1); - let undo0 = undo_len(h.state()); - - // One RawInput: the key settles the composition and the platform's queued commit follows. - h.input_mut().events.push(Event::Key { key: egui::Key::End, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("日本".into()))); - h.input_mut().events.push(Event::Key { key: egui::Key::End, physical_key: None, pressed: false, repeat: false, modifiers: Default::default() }); - h.run_steps(1); - assert_eq!(title_text(h.state()), "日本", "the same-batch commit does not type the conversion twice"); - assert_eq!(undo_len(h.state()), undo0 + 1); - assert!(h.state().ime_cancelled.is_none(), "the published interrupt retired the tombstone"); - let reset = h.output().platform_output.ime.as_ref().and_then(|ime| ime.reset_request).expect("the settled pass carries the opaque reset request"); - - // A direct commit with no pre-edit (a real IME's punctuation/full-width character path) - // arrives after the exact ordered completion and is accepted. - h.input_mut().events.extend([reset_completed(reset), Event::Ime(ImeEvent::Commit("。".into()))]); - h.run_steps(1); - assert_eq!(title_text(h.state()), "日本。", "a later commit-only is not lost"); -} - -/// The interrupt is only a boundary when it reaches the platform. A discarded layout/font pass -/// keeps both the pending interrupt and the tombstone; the next settled pass retires the tombstone -/// and publishes the reset. Assert the per-pass state, not just the final output carrier. -#[test] -fn a_discarded_pass_keeps_the_tombstone_until_a_settled_pass_publishes_the_interrupt() { - use std::sync::{Arc, Mutex}; - let traces = Arc::new(Mutex::new(Vec::new())); - let seen = traces.clone(); - let mut h = - egui_kittest::Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1280.0, 800.0)).build_ui_state( - move |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - seen.lock().unwrap().push(( - app.ime_cancelled.is_some(), - app.ime_interrupt_pending, - app.ime_composition.is_none(), - ui.ctx().will_discard(), - )); - }, - SlideApp::new(Session::with_new(), Services::default()), - ); - h.run_steps(3); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.run_steps(2); - h.event(preedit("日本")); - h.run_steps(1); - traces.lock().unwrap().clear(); - - h.ctx.request_discard("discarded IME interrupt boundary"); - h.input_mut().events.push(Event::Key { key: egui::Key::End, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }); - h.input_mut().events.push(preedit("日本")); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("日本".into()))); - h.run_steps(1); - - let t = traces.lock().unwrap().clone(); - assert_eq!(t.len(), 2, "one discarded pass followed by the settled pass: {t:?}"); - assert!(t[0].0, "the discarded pass keeps the settled tombstone"); - assert!(t[0].1, "the interrupt stays pending through the discarded pass"); - assert!(t[0].2, "the stale pre-edit/commit cleared the tracked composition"); - assert!(t[0].3, "the first pass is discarded"); - assert!(!t[1].0, "the settled pass publishes the interrupt and retires the tombstone"); - assert!(!t[1].1); - assert!(!t[1].3); - assert_eq!(title_text(h.state()), "日本"); - assert!(h.output().platform_output.ime.as_ref().is_some_and(|ime| ime.should_interrupt_composition)); -} - -/// A settled composition whose descriptor was not painted leaves a tombstone. A *discarded* -/// pass keeps it (the platform has not been told to reset), but an accepted no-descriptor pass is -/// the backend's reset boundary: the tombstone must be retired there, or the first legitimate -/// commit into the next text target is lost. -#[test] -fn accepted_no_descriptor_pass_retires_the_settled_tombstone() { - use std::sync::{Arc, Mutex}; - - let mut app = SlideApp::new(Session::with_new(), Services::default()); - let ctx = egui::Context::default(); - let title = app.session.active().unwrap().doc.slides[0].shapes[0].id.0; - app.run("text.edit", json!({"id": title})).unwrap(); - let owner = app.ime_target().expect("the edited title is an IME target").owner; - let generation = 7; - app.ime_generation = generation; - app.ime_composition = Some(crate::ImeComposition { owner, generation, settled: true }); - app.ime_cancelled = Some(crate::ImeCancelled { owner, generation }); - app.ime_interrupt_pending = true; - app.ime_pending = None; - - let traces = Arc::new(Mutex::new(Vec::new())); - let seen = traces.clone(); - ctx.request_discard("no-descriptor IME boundary"); - ctx.run_ui(egui::RawInput::default(), |ui| { - let will_discard = ui.ctx().will_discard(); - app.ime_pending = None; - let _ = app.observe_ime(ui.ctx()); - seen.lock().unwrap().push((will_discard, app.ime_cancelled.is_some(), app.ime_interrupt_pending)); - }) - .drop_without_applying_deltas(); - - let t = traces.lock().unwrap().clone(); - assert_eq!(t.len(), 2, "one discarded pass then the accepted pass: {t:?}"); - assert!(t[0].0, "the first pass is discarded"); - assert!(t[0].1, "a discarded pass keeps the tombstone"); - assert!(t[0].2, "a discarded pass keeps the interrupt pending"); - assert!(!t[1].0, "the second pass is accepted"); - assert!(!t[1].1, "the accepted no-descriptor pass retires the tombstone"); - assert!(!t[1].2, "there is no descriptor to publish the interrupt in"); - assert!(app.ime_composition.is_none(), "the settled composition is retired with its tombstone"); - - // The next text target's first event is a legitimate direct commit, not the old generation. - app.ime_event(&ctx, &egui::ImeEvent::Commit("。".into())); - assert_eq!(title_text(&app), "。", "a first commit in the new target is not swallowed"); -} - -/// A focused stock `TextEdit` can publish its own `o.ime` while the canvas has no pending rect. -/// That descriptor is not a backend reset: the canvas tombstone and settled composition must -/// survive until an accepted pass really publishes no descriptor at all. -#[test] -fn focused_text_field_descriptor_keeps_the_settled_tombstone() { - let mut h = harness(Session::with_new()); - let notes = egui::Id::unique("notes_edit"); - h.ctx.memory_mut(|m| m.request_focus(notes)); - h.run_steps(2); - assert!(h.ctx.memory(|m| m.has_focus(notes)), "the notes TextEdit has focus"); - let owner = egui::Id::unique("old-canvas-ime"); - h.state_mut().ime_composition = Some(crate::ImeComposition { owner, generation: 7, settled: true }); - h.state_mut().ime_cancelled = Some(crate::ImeCancelled { owner, generation: 7 }); - h.state_mut().ime_interrupt_pending = true; - - h.run_steps(1); - assert!(h.output().platform_output.ime.is_some(), "the focused stock TextEdit publishes its own descriptor"); - assert!(h.state().ime_cancelled.is_some(), "a descriptor-publishing pass is not a reset"); - assert!(h.state().ime_interrupt_pending, "the canvas interrupt is still waiting for a reset pass"); - assert!(h.state().ime_composition.is_some_and(|c| c.settled), "the settled composition is not retired"); - - // With focus gone there is no canvas target and no TextEdit descriptor: this accepted pass - // is the backend reset boundary, so the tombstone and settled composition retire. - h.ctx.memory_mut(|m| m.surrender_focus(notes)); - h.run_steps(1); - assert!(h.output().platform_output.ime.is_none(), "nothing publishes an IME descriptor"); - assert!(h.state().ime_cancelled.is_none(), "the accepted no-descriptor pass retires the tombstone"); - assert!(!h.state().ime_interrupt_pending); - assert!(h.state().ime_composition.is_none(), "the settled composition retires with its tombstone"); -} - -/// Typing on a selected (not edited) shape with an input method replaces its text, as typing does; -/// the input method is on for it. -#[test] -fn composing_on_a_selected_shape_starts_editing_it() { - let mut h = harness(Session::with_new()); - let r = h.state_mut().run("shape.insert", json!({"preset": "rect", "rect": [100, 100, 200, 100], "text": "Old"})).unwrap(); - let id = r["id"].as_u64().unwrap(); - h.state_mut().run("text.exit", json!({})).unwrap(); - h.run_steps(2); - assert!(h.state().session.active().unwrap().selection.text.is_none()); - assert!(h.output().platform_output.ime.is_some(), "a selected shape takes typing"); - h.event(preedit("新")); - h.event(Event::Ime(ImeEvent::Commit("新しい".into()))); - h.run_steps(2); - let v = h.state_mut().session.execute("text.get", &json!({"id": id})).unwrap(); - assert_eq!(v["text"], "新しい"); -} - -/// The notes pane is an egui text field: composition shows in it and replaces each preedit, the -/// candidate window is at its caret, and the notes are one undo step when it loses focus. -#[test] -fn korean_composes_in_the_notes_pane() { - let mut h = harness(Session::with_new()); - let id = egui::Id::unique("notes_edit"); - h.ctx.memory_mut(|m| m.request_focus(id)); - h.run_steps(2); - assert!(h.ctx.memory(|m| m.has_focus(id))); - let undo0 = undo_len(h.state()); - for pre in ["ㄴ", "노", "놑", "노트"] { - h.event(preedit(pre)); - h.run_steps(1); - assert_eq!(h.state().notes_buf.2.text, pre, "the preedit replaces the last one"); - } - let ime = h.output().platform_output.ime.as_ref().expect("the notes field turns the input method on"); - let slide = h.state().slide_rect.unwrap(); - assert!(ime.cursor_rect.min.y > slide.max.y, "candidate window at the notes caret, under the slide"); - h.event(Event::Ime(ImeEvent::Commit("노트".into()))); - h.run_steps(1); - assert_eq!(h.state().notes_buf.2.text, "노트"); - // Focus leaves the field (Escape): the notes are committed as one step. - h.key_press(egui::Key::Escape); - h.run_steps(2); - let notes = h.state().session.active().unwrap().doc.slides[0].notes_text(); - assert_eq!(notes, "노트"); - assert_eq!(undo_len(h.state()), undo0 + 1); - assert!(h.ctx.fonts_mut(|f| f.has_glyphs(&FontId::proportional(13.0), "노트")) || !system_has("노트")); - - // Composing, then going to another slide: the notes stay with the slide they were typed for. - h.state_mut().run("slide.new", json!({})).unwrap(); - h.state_mut().run("slide.go", json!({"index": 0})).unwrap(); - h.run_steps(2); - h.ctx.memory_mut(|m| m.request_focus(id)); - h.run_steps(2); - h.event(Event::Key { key: egui::Key::End, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }); - h.event(preedit("ㅇ")); - h.event(Event::Ime(ImeEvent::Commit("요".into()))); - h.run_steps(1); - h.state_mut().run("slide.go", json!({"index": 1})).unwrap(); - h.run_steps(2); - let d = h.state().session.active().unwrap(); - assert_eq!(d.doc.slides[0].notes_text(), "노트요"); - assert_eq!(d.doc.slides[1].notes_text(), ""); -} - -/// Does some font on this machine (embedded or installed) draw every letter of `s`? Machines -/// without a Korean or Chinese font (a bare Linux runner) can't draw it in the interface either. -fn system_has(s: &str) -> bool { - s.chars().filter(|c| !c.is_whitespace()).all(|c| deckcraft_fonts::FontDb::global().fallback_for(c, u32::MAX).is_some_and(|f| !f.is_color())) -} - -/// Assert that both interface faces draw every non-space character of `text`; `painted` describes -/// the sample in a failure message. -fn assert_faces_draw(h: &egui_kittest::Harness<'_, SlideApp>, text: &str, painted: &str) { - for family in [FontId::proportional(13.0), crate::theme::bold(13.0)] { - let missing: String = text.chars().filter(|c| !c.is_whitespace() && !h.ctx.fonts_mut(|f| f.has_glyph(&family, *c))).collect(); - assert!(missing.is_empty(), "{family:?} draws {missing:?} of {painted} as boxes"); - } -} - -/// #101: a Korean file name, title, notes and comments, a Japanese slide and a Chinese section are -/// drawn with glyphs in the interface (title bar, outline, notes pane, comments), not boxes: faces -/// that draw them are borrowed from the font database. A Latin presentation borrows nothing. -#[test] -fn cjk_text_in_the_interface_is_drawn_with_real_glyphs() { - let h = harness(Session::with_new()); - assert!(h.state().ui_fonts.faces.is_empty(), "nothing to borrow for {:?}", h.state().session.active().unwrap().title()); - - let mut s = Session::with_new(); - let korean = "한국어 발표 자료"; - let japanese = "日本語のスライド"; - let chinese = "简体中文演示文稿"; - let notes = "발표자 노트입니다"; - let require_all = option_env!("CRAFT_FONTS_REQUIRED").is_some() || deckcraft_fonts::CRAFT_FONTS.iter().any(|f| f.family == "LXGW WenKai Lite"); - // The title slide's title and subtitle are painted by the initial Normal view, under - // kittest's strict missing-glyph policy. Pre-paint CJK only when this build is required to - // carry it or this machine can draw every initial sample; an optional build without those - // fonts must skip before that first paint instead of panicking and only then checking. - let initial_cjk = require_all || [chinese, japanese, korean].iter().all(|t| system_has(t)); - let slide = s.doc().unwrap().current_slide().unwrap(); - let title = slide.shapes[0].id.0; - let body = slide.shapes[1].id.0; - if initial_cjk { - s.execute("text.set", &json!({"id": title, "text": chinese})).unwrap(); - s.execute("text.set", &json!({"id": body, "text": japanese})).unwrap(); - s.execute("slide.notes", &json!({"text": notes})).unwrap(); - s.execute("section.add", &json!({"name": chinese})).unwrap(); - s.doc_mut().unwrap().path = Some(format!("{korean}.pptx")); - } - let mut h = harness(s); - if initial_cjk { - // `harness` already completed its first passes. Both initially painted samples must have - // real glyph coverage before any command (and the strict policy would have panicked - // otherwise). - let initial: Vec = h.state().session.active().unwrap().doc.slides[0] - .shapes - .iter() - .take(2) - .map(|sh| sh.text.as_ref().map(|t| t.paragraphs.iter().map(|p| p.text()).collect::>().join("\n")).unwrap_or_default()) - .collect(); - assert_eq!(initial, [chinese.to_owned(), japanese.to_owned()]); - for text in [chinese, japanese] { - assert_faces_draw(&h, text, &format!("initially painted {text:?}")); - } - } else { - eprintln!("optional font input: initial CJK paint skipped before layout (no complete local coverage)"); - // Each sample this machine can draw is still painted for real after the check; the - // strict policy then checks it. Unsupported samples stay out of the document entirely. - if system_has(chinese) { - h.state_mut().run("text.set", json!({"id": title, "text": chinese})).unwrap(); - h.state_mut().run("section.add", json!({"name": chinese})).unwrap(); - } - if system_has(japanese) { - h.state_mut().run("text.set", json!({"id": body, "text": japanese})).unwrap(); - } - if system_has(korean) { - h.state_mut().run("slide.notes", json!({"text": notes})).unwrap(); - h.state_mut().session.doc_mut().unwrap().path = Some(format!("{korean}.pptx")); - } - if system_has(chinese) || system_has(japanese) || system_has(korean) { - h.run_steps(3); - } - } - // Outline and file-name text is painted only after this command; the Chinese title above has - // already covered the initial-paint case. - h.state_mut().run("view.outline", json!({})).unwrap(); - h.run_steps(3); - assert!(!initial_cjk || h.state().session.active().unwrap().title().contains(korean)); - let mut checked = 0; - for text in [korean, japanese, chinese, notes] { - if !system_has(text) { - assert!(!require_all, "required font input does not draw {text:?}"); - eprintln!("skipped {text:?}: no font on this machine draws it"); - continue; - } - assert_faces_draw(&h, text, &format!("{text:?}")); - checked += 1; - } - if require_all || cfg!(windows) || cfg!(target_os = "macos") { - assert_eq!(checked, 4, "all CJK samples must be exercised with required/bundled fonts"); - } - // Text typed later (a dialog field, a new comment) is looked at too. Never type text this - // machine cannot draw: the strict missing-glyph policy would panic before the optional check. - let typed = "ไทย"; - if system_has(typed) { - h.event(Event::Text(typed.into())); - h.run_steps(2); - assert!(h.ctx.fonts_mut(|f| f.has_glyphs(&FontId::proportional(13.0), typed))); - } else if require_all { - panic!("required font input does not draw {typed:?}"); - } else { - eprintln!("skipped {typed:?}: no font on this machine draws it"); - } -} - -/// An input method can ask for characters (stock `DeleteSurrounding`) or UTF-8 bytes (the fork's -/// `DeleteSurroundingBytes`) around the caret to be removed. The byte range never splits a -/// character, and a deletion made while composing stays in the composition's one undo step. -#[test] -fn ime_delete_surrounding_handles_chars_bytes_and_composition_undo() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.insert", &json!({"text": "abc"})).unwrap(); - h.run_steps(2); - h.event(Event::Ime(ImeEvent::DeleteSurrounding { before_chars: 2, after_chars: 0 })); - h.run_steps(1); - assert_eq!(title_text(h.state()), "a"); - let deleted = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(deleted.change_cause, egui::output::ImeChangeCause::InputMethod, "an accepted deletion is an IME mutation"); - h.state_mut().session.execute("edit.undo", &json!({})).unwrap(); - h.run_steps(1); - assert_eq!(title_text(h.state()), "abc", "a non-composing deletion is one undo step"); - - // UTF-8 bytes: the four bytes of an emoji are one character and must delete whole. - h.state_mut().session.execute("text.set", &json!({"id": title, "text": "aé😀"})).unwrap(); - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.move", &json!({"to": "end"})).unwrap(); - h.run_steps(2); - h.event(Event::Ime(ImeEvent::DeleteSurroundingBytes { before_bytes: 4, after_bytes: 0 })); - h.run_steps(2); - assert_eq!(title_text(h.state()), "aé", "the emoji's bytes delete exactly one scalar"); - - // Deleting before a composition, then committing, is a single undo step. - h.state_mut().session.execute("text.set", &json!({"id": title, "text": "abc"})).unwrap(); - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.run_steps(2); - let undo0 = undo_len(h.state()); - h.event(preedit("日本")); - h.run_steps(1); - h.event(Event::Ime(ImeEvent::DeleteSurroundingBytes { before_bytes: 1, after_bytes: 0 })); - h.run_steps(1); - assert_eq!(title_text(h.state()), "ab日本"); - h.event(Event::Ime(ImeEvent::Commit("日本".into()))); - h.run_steps(2); - assert_eq!(title_text(h.state()), "ab日本"); - assert_eq!(undo_len(h.state()), undo0 + 1, "delete + commit is one composition step"); - h.state_mut().session.execute("edit.undo", &json!({})).unwrap(); - h.run_steps(1); - assert_eq!(title_text(h.state()), "abc"); -} - -/// The canvas producer publishes bounded logical committed text with UTF-8 byte offsets and a -/// stable owner/generation across ordinary typing, caret movement and reversed selection. -#[test] -fn ime_output_is_logical_bounded_and_owner_stable() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.insert", &json!({"text": "aé😀b"})).unwrap(); - h.run_steps(2); - let first = h.output().platform_output.ime.clone().expect("editing text owns the input method"); - assert_eq!(first.purpose, egui::IMEPurpose::Normal); - assert_eq!(first.change_cause, egui::output::ImeChangeCause::Other); - let payload = first.surrounding_text.available().expect("model text is available"); - assert_eq!((payload.text.as_str(), payload.cursor, payload.anchor), ("aé😀b", 8, 8)); - let (owner, generation) = (first.owner, first.context_generation); - - // A caret move is not a new context and still reports logical UTF-8 offsets. - h.state_mut().session.execute("text.select", &json!({"anchor": [0, 2], "caret": [0, 2]})).unwrap(); - h.run_steps(1); - let moved = h.output().platform_output.ime.clone().unwrap(); - assert_eq!((moved.owner, moved.context_generation), (owner, generation)); - let payload = moved.surrounding_text.available().unwrap(); - assert_eq!((payload.cursor, payload.anchor), (3, 3)); - - // A reversed selection keeps caret < anchor in the outgoing bytes. - h.state_mut().session.execute("text.select", &json!({"anchor": [0, 3], "caret": [0, 1]})).unwrap(); - h.run_steps(1); - let reversed = h.output().platform_output.ime.clone().unwrap(); - assert_eq!((reversed.owner, reversed.context_generation), (owner, generation)); - let payload = reversed.surrounding_text.available().unwrap(); - assert_eq!((payload.cursor, payload.anchor), (1, 7), "caret and anchor keep their direction"); - - // A forced extra pass in the same frame keeps the same context. - h.ctx.request_discard("ime multipass regression"); - h.run_steps(1); - let multipass = h.output().platform_output.ime.clone().unwrap(); - assert_eq!((multipass.owner, multipass.context_generation), (owner, generation)); - - // The extra window renders the slide and owns no text: whether the backend draws it as its - // own native viewport or (as in kittest, which installs no immediate-viewport renderer) - // embedded in this pass, it must neither own nor disturb the editor's context. - h.state_mut().run("view.newWindow", json!({"on": true})).unwrap(); - h.run_steps(2); - let second_window = h.output().platform_output.ime.clone().unwrap(); - assert_eq!((second_window.owner, second_window.context_generation), (owner, generation)); - h.state_mut().run("view.newWindow", json!({"on": false})).unwrap(); -} - -/// A model-stored composition is pre-edit, not committed text. An accepted commit changes the -/// committed snapshot and is the only path that earns `InputMethod`. -#[test] -fn preedit_is_excluded_and_a_commit_is_input_method() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.insert", &json!({"text": "ab"})).unwrap(); - h.run_steps(2); - h.event(preedit("日本")); - h.run_steps(1); - let composing = h.output().platform_output.ime.clone().unwrap(); - let payload = composing.surrounding_text.available().unwrap(); - assert_eq!((payload.text.as_str(), payload.cursor, payload.anchor), ("ab", 2, 2), "pre-edit is not committed text"); - assert_eq!(composing.change_cause, egui::output::ImeChangeCause::Other); - - h.event(Event::Ime(ImeEvent::Commit("日本".into()))); - h.run_steps(1); - let committed = h.output().platform_output.ime.clone().unwrap(); - let payload = committed.surrounding_text.available().unwrap(); - assert_eq!(payload.text, "ab日本"); - assert_eq!((payload.cursor, payload.anchor), (8, 8)); - assert_eq!(committed.change_cause, egui::output::ImeChangeCause::InputMethod); - - // A pre-edit and its commit in one frame is still one accepted IME mutation. `Harness::event` - // queues one frame per event, so put both in a single RawInput. - h.state_mut().session.execute("text.insert", &json!({"text": "X"})).unwrap(); - h.run_steps(1); - h.input_mut().events.push(preedit("Y")); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("Y".into()))); - h.run_steps(1); - let same_frame = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(title_text(h.state()), "ab日本XY"); - assert_eq!(same_frame.change_cause, egui::output::ImeChangeCause::InputMethod); -} - -/// An application edit anywhere in the frame dominates an IME commit in that same frame. -#[test] -fn mixed_application_and_ime_edits_report_other() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.insert", &json!({"text": "a"})).unwrap(); - h.run_steps(2); - // Both events belong to one pass. `Harness::event` queues one frame per event, so put them - // in a single RawInput instead. - h.input_mut().events.push(Event::Text("x".into())); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("y".into()))); - h.run_steps(1); - let ime = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(title_text(h.state()), "axy"); - assert_eq!(ime.change_cause, egui::output::ImeChangeCause::Other); - let payload = ime.surrounding_text.available().unwrap(); - assert_eq!(payload.text, "axy"); -} - -/// An empty commit is a no-op: it must not claim an IME mutation. An empty body is still an -/// available surrounding context, not `Unavailable`. -#[test] -fn no_op_commit_stays_other_and_empty_text_is_available() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.run_steps(1); - let empty = h.output().platform_output.ime.clone().unwrap(); - let payload = empty.surrounding_text.available().expect("an empty editable body is available"); - assert_eq!((payload.text.as_str(), payload.cursor, payload.anchor), ("", 0, 0)); - - h.event(Event::Ime(ImeEvent::Commit(String::new()))); - h.run_steps(1); - let no_op = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(no_op.change_cause, egui::output::ImeChangeCause::Other); - assert!(no_op.surrounding_text.available().is_some_and(|p| p.text.is_empty())); -} - -/// A no-op delete is not a mutation: a real commit in the same `RawInput` is still an accepted -/// IME edit, not `Other` caused by a poisoned frame. -#[test] -fn no_op_delete_does_not_poison_a_commit_in_the_same_frame() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.insert", &json!({"text": "abc"})).unwrap(); - h.run_steps(2); - - h.input_mut().events.push(Event::Ime(ImeEvent::DeleteSurrounding { before_chars: 0, after_chars: 0 })); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("X".into()))); - h.run_steps(1); - assert_eq!(title_text(h.state()), "abcX"); - let ime = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(ime.change_cause, egui::output::ImeChangeCause::InputMethod, "the no-op did not poison the real commit"); -} - -/// An empty commit is likewise a no-op; a real commit later in the same frame remains the -/// accepted input-method mutation. -#[test] -fn empty_commit_does_not_poison_a_commit_in_the_same_frame() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.insert", &json!({"text": "ab"})).unwrap(); - h.run_steps(2); - - h.input_mut().events.push(Event::Ime(ImeEvent::Commit(String::new()))); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("Y".into()))); - h.run_steps(1); - assert_eq!(title_text(h.state()), "abY"); - let ime = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(ime.change_cause, egui::output::ImeChangeCause::InputMethod, "the empty commit did not poison the real commit"); -} - -/// A selection wider than the surrounding-text budget is published as `Unavailable`. A real -/// deletion from that state must still be certified through the unavailable revision, including -/// when the selection stays unavailable afterwards. -#[test] -fn wide_selection_delete_is_certified_with_the_unavailable_revision() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.set", &json!({"id": title, "text": "a".repeat(4500)})).unwrap(); - h.state_mut().session.execute("text.select", &json!({"anchor": [0, 1], "caret": [0, 4500]})).unwrap(); - h.run_steps(2); - let before = h.output().platform_output.ime.clone().unwrap(); - assert!(before.surrounding_text.available().is_none(), "the wide selection is unavailable"); - - h.input_mut().events.push(Event::Ime(ImeEvent::DeleteSurrounding { before_chars: 1, after_chars: 0 })); - h.run_steps(1); - assert_eq!(title_text(h.state()).len(), 4499, "one character before the selection was deleted"); - let after = h.output().platform_output.ime.clone().unwrap(); - assert!(after.surrounding_text.available().is_none(), "the selection is still wider than the budget"); - assert_eq!(after.change_cause, egui::output::ImeChangeCause::InputMethod, "the unavailable revision certifies the deletion"); -} - -/// A commit that replaces a wide (unavailable) selection produces available text; the mixed -/// unavailable -> available transition needs the before revision to be certified. -#[test] -fn wide_selection_commit_is_certified_with_the_unavailable_revision() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.state_mut().session.execute("text.set", &json!({"id": title, "text": "a".repeat(4500)})).unwrap(); - h.state_mut().session.execute("text.select", &json!({"anchor": [0, 1], "caret": [0, 4500]})).unwrap(); - h.run_steps(2); - assert!(h.output().platform_output.ime.as_ref().unwrap().surrounding_text.available().is_none()); - - h.event(Event::Ime(ImeEvent::Commit("Y".into()))); - h.run_steps(1); - assert_eq!(title_text(h.state()), "aY", "the selected tail is replaced"); - let ime = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(ime.surrounding_text.available().unwrap().text, "aY"); - assert_eq!(ime.change_cause, egui::output::ImeChangeCause::InputMethod, "the unavailable revision certifies the commit"); -} - -/// The surrounding window is bounded even in a large body, and switching the edited target -/// starts a new owner/generation once. -#[test] -fn surrounding_text_is_bounded_and_target_replacement_resets_generation() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - let long = "a".repeat(4500); - h.state_mut().session.execute("text.set", &json!({"id": title, "text": long})).unwrap(); - h.state_mut().session.execute("text.move", &json!({"to": "end"})).unwrap(); - h.run_steps(2); - let ime = h.output().platform_output.ime.clone().unwrap(); - let payload = ime.surrounding_text.available().unwrap(); - assert!(payload.text.len() <= 4000, "{}", payload.text.len()); - assert_eq!(payload.cursor, payload.text.len()); - let first = (ime.owner, ime.context_generation); - - // A selection wider than the protocol bound is explicitly unavailable, not truncated. - h.state_mut().session.execute("text.selectAll", &json!({})).unwrap(); - h.run_steps(1); - let wide = h.output().platform_output.ime.clone().unwrap(); - assert!(wide.surrounding_text.available().is_none(), "oversized selection is Unavailable"); - - h.state_mut().run("text.exit", json!({})).unwrap(); - let r = h.state_mut().run("shape.insert", json!({"preset": "rect", "rect": [20, 20, 200, 80], "text": "other"})).unwrap(); - let other = r["id"].as_u64().unwrap(); - h.state_mut().run("text.edit", json!({"id": other})).unwrap(); - h.run_steps(2); - let ime = h.output().platform_output.ime.clone().unwrap(); - assert_ne!((ime.owner, ime.context_generation), first, "a new target is a new context"); - let payload = ime.surrounding_text.available().unwrap(); - assert_eq!((payload.text.as_str(), payload.cursor, payload.anchor), ("other", 5, 5)); -} - -/// With no target, the custom owner is hidden: it observes `None` and publishes no descriptor. -#[test] -fn hidden_canvas_owner_observes_none() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.run_steps(1); - let first = h.output().platform_output.ime.clone().unwrap(); - h.state_mut().run("text.exit", json!({})).unwrap(); - h.state_mut().run("edit.select", json!({"ids": []})).unwrap(); - h.run_steps(1); - assert!(h.output().platform_output.ime.is_none(), "nothing to type into: no custom owner"); - - // Re-focusing the same shape starts one new generation after the hidden pass. - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.run_steps(1); - let again = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(again.owner, first.owner); - assert_ne!(again.context_generation, first.context_generation); -} - -/// A platform pre-edit or commit queued in the same pass as the application settling the -/// composition (a plain click on another shape) must not be typed into the new target: the -/// settled text stays in the body it was composed in, and the platform's copy is interrupted. -/// Once that interrupt is published, an event the OS still queues is indistinguishable from a -/// legitimate new composition (egui's event payload has no generation), so only the settling -/// batch can be rejected deterministically. -/// -/// The pre-edit is plain ASCII on purpose: borrowing a CJK face installs fonts and discards the -/// pass, which would hide the one pass the interruption is published in. -#[test] -fn a_settling_batch_cannot_land_an_ime_event_in_the_next_target() { - let mut h = harness(Session::with_new()); - let a = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - let r = h.state_mut().run("shape.insert", json!({"preset": "rect", "rect": [400, 400, 240, 120], "text": "Confidential draft"})).unwrap(); - let b = r["id"].as_u64().unwrap() as u32; - h.state_mut().run("text.exit", json!({})).unwrap(); - h.state_mut().session.execute("text.set", &json!({"id": a, "text": "Quarterly results"})).unwrap(); - h.state_mut().run("text.edit", json!({"id": a})).unwrap(); - h.run_steps(2); - - // An input-method pre-edit in A. - h.event(preedit("nihon")); - h.run_steps(2); - assert!(h.state().session.active().unwrap().composition.is_some()); - - // A plain press on B settles the composition (PowerPoint does the same) and selects B. Its - // queued pre-edit and commit travel in the same input batch as the settling pass. - let press = deckcraft_engine::tools::PointerEvent { kind: deckcraft_engine::tools::PointerKind::Down, x: 500.0, y: 450.0, ..Default::default() }; - h.state_mut().session.pointer(press).unwrap(); - h.input_mut().events.push(preedit("nihon")); - h.input_mut().events.push(Event::Ime(ImeEvent::Commit("nihon".into()))); - h.run_steps(1); - let st = h.state().session.active().unwrap(); - assert!(st.composition.is_none(), "the click settles the composition"); - assert_eq!(st.selection.shapes, vec![deckcraft_model::ShapeId(b)], "B is the new target"); - assert!(st.selection.text.is_none(), "the queued IME events did not start editing B"); - assert_eq!(text_of(&h, a), "Quarterly resultsnihon", "the settled pre-edit stays in A"); - assert_eq!(text_of(&h, b), "Confidential draft", "B's whole text is not replaced"); - let ime = h.output().platform_output.ime.clone().expect("B is a typing target"); - assert!(ime.should_interrupt_composition, "the platform's copy is cancelled, not committed back"); - assert!(h.state().ime_cancelled.is_none(), "the settled pass published the interrupt boundary"); -} - -/// The extra document window is a rendered image, not a second text target: the canvas owner -/// stays in the editing viewport, and closing the last presentation really releases it. -#[test] -fn a_second_window_keeps_the_canvas_owner_and_closing_the_last_document_tears_it_down() { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.run_steps(1); - let first = h.output().platform_output.ime.clone().unwrap(); - assert_eq!(h.state().ime_viewport, Some(egui::ViewportId::ROOT), "the canvas owner lives in the editing viewport"); - - h.state_mut().run("view.newWindow", json!({"on": true})).unwrap(); - h.run_steps(2); - let second = h.output().platform_output.ime.clone().expect("the canvas still owns the input method"); - assert_eq!( - (second.owner, second.context_generation), - (first.owner, first.context_generation), - "the render-only window neither owns nor disturbs the input method" - ); - assert_eq!(h.state().ime_viewport, Some(egui::ViewportId::ROOT)); - h.state_mut().run("view.newWindow", json!({"on": false})).unwrap(); - h.run_steps(1); - - h.state_mut().run("file.close", json!({})).unwrap(); - h.run_steps(1); - assert!(h.state().session.active().is_none(), "the last presentation closed"); - assert_eq!(h.state().ime_viewport, None, "its viewport's IME state is released"); - assert!(h.output().platform_output.ime.is_none()); -} - -/// The text of the shape `id` in the active presentation. -fn text_of(h: &egui_kittest::Harness<'static, SlideApp>, id: u32) -> String { - h.state() - .session - .active() - .and_then(|d| d.shape(deckcraft_model::ShapeId(id))) - .and_then(|sh| sh.text.as_ref()) - .map(deckcraft_model::text::TextBody::text) - .unwrap_or_default() -} - -/// Open the title editor on `abcd`, select the text, and return the caret point used for -/// pointer interruption. -fn pending_terminal_editor() -> (egui_kittest::Harness<'static, SlideApp>, egui::Pos2) { - let mut h = harness(Session::with_new()); - let title = h.state().session.active().unwrap().doc.slides[0].shapes[0].id.0; - h.state_mut().run("text.edit", json!({"id": title})).unwrap(); - h.event(Event::Text("abcd".into())); - h.run_steps(1); - h.state_mut().run("text.select", json!({"anchor": [0, 1], "caret": [0, 1]})).unwrap(); - h.run_steps(1); - let point = h.output().platform_output.ime.as_ref().expect("the actual canvas caret1").cursor_rect.center(); - assert!(h.state().canvas_rect.unwrap().contains(point)); - h.state_mut().run("text.select", json!({"anchor": [0, 4], "caret": [0, 4]})).unwrap(); - h.run_steps(1); - assert_eq!(title_text(h.state()), "abcd"); - (h, point) -} - -/// Clear a pending pre-edit and assert that the visible text and undo length are unchanged and -/// no platform interrupt was requested. -fn clear_pending_preedit(h: &mut egui_kittest::Harness<'_, SlideApp>) { ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 let undo = undo_len(h.state()); let converted = "日本ご"; h.event(Event::Ime(ImeEvent::Preedit { text: converted.into(), active_range_chars: Some(2..3) })); diff --git a/crates/ui-egui/src/last_color_tests.rs b/crates/ui-egui/src/last_color_tests.rs index 519d985ad..594e94efb 100644 --- a/crates/ui-egui/src/last_color_tests.rs +++ b/crates/ui-egui/src/last_color_tests.rs @@ -24,20 +24,8 @@ fn harness(tab: &str) -> (Harness<'static, SlideApp>, [ShapeId; 2]) { s.execute("shape.fill", &json!({"color": "#FF0000"})).unwrap(); s.execute("shape.line", &json!({"color": "#0000FF", "width": 3})).unwrap(); s.execute("selection.select", &json!({"ids": [ids[0].0]})).unwrap(); -<<<<<<< HEAD let mut h = crate::test_harness::harness_with(s, Services::default(), Harness::builder().with_size(egui::vec2(1800.0, 900.0)), |_| {}); h.state_mut().ui.tab = tab.into(); -======= - let mut app = SlideApp::new(s, Services::default()); - app.ui.tab = tab.into(); - let mut h = Harness::builder().with_context_setup(crate::framework::install_headless).with_size(egui::vec2(1800.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); ->>>>>>> b6dd921b46498082f4f451673ff694ee83413c08 h.run_steps(3); (h, ids) }