diff --git a/crates/ui-egui/src/dialogs/artboard_options.rs b/crates/ui-egui/src/dialogs/artboard_options.rs index 2965adaae6..3da5adc1bf 100644 --- a/crates/ui-egui/src/dialogs/artboard_options.rs +++ b/crates/ui-egui/src/dialogs/artboard_options.rs @@ -706,9 +706,8 @@ mod tests { use vectorcraft_engine::Session; /// An app with one 200 × 150 artboard on a window with a dialog host. - // PLAN: assumed `VectorcraftApp::new` gives `dialogs()` a host; otherwise the shared test app of the dialogs tests. fn app() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 200, "height": 150})).unwrap(); app } diff --git a/crates/ui-egui/src/dialogs/char_style_options/tests.rs b/crates/ui-egui/src/dialogs/char_style_options/tests.rs index 49fc0f9ff0..d6c278790d 100644 --- a/crates/ui-egui/src/dialogs/char_style_options/tests.rs +++ b/crates/ui-egui/src/dialogs/char_style_options/tests.rs @@ -12,7 +12,7 @@ type Existing = CharStyleOptions; type Fresh = NewTextStyle; fn app() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); app } diff --git a/crates/ui-egui/src/dialogs/flare_options.rs b/crates/ui-egui/src/dialogs/flare_options.rs index 76f8f699d6..6b1d6770cd 100644 --- a/crates/ui-egui/src/dialogs/flare_options.rs +++ b/crates/ui-egui/src/dialogs/flare_options.rs @@ -305,7 +305,7 @@ mod tests { use vectorcraft_engine::doc::NodeKind; fn app() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 600, "height": 600})).unwrap(); app } diff --git a/crates/ui-egui/src/dialogs/graph_data.rs b/crates/ui-egui/src/dialogs/graph_data.rs index 49a494fe89..5f32f1780f 100644 --- a/crates/ui-egui/src/dialogs/graph_data.rs +++ b/crates/ui-egui/src/dialogs/graph_data.rs @@ -778,7 +778,7 @@ mod tests { } fn app_with(csv: &str, ty: &str) -> (VectorcraftApp, u64) { - let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default())); app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); let id = app.run("graph.create", json!({"type": ty, "x": 0, "y": 0, "width": 200, "height": 150, "csv": csv})).unwrap()["id"].as_u64().unwrap(); diff --git a/crates/ui-egui/src/dialogs/object_mosaic.rs b/crates/ui-egui/src/dialogs/object_mosaic.rs index c30387542a..e5c2b82042 100644 --- a/crates/ui-egui/src/dialogs/object_mosaic.rs +++ b/crates/ui-egui/src/dialogs/object_mosaic.rs @@ -552,7 +552,7 @@ mod tests { /// An app with a 100 × 50 pt embedded image selected. fn app_with_image() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 400, "height": 400})).unwrap(); app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 100, "height": 50})).unwrap(); app.run("paint.setStroke", json!({"none": true})).unwrap(); diff --git a/crates/ui-egui/src/dialogs/para_style_options/tests.rs b/crates/ui-egui/src/dialogs/para_style_options/tests.rs index 7f61a586ac..82680b0eec 100644 --- a/crates/ui-egui/src/dialogs/para_style_options/tests.rs +++ b/crates/ui-egui/src/dialogs/para_style_options/tests.rs @@ -6,7 +6,7 @@ use vectorcraft_engine::Session; use vectorcraft_engine::doc::{Composer, NodeId, NodeKind, ParaStyle}; fn app() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); app } diff --git a/crates/ui-egui/src/dialogs/relink.rs b/crates/ui-egui/src/dialogs/relink.rs index dada9ff696..1f855684b8 100644 --- a/crates/ui-egui/src/dialogs/relink.rs +++ b/crates/ui-egui/src/dialogs/relink.rs @@ -339,7 +339,7 @@ mod tests { for n in names { std::fs::write(dir.join(n), png([200, 0, 0])).unwrap(); } - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.services.read = Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string()))); app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); (app, dir) @@ -363,7 +363,6 @@ mod tests { p.to_string_lossy().into_owned() } - // PLAN: assumed `app.ui_ctx` readable from tests (the window's context). fn ctx(app: &VectorcraftApp) -> egui::Context { app.ui_ctx.clone().expect("a window") } diff --git a/crates/ui-egui/src/dialogs/symbolism_options.rs b/crates/ui-egui/src/dialogs/symbolism_options.rs index af4fc5efc7..7cfe2649ec 100644 --- a/crates/ui-egui/src/dialogs/symbolism_options.rs +++ b/crates/ui-egui/src/dialogs/symbolism_options.rs @@ -136,7 +136,7 @@ mod tests { use vectorcraft_engine::Session; fn app() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); app } diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index 2dfd0c2dca..1f8f0825dd 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -11,14 +11,7 @@ use crate::i18n::LangExt as _; /// The window the tests draw in. pub(super) const SCREEN: egui::Vec2 = egui::vec2(1600.0, 1100.0); -/// `app` shown in a window of its own: its context is the one every frame of the test runs on, so focus and drags last -/// from frame to frame, and the access tree is on for the tests that find a control by its role. -pub(super) fn window(mut app: VectorcraftApp) -> VectorcraftApp { - let ctx = crate::testing::ui_context(); - ctx.enable_accesskit(); - app.ui_ctx = Some(ctx); - app -} +pub(super) use crate::testing::windowed as window; pub(super) fn app() -> VectorcraftApp { let mut app = window(VectorcraftApp::new(Session::new(), Default::default())); diff --git a/crates/ui-egui/src/dialogs/tests_warp.rs b/crates/ui-egui/src/dialogs/tests_warp.rs index 8796f410f6..47860ad577 100644 --- a/crates/ui-egui/src/dialogs/tests_warp.rs +++ b/crates/ui-egui/src/dialogs/tests_warp.rs @@ -8,11 +8,7 @@ use vectorcraft_engine::Session; use crate::VectorcraftApp; -/// `app` with a window, so its dialogs open on the host. -pub(super) fn windowed(mut app: VectorcraftApp) -> VectorcraftApp { - app.ui_ctx = Some(crate::testing::ui_context()); - app -} +pub(super) use crate::testing::windowed; fn app() -> (VectorcraftApp, NodeId) { let mut app = windowed(VectorcraftApp::new(Session::new(), Default::default())); diff --git a/crates/ui-egui/src/dialogs/width_point/tests.rs b/crates/ui-egui/src/dialogs/width_point/tests.rs index 01f47134fd..9e9d404ab8 100644 --- a/crates/ui-egui/src/dialogs/width_point/tests.rs +++ b/crates/ui-egui/src/dialogs/width_point/tests.rs @@ -5,7 +5,7 @@ use vectorcraft_tools::{PointerEvent, PointerKind}; /// A 10 pt line from (100, 150) to (300, 150) with a 4 + 4 pt width point in the middle. fn app() -> (VectorcraftApp, u64) { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); let id = app.run("shape.line", json!({"x1": 100, "y1": 150, "x2": 300, "y2": 150})).unwrap()["id"].as_u64().unwrap(); app.run("stroke.set", json!({"ids": [id], "weight": 10})).unwrap(); diff --git a/crates/ui-egui/src/panels/actions/tests_support.rs b/crates/ui-egui/src/panels/actions/tests_support.rs index 7f2ff68ab2..1401496765 100644 --- a/crates/ui-egui/src/panels/actions/tests_support.rs +++ b/crates/ui-egui/src/panels/actions/tests_support.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use std::sync::Arc; use craft::automation::actions::{Action, ActionList, ActionStep}; -use craft::host::{Host, Picked, ScriptedFiles}; +use craft::host::{Picked, ScriptedFiles}; use craft::ui::dialog::{DialogHost, HeldOk, StackDialog}; use serde_json::{Value, json}; use vectorcraft_engine::Session; @@ -119,11 +119,8 @@ pub(crate) fn saved_sets(app: &VectorcraftApp) -> Value { } /// Puts `picks` in place of the file service of `app`'s window. -fn install_picks(app: &VectorcraftApp, picks: ScriptedFiles) { - let ctx = app.ui_ctx.clone().expect("a test app has a window"); - // PLAN: assumed, as `tests::picks::scripted` (files-w7), that the app's context carries its host (hub-w1). - let host = Host::try_of_ctx(&ctx).expect("the app's context carries its host"); - host.with_files(Arc::new(picks)).install(&ctx); +fn install_picks(app: &mut VectorcraftApp, picks: ScriptedFiles) { + crate::tests::picks::install_files(app, Arc::new(picks)); } /// The most file dialogs [`with_files`] answers in one test. diff --git a/crates/ui-egui/src/panels/artboards/tests.rs b/crates/ui-egui/src/panels/artboards/tests.rs index 69b0b0b56f..93fba977a3 100644 --- a/crates/ui-egui/src/panels/artboards/tests.rs +++ b/crates/ui-egui/src/panels/artboards/tests.rs @@ -156,7 +156,7 @@ fn list_events_and_menu_rows_reach_their_commands() { /// and an explicit artboard still wins. #[test] fn all_on_active_artboard_takes_the_active_artboard() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 100, "height": 100, "units": "Points", "artboards": 2})).unwrap(); let mut rect = |x| app.session.execute("shape.rectangle", &json!({"x": x, "y": 10, "width": 20, "height": 20})).unwrap()["id"].clone(); let (a, b) = (rect(10), rect(130)); @@ -178,7 +178,7 @@ fn all_on_active_artboard_takes_the_active_artboard() { #[test] fn fit_to_artwork_bounds_and_selected_art_resize_the_active_artboard() { for id in ["artboard.fitToArt", "artboard.fitToSelection"] { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 100, "height": 100, "units": "Points", "artboards": 2})).unwrap(); // Partly on artboard 1 and partly on artboard 2. app.session.execute("shape.rectangle", &json!({"x": 90, "y": 10, "width": 60, "height": 30})).unwrap(); @@ -197,7 +197,7 @@ fn fit_to_artwork_bounds_and_selected_art_resize_the_active_artboard() { /// Bounds fits each of them to the art on it and leaves artboard 2 as it was. #[test] fn fit_to_artwork_bounds_fits_each_selected_artboard_to_its_own_art() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 100, "height": 100, "units": "Points", "artboards": 3})).unwrap(); for (x, h) in [(10, 30), (130, 20), (250, 40)] { app.session.execute("shape.rectangle", &json!({"x": x, "y": 10, "width": 20, "height": h})).unwrap(); @@ -219,7 +219,7 @@ fn fit_to_artwork_bounds_fits_each_selected_artboard_to_its_own_art() { /// as it was. #[test] fn a_batchs_fit_to_artwork_bounds_step_fits_each_selected_artboard() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 100, "height": 100, "units": "Points", "artboards": 3})).unwrap(); for (x, h) in [(10, 30), (130, 20), (250, 40)] { app.session.execute("shape.rectangle", &json!({"x": x, "y": 10, "width": 20, "height": h})).unwrap(); @@ -268,7 +268,7 @@ fn shift_clicking_rows_selects_several_artboards() { /// order, in one undo step. With one artboard selected, Rename gives it the name as typed. #[test] fn the_panel_menus_rename_numbers_several_selected_artboards() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap(); for x in [400, 800, 1200] { app.session.execute("artboard.new", &json!({"x": x, "y": 0, "width": 200, "height": 150})).unwrap(); @@ -296,7 +296,7 @@ fn the_panel_menus_rename_numbers_several_selected_artboards() { /// that artboard, not the active one. #[test] fn the_panel_menus_rename_opens_on_a_selected_artboard() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 200, "height": 150, "artboards": 2})).unwrap(); app.select_tool("artboard"); select(&mut app, 1); @@ -314,7 +314,7 @@ fn the_panel_menus_rename_opens_on_a_selected_artboard() { /// one the tool then has active. #[test] fn paste_and_cut_with_the_artboard_tool_make_its_artboard_active() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 200, "height": 150, "artboards": 3})).unwrap(); app.select_tool("artboard"); select(&mut app, 1); @@ -334,7 +334,7 @@ fn paste_and_cut_with_the_artboard_tool_make_its_artboard_active() { /// selected, on the active one. #[test] fn in_place_pastes_put_a_copy_on_each_artboard_the_artboard_tool_selects() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 200, "height": 150, "artboards": 3})).unwrap(); let boards: Vec<_> = app.session.active().unwrap().doc.artboards.iter().map(|a| a.rect.origin()).collect(); let r = app.run("shape.rectangle", json!({"x": boards[0].x + 10.0, "y": boards[0].y + 20.0, "width": 5, "height": 5})).unwrap()["id"].clone(); @@ -359,7 +359,7 @@ fn in_place_pastes_put_a_copy_on_each_artboard_the_artboard_tool_selects() { /// then has active the active one. #[test] fn the_artboard_tools_options_make_its_artboard_active() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 200, "height": 150, "artboards": 3})).unwrap(); app.select_tool("artboard"); app.run("tool.setOption", json!({"key": "selected", "value": [2, 0]})).unwrap(); @@ -373,7 +373,7 @@ fn the_artboard_tools_options_make_its_artboard_active() { /// tool's artboards keeps the active artboard, and Copy and Paste make the pasted one active. #[test] fn a_batch_in_one_document_makes_the_artboard_tools_artboard_active() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 200, "height": 150, "artboards": 3})).unwrap(); app.select_tool("artboard"); select(&mut app, 1); @@ -389,7 +389,7 @@ fn a_batch_in_one_document_makes_the_artboard_tools_artboard_active() { /// switches to the tool's, as choosing the document's tab does. #[test] fn switching_documents_with_the_artboard_tool_keeps_the_active_artboard() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 200, "height": 150, "artboards": 3})).unwrap(); app.select_tool("artboard"); select(&mut app, 2); @@ -404,7 +404,7 @@ fn switching_documents_with_the_artboard_tool_keeps_the_active_artboard() { /// tool's artboard 1 makes the new first artboard active, as Cut on its own makes it. #[test] fn a_batch_that_switches_documents_and_back_keeps_the_active_artboard() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 200, "height": 150, "artboards": 3})).unwrap(); app.run("file.new", json!({"width": 200, "height": 150, "artboards": 2})).unwrap(); app.run("document.activate", json!({"index": 0})).unwrap(); @@ -430,7 +430,7 @@ fn a_batch_that_switches_documents_and_back_keeps_the_active_artboard() { /// artboard and for the row's artboard, and leave the tool as it is. #[test] fn the_panel_menus_artboard_options_opens_the_active_artboards_options() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap(); app.session.execute("artboard.new", &json!({"x": 400, "y": 300, "width": 100, "height": 50})).unwrap(); select(&mut app, 1); @@ -454,7 +454,7 @@ fn the_panel_menus_artboard_options_opens_the_active_artboards_options() { /// active artboard's copy active. #[test] fn the_panel_menus_duplicate_artboards_copies_every_selected_artboard() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap(); for x in [400, 800] { app.session.execute("artboard.new", &json!({"x": x, "y": 0, "width": 200, "height": 150})).unwrap(); @@ -481,7 +481,7 @@ fn the_panel_menus_duplicate_artboards_copies_every_selected_artboard() { /// one selected. #[test] fn the_panel_menus_new_artboard_makes_the_new_artboard_active() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 200, "height": 150, "artboards": 2})).unwrap(); app.view_mut().unwrap().artboard = 0; run(&mut app, "ui.artboards.new", &json!({})).unwrap().unwrap(); @@ -507,7 +507,7 @@ fn the_panel_menus_new_artboard_makes_the_new_artboard_active() { /// rectangles, in one undo step, as Object › Artboards › Convert to Artboards does. #[test] fn the_panel_menus_convert_to_artboards_converts_the_selected_objects() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap(); for x in [10, 60] { app.session.execute("shape.rectangle", &json!({"x": x, "y": 10, "width": 20, "height": 30})).unwrap(); @@ -538,7 +538,7 @@ fn boards(app: &VectorcraftApp) -> (Vec, usize, Vec>(); let run = |app: &mut VectorcraftApp, menu: &str, label: &str| { @@ -818,7 +818,7 @@ fn the_artboard_tools_context_menu_locks_and_unlocks_artboards() { /// A document of `boards` artboards of 100 × 50 pt with the Artboard tool chosen. fn menu_app(boards: usize) -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.session.execute("file.new", &json!({"width": 100, "height": 50, "units": "Points", "artboards": boards})).unwrap(); app.select_tool("artboard"); app @@ -1189,6 +1189,6 @@ fn select_all_artboards_chooses_the_tool_and_needs_a_document() { app.select_tool("selection"); assert_eq!(app.run("artboard.selectAll", json!({})).unwrap()["selected"], json!([0, 1])); assert_eq!(app.session.tool_id(), "artboard"); - let mut empty = VectorcraftApp::new(Session::new(), Default::default()); + let mut empty = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); assert_eq!(empty.run("artboard.selectAll", json!({})).unwrap_err(), "no document"); } diff --git a/crates/ui-egui/src/panels/color_guide.rs b/crates/ui-egui/src/panels/color_guide.rs index de1cd96657..1561d21524 100644 --- a/crates/ui-egui/src/panels/color_guide.rs +++ b/crates/ui-egui/src/panels/color_guide.rs @@ -802,7 +802,7 @@ mod tests { use vectorcraft_engine::Session; fn app() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); app } diff --git a/crates/ui-egui/src/panels/symbols/tests.rs b/crates/ui-egui/src/panels/symbols/tests.rs index 01ce66cc37..1c2a9f979f 100644 --- a/crates/ui-egui/src/panels/symbols/tests.rs +++ b/crates/ui-egui/src/panels/symbols/tests.rs @@ -129,11 +129,7 @@ fn window(app: &VectorcraftApp) -> egui::Context { app.ui_ctx.clone().expect("the app has a window") } -/// `app` with a window for its dialogs, as its first frame gives it one. -fn windowed(mut app: VectorcraftApp) -> VectorcraftApp { - app.ui_ctx = Some(crate::testing::ui_context()); - app -} +use crate::testing::windowed; /// The dialog on top of the app's window: its id, its key and its fields, as automation reads them. fn top(app: &VectorcraftApp) -> Option<(DialogId, String, Value)> { diff --git a/crates/ui-egui/src/panels/tests_appearance.rs b/crates/ui-egui/src/panels/tests_appearance.rs index 6f2b0b27ae..b27f306dd3 100644 --- a/crates/ui-egui/src/panels/tests_appearance.rs +++ b/crates/ui-egui/src/panels/tests_appearance.rs @@ -12,7 +12,7 @@ use crate::tests::panel_harness::Panel; use crate::tests::synthetic::key_frame; pub(super) fn app_with_rect() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); run(&mut app, "file.new", json!({"width": 200, "height": 200})); let id = run(&mut app, "shape.rectangle", json!({"x": 10, "y": 10, "width": 100, "height": 100}))["id"].clone(); run(&mut app, "select.set", json!({ "ids": [id] })); @@ -411,7 +411,7 @@ fn effect_rows_dropped_on_delete_or_duplicate() { /// A row dropped on something that is not a button changes nothing either, and the next drop still works. #[test] fn contents_rows_and_drops_elsewhere_change_nothing() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); run(&mut app, "file.new", json!({"width": 100, "height": 100})); let a = run(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 20, "height": 20}))["id"].clone(); let b = run(&mut app, "shape.rectangle", json!({"x": 30, "y": 0, "width": 20, "height": 20}))["id"].clone(); @@ -690,7 +690,7 @@ fn transform_effect_preview_commit_cancel_and_undo_cover_artwork_targets() { |image: &Image| (0..image.width).rev().find(|&x| (0..image.height).any(|y| image.over_white(x, y).iter().any(|&c| c < 245))).unwrap(); for kind in ["object", "fill", "stroke", "group", "layer", "text", "image"] { for preview in [true, false] { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); match kind { "text" => { @@ -825,7 +825,7 @@ fn fill_and_stroke_labels_are_links_and_their_empty_space_only_highlights() { #[test] fn after_a_contents_click_delete_removes_nothing() { let group = || { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); run(&mut app, "file.new", json!({"width": 100, "height": 100})); let a = run(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 20, "height": 20}))["id"].clone(); let b = run(&mut app, "shape.rectangle", json!({"x": 30, "y": 0, "width": 20, "height": 20}))["id"].clone(); @@ -835,7 +835,7 @@ fn after_a_contents_click_delete_removes_nothing() { app }; let type_object = || { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); run(&mut app, "file.new", json!({"width": 100, "height": 100})); let t = run(&mut app, "text.create", json!({"x": 10, "y": 50, "text": "Hi"}))["id"].clone(); run(&mut app, "select.set", json!({"ids": [t]})); @@ -925,7 +925,7 @@ fn a_row_link_to_a_panel_in_sight_opens_no_popup() { /// "row link to popup": on a type object "Characters" is a link to the Character panel. #[test] fn characters_opens_the_character_panel() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); run(&mut app, "file.new", json!({"width": 100, "height": 100})); let t = run(&mut app, "text.create", json!({"x": 0, "y": 60, "text": "Hi"}))["id"].clone(); run(&mut app, "select.set", json!({"ids": [t]})); @@ -1024,7 +1024,7 @@ fn a_drop_on_delete_above_the_active_effect_keeps_the_highlight_on_its_rows() { /// group too, not a copy of it; nothing with nothing selected or no document open. #[test] fn first_selected_is_the_node_the_document_holds() { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); assert!(first_selected(&app).is_none(), "no document"); run(&mut app, "file.new", json!({"width": 200, "height": 200})); let a = run(&mut app, "shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50}))["id"].clone(); diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index 1e1d8a2a30..b6a757b731 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -63,9 +63,12 @@ fn idle(app: &mut VectorcraftApp, ctx: &egui::Context, n: usize) { } } +/// An app with a 200 × 200 document whose window has drawn its first frame, which builds the keymap the shortcut +/// commands edit. fn new_app() -> VectorcraftApp { let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap(); + ready(&mut app); app } @@ -73,6 +76,7 @@ fn app_with_a_selected_rectangle() -> VectorcraftApp { let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 30})).unwrap(); + ready(&mut app); app } diff --git a/crates/ui-egui/src/testing.rs b/crates/ui-egui/src/testing.rs index dd28fe0289..c1cbeca4ee 100644 --- a/crates/ui-egui/src/testing.rs +++ b/crates/ui-egui/src/testing.rs @@ -16,6 +16,16 @@ pub(crate) fn install(ctx: &egui::Context) { set_input(ctx, FrameInput::new(crate::app::root_env(&vectorcraft_engine::Prefs::default(), 1.0))); } +/// `app` shown in a window of its own: its context is the one every frame of the test runs on, so its dialogs open on +/// the window's host, focus and drags last from frame to frame, and the access tree is on for the tests that find a +/// control by its role. +pub(crate) fn windowed(mut app: crate::VectorcraftApp) -> crate::VectorcraftApp { + let ctx = ui_context(); + ctx.enable_accesskit(); + app.ui_ctx = Some(ctx); + app +} + /// A context with the runtime, the app's interface fonts and its root theme installed. pub(crate) fn ui_context() -> egui::Context { let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/tests/picks.rs b/crates/ui-egui/src/tests/picks.rs index 277b2b330c..33c961f389 100644 --- a/crates/ui-egui/src/tests/picks.rs +++ b/crates/ui-egui/src/tests/picks.rs @@ -64,10 +64,8 @@ pub(crate) fn scripted_sheets(app: &mut VectorcraftApp, on: bool) -> Picker { /// [`scripted`] with `files` as the app's file service: the app's host carries it, and so does the /// window's context, as a frame installs the app's host there. fn scripted_files(app: &mut VectorcraftApp, files: ScriptedFiles) -> Picker { - let ctx = app.ui_ctx.get_or_insert_with(crate::testing::ui_context).clone(); let files = Arc::new(files); - app.host = Arc::new(app.host.with_files(files.clone())); - Host::clone(&app.host).install(&ctx); + install_files(app, files.clone()); let written = Rc::new(RefCell::new(Vec::new())); let w = written.clone(); app.services.read.get_or_insert_with(|| Box::new(|_: &str| Ok(SVG.to_vec()))); @@ -80,6 +78,14 @@ fn scripted_files(app: &mut VectorcraftApp, files: ScriptedFiles) -> Picker { Picker { files, written } } +/// Makes `files` the file service of `app`'s host and of its window's context, as a frame installs the app's host +/// there; an app without a window gets one. +pub(crate) fn install_files(app: &mut VectorcraftApp, files: Arc) { + let ctx = app.ui_ctx.get_or_insert_with(crate::testing::ui_context).clone(); + app.host = Arc::new(app.host.with_files(files)); + Host::clone(&app.host).install(&ctx); +} + /// Run what the frame runs for the picks: their continuations, then the saves. pub(crate) fn poll(app: &mut VectorcraftApp, ctx: &egui::Context) { file_asks::poll(app); diff --git a/crates/ui-egui/src/toolbar/tests.rs b/crates/ui-egui/src/toolbar/tests.rs index 385ea3b12c..db47acbcf3 100644 --- a/crates/ui-egui/src/toolbar/tests.rs +++ b/crates/ui-egui/src/toolbar/tests.rs @@ -76,11 +76,7 @@ fn cells(app: &VectorcraftApp, ctx: &egui::Context, nodes: &[Node]) -> Vec VectorcraftApp { - app.ui_ctx = Some(crate::testing::ui_context()); - app -} +use crate::testing::windowed; /// The open tool-options dialog: its id and the fields automation reads. fn tool_dialog(app: &VectorcraftApp) -> Option<(DialogId, serde_json::Value)> {