Give tests that open dialogs or edit shortcuts the app's window

Dialogs now open on the window's dialog host and the shortcut commands edit the
keymap the window builds in its first frame, so a test app needs a window. One
helper, testing::windowed, gives it one (the dialogs tests' window and three
copies of it now use it); the dialog, artboard and appearance tests that built
a window-less app use it, the shortcut tests' apps draw their first frame, and
the actions tests install their scripted files on the app's host the way the
picks tests do.
This commit is contained in:
bflatastic
2026-11-22 17:58:48 +07:00
parent 881efe891b
commit 4a565baf0c
20 changed files with 75 additions and 79 deletions
@@ -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
}
@@ -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
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -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();
@@ -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
}
+1 -2
View File
@@ -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")
}
@@ -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
}
+1 -8
View File
@@ -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()));
+1 -5
View File
@@ -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()));
@@ -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();
@@ -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.
+28 -28
View File
@@ -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<vectorcraft_geom::Rect>, usize, Vec<Stri
/// step: about its center, and from its top-left corner once the top-left point is chosen.
#[test]
fn the_control_bar_resizes_the_active_artboard_about_the_reference_point() {
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": 100, "units": "Points", "artboards": 2})).unwrap();
app.select_tool("artboard");
select(&mut app, 1);
@@ -567,7 +567,7 @@ fn the_control_bar_resizes_the_active_artboard_about_the_reference_point() {
/// selected.
#[test]
fn choosing_the_artboard_tool_starts_it_on_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": 200, "height": 150})).unwrap();
for x in [400, 800] {
app.session.execute("artboard.new", &json!({"x": x, "y": 0, "width": 200, "height": 150})).unwrap();
@@ -598,7 +598,7 @@ fn choosing_the_artboard_tool_starts_it_on_the_active_artboard() {
/// active artboard; a plain New adds an empty one.
#[test]
fn dragging_a_row_onto_new_artboard_duplicates_it() {
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("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
apply(&mut app, vec![PageListEvent::new_row(Some(0), false)]);
@@ -648,7 +648,7 @@ fn the_row_menus_rename_opens_the_rename_dialog_for_the_selected_artboards() {
/// becomes the active one; a locked artboard can be renamed too.
#[test]
fn the_row_menu_renames_the_right_clicked_artboard_with_any_tool() {
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": 3})).unwrap();
app.session.execute("artboard.setProps", &json!({"index": 2, "locked": true})).unwrap();
select(&mut app, 0);
@@ -667,7 +667,7 @@ fn the_row_menu_renames_the_right_clicked_artboard_with_any_tool() {
/// locked artboard.
#[test]
fn the_lock_column_locks_and_unlocks_an_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();
app.session.execute("artboard.new", &json!({"x": 400, "y": 0, "width": 200, "height": 150})).unwrap();
select(&mut app, 1);
@@ -688,7 +688,7 @@ fn the_lock_column_locks_and_unlocks_an_artboard() {
/// refuses the change. A name typed for them goes to the locked one too.
#[test]
fn a_new_size_for_the_selected_artboards_leaves_a_locked_one() {
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();
@@ -713,7 +713,7 @@ fn a_new_size_for_the_selected_artboards_leaves_a_locked_one() {
/// step and makes it the active one.
#[test]
fn alt_clicking_new_artboard_opens_artboard_options_for_the_new_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();
app.session.execute("artboard.new", &json!({"x": 400, "y": 300, "width": 100, "height": 50})).unwrap();
select(&mut app, 0);
@@ -752,7 +752,7 @@ fn alt_clicking_new_artboard_opens_artboard_options_for_the_new_artboard() {
/// artboard its default name, and with the Artboard tool in use the tool moves to the new artboard.
#[test]
fn new_artboard_options_with_an_empty_name_add_the_default_name() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
let ctx = crate::testing::ui_context();
assert!(app.run("ui.newArtboard", json!({})).is_err(), "no document");
app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap();
@@ -769,7 +769,7 @@ fn new_artboard_options_with_an_empty_name_add_the_default_name() {
/// left active.
#[test]
fn delete_empty_artboards_deletes_the_empty_ones_and_selects_one_left() {
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();
for x in [400, 800] {
app.run("artboard.new", json!({"x": x, "y": 0, "width": 200, "height": 150})).unwrap();
@@ -793,7 +793,7 @@ fn delete_empty_artboards_deletes_the_empty_ones_and_selects_one_left() {
/// locks the selected one (the others stay free), Unlock All frees every artboard.
#[test]
fn the_artboard_tools_context_menu_locks_and_unlocks_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": 100, "height": 100, "units": "Points", "artboards": 3})).unwrap();
let locked = |app: &VectorcraftApp| app.session.active().unwrap().doc.artboards.iter().map(|a| a.locked).collect::<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");
}
+1 -1
View File
@@ -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
}
+1 -5
View File
@@ -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)> {
@@ -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();
+4
View File
@@ -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
}
+10
View File
@@ -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();
+9 -3
View File
@@ -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<ScriptedFiles>) {
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);
+1 -5
View File
@@ -76,11 +76,7 @@ fn cells(app: &VectorcraftApp, ctx: &egui::Context, nodes: &[Node]) -> Vec<egui:
found
}
/// `app` with a window to host its dialogs in.
fn windowed(mut app: VectorcraftApp) -> 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)> {