From f0964d3c0c2dd60fd0eaeb8a3e08d6941e4c8ce2 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 21:31:41 +0700 Subject: [PATCH] Run the chrome, palette, menus, document window and unsaved tests in the app's window with its frame input --- crates/ui-egui/src/chrome/tests.rs | 14 +++++++------- crates/ui-egui/src/doc_windows/tests.rs | 10 ++++------ crates/ui-egui/src/menus/tests.rs | 2 +- crates/ui-egui/src/palette.rs | 16 ++++++++++------ crates/ui-egui/src/unsaved.rs | 3 +-- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 01f04cfac8..be6392e421 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -34,6 +34,8 @@ impl Shown { (*draw)(&mut shown.borrow_mut(), ui); }); fixture.room(room); + // The fixture's context is the app's window, as a host's is. + app.borrow_mut().ui_ctx = Some(fixture.ctx().clone()); Shown { fixture, app, draw } } @@ -56,6 +58,7 @@ impl Shown { /// One frame with `events`, then the commands it fired. fn frame(&mut self, events: Vec) -> &mut Self { + self.run_fired(); self.fixture.frame(events); self.run_fired(); self @@ -63,19 +66,16 @@ impl Shown { /// Frames with no events until the chrome is at rest, then the commands they fired. fn settle(&mut self) -> &mut Self { + self.run_fired(); self.fixture.settle(); self.run_fired(); self } - /// Runs the commands the frames since the last call fired, as the window runs them. + /// Runs the commands the frames since the last call fired, as the window runs them, and gives the fixture the + /// app's input for the next frame. fn run_fired(&mut self) { - let ctx = self.fixture.ctx().clone(); - let fired = craft::ui::runtime::frame::take_output(&ctx).fired; - let mut app = self.app.borrow_mut(); - for one in &fired { - crate::shortcuts::run_fired(&mut app, &ctx, one); - } + crate::testing::fixture_input(&mut self.app.borrow_mut(), &mut self.fixture); } /// Moves the fixture's clock on by `seconds` before the next frame. diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 255252d44e..887cb15def 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -14,8 +14,8 @@ fn app_with(n: usize) -> VectorcraftApp { } /// One headless frame of the canvas panel's body (the tabs and the canvas or panes) on a -/// 1200 × 800 window, then the floating document windows, which egui draws inside the window → -/// the shapes it drew, `Shape::Vec`s flattened. +/// 1200 × 800 window, then the floating document windows, which egui draws inside the window, run +/// as the hosts run a frame → the shapes it drew, `Shape::Vec`s flattened. fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) -> Vec { fn flat(s: Shape, out: &mut Vec) { match s { @@ -29,11 +29,10 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec events, ..Default::default() }; - let mut out = ctx.run_ui(raw, |ui| { + let out = crate::testing::part_frame(app, ctx, raw, |app, ui| { app.canvas_area(ui); show(app, ui); }); - out.textures_delta.clear(); let mut shapes = vec![]; out.shapes.into_iter().for_each(|c| flat(c.shape, &mut shapes)); shapes @@ -868,11 +867,10 @@ fn app_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec VectorcraftApp { - let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default())); app.run("file.new", json!({})).unwrap(); app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); app diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 4e571d2f15..753953ef2a 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -757,11 +757,12 @@ mod tests { use crate::i18n::LangExt as _; - /// An app over `session` with its menu model built, in English. + /// An app over `session` in a window of its own with its menu model built, in English. fn app_on(session: Session) -> VectorcraftApp { crate::i18n::set_current(Lang::EN); - let mut app = VectorcraftApp::new(session, crate::Services::default()); - crate::menus::model::refresh(&mut app, &crate::testing::ui_context()); + let mut app = crate::testing::windowed(VectorcraftApp::new(session, crate::Services::default())); + let ctx = app.ui_ctx.clone().unwrap(); + crate::menus::model::refresh(&mut app, &ctx); app } @@ -774,7 +775,8 @@ mod tests { /// A pick of result `id`: the command its entry runs ([`crate::keymap::command_of`]), fired /// from the palette. fn pick(app: &mut VectorcraftApp, id: &str) { - fire(app, &crate::testing::ui_context(), crate::keymap::command_of(id), FireSource::Palette); + let ctx = app.ui_ctx.clone().unwrap(); + fire(app, &ctx, crate::keymap::command_of(id), FireSource::Palette); } /// Cancels, or confirms, every open dialog. @@ -1081,7 +1083,8 @@ mod tests { let before = outcome(&picked); pick(&mut picked, id); if row.is_enabled() { - fire(&mut clicked, &crate::testing::ui_context(), item.clone(), FireSource::Menu); + let window = clicked.ui_ctx.clone().unwrap(); + fire(&mut clicked, &window, item.clone(), FireSource::Menu); assert_eq!(outcome(&picked), outcome(&clicked), "{id} [state {n}]"); compared += 1; } else { @@ -1743,7 +1746,8 @@ mod tests { let before = outcome(&picked); pick(&mut picked, shadow); let click = CommandRef::with_params(item.command, json!({ "effect": item.effect })); - fire(&mut clicked, &crate::testing::ui_context(), click, FireSource::Menu); + let window = clicked.ui_ctx.clone().unwrap(); + fire(&mut clicked, &window, click, FireSource::Menu); let after = outcome(&picked); assert!(after.0, "the dialog opens: {}", after.2); assert_eq!(after.1, before.1, "nothing changes yet"); diff --git a/crates/ui-egui/src/unsaved.rs b/crates/ui-egui/src/unsaved.rs index 163bf26a07..b6a3c5dfb2 100644 --- a/crates/ui-egui/src/unsaved.rs +++ b/crates/ui-egui/src/unsaved.rs @@ -249,8 +249,7 @@ fn advance(app: &mut VectorcraftApp, mut closing: Closing, mut step: GuardStep egui::Context { let ctx = crate::testing::ui_context(); - let mut out = ctx.run_ui(egui::RawInput::default(), |ui| app.ui(ui)); - out.textures_delta.clear(); + crate::testing::app_frame(app, &ctx, egui::RawInput::default()); ctx }