Run the chrome, palette, menus, document window and unsaved tests in the app's window with its frame input

This commit is contained in:
bflatastic
2026-11-22 21:31:41 +07:00
parent 6411453ed5
commit f0964d3c0c
5 changed files with 23 additions and 22 deletions
+7 -7
View File
@@ -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<egui::Event>) -> &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.
+4 -6
View File
@@ -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<egui::Event>) -> Vec<Shape> {
fn flat(s: Shape, out: &mut Vec<Shape>) {
match s {
@@ -29,11 +29,10 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>
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<egui::Ev
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();
out.platform_output.cursor_icon
}
+1 -1
View File
@@ -892,7 +892,7 @@ fn edit_views_opens_its_dialog_on_the_saved_views() {
}
fn app_with_a_rectangle() -> 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
+10 -6
View File
@@ -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");
+1 -2
View File
@@ -249,8 +249,7 @@ fn advance(app: &mut VectorcraftApp, mut closing: Closing, mut step: GuardStep<u
#[cfg(test)]
pub(crate) fn ready_for_test(app: &mut VectorcraftApp) -> 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
}