mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 19:51:26 -05:00
Give tests that open dialogs or click by name the shared windowed app
This commit is contained in:
@@ -8,8 +8,7 @@ use crate::{VectorcraftApp, menus};
|
||||
|
||||
/// An app with a window, where its dialogs open, and two rectangles without a stroke, both selected.
|
||||
fn app() -> (VectorcraftApp, NodeId, NodeId) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("paint.setStroke", json!({"none": true})).unwrap();
|
||||
let mut rect = |x, y, w, h| NodeId(app.run("shape.rectangle", json!({"x": x, "y": y, "width": w, "height": h})).unwrap()["id"].as_u64().unwrap());
|
||||
|
||||
@@ -228,8 +228,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn find_nearest_swatch_lists_the_matches_and_applies_the_nearest() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
let ctx = app.ui_ctx.clone().expect("the test context");
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("swatch.new", json!({"name": "Brand", "color": "#ff8000", "global": true})).unwrap();
|
||||
|
||||
@@ -4,13 +4,13 @@ use vectorcraft_engine::Session;
|
||||
use super::{ADJUSTMENTS, Picked};
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
/// An app with a selected red rectangle.
|
||||
/// An app in a window with a selected red rectangle.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#ff0000"})).unwrap();
|
||||
app
|
||||
crate::testing::windowed(app)
|
||||
}
|
||||
|
||||
/// The fields of the hosted dialog open on top and its id.
|
||||
@@ -62,7 +62,7 @@ fn every_adjustment_offered_is_a_colour_adjustment_with_its_defaults() {
|
||||
#[test]
|
||||
fn the_halftone_effect_dialog_has_the_command_fields_and_edits_the_effect() {
|
||||
let mut app = app();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
open(&mut app, &ctx, json!({"effect": "addon.color.halftone"}));
|
||||
let (_, fields) = top(&app);
|
||||
let shown: std::collections::BTreeSet<&str> = fields.as_object().unwrap().keys().map(String::as_str).collect();
|
||||
@@ -84,7 +84,7 @@ fn the_halftone_effect_dialog_has_the_command_fields_and_edits_the_effect() {
|
||||
#[test]
|
||||
fn the_duotone_dialog_has_a_row_per_tone_and_the_curve_of_one() {
|
||||
let mut app = app();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
app.run("swatch.new", json!({"name": "Ink", "color": "#e07020", "spot": true})).unwrap();
|
||||
open(&mut app, &ctx, json!({"effect": "addon.color.duotone"}));
|
||||
assert!(app.session.in_interaction(), "the preview runs");
|
||||
|
||||
@@ -22,8 +22,7 @@ struct Row {
|
||||
}
|
||||
|
||||
fn new_app(width: u32, height: u32) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": width, "height": height})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ fn x0(app: &VectorcraftApp, i: usize) -> f64 {
|
||||
}
|
||||
|
||||
fn new_app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 600, "height": 400})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -58,8 +58,7 @@ fn app() -> VectorcraftApp {
|
||||
.map(|__b| png.extend_from_slice(&__b))
|
||||
}
|
||||
.unwrap();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("document.open", json!({"name": "art.png", "dataBase64": vectorcraft_format::base64_encode(&png)})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app
|
||||
|
||||
@@ -85,8 +85,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn constant_gap_shows_the_gap_and_bridges_many_circles_within_reach() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
// Three circles 4 apart in a row and one far off.
|
||||
let ids: Vec<u64> = [100.0, 124.0, 148.0, 300.0].iter().map(|&x| circle(&mut app, x, 10.0)).collect();
|
||||
|
||||
@@ -86,8 +86,7 @@ mod tests {
|
||||
|
||||
/// A window's app with a document and the closed path through `anchors` selected; the path's id.
|
||||
fn selected_path(anchors: serde_json::Value) -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
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("path.create", json!({"anchors": anchors, "closed": true})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
|
||||
@@ -89,8 +89,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn tangent_circle_previews_picks_one_cancels_and_runs_on_ok() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let a = circle(&mut app, 100.0, 100.0, 10.0);
|
||||
let b = circle(&mut app, 130.0, 100.0, 10.0);
|
||||
|
||||
@@ -15,9 +15,7 @@ fn app() -> VectorcraftApp {
|
||||
|
||||
/// An app with a window, which the dialogs open in.
|
||||
fn app_with_window() -> VectorcraftApp {
|
||||
let mut app = app();
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(app())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -8,9 +8,7 @@ use crate::{VectorcraftApp, menus};
|
||||
|
||||
/// An app with the window the dialogs open in.
|
||||
pub(super) fn new_app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
/// The window context of `app`.
|
||||
|
||||
@@ -6,8 +6,7 @@ use crate::addons::dialogs::tests::{dialog_id, frame, open_item, read, set};
|
||||
|
||||
/// A window's app with one type object, selected.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
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("text.create", json!({"x": 40, "y": 100, "text": "abc", "size": 20})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
|
||||
@@ -755,8 +755,7 @@ fn the_method_table_routes_each_method_and_checks_its_params() {
|
||||
assert!(r["error"].as_str().is_some_and(|e| e.contains(&format!("`{key}`"))), "{method} {params}: {r}");
|
||||
assert_eq!((app.ui.view.rulers, app.ui.view.grid, app.ui.control_bar), before, "{method} {params}: nothing is set");
|
||||
}
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
@@ -1025,8 +1024,7 @@ fn held_cmd_click(then: &str) {
|
||||
#[test]
|
||||
fn menu_dialogs_open_after_a_merge_on_another_thread() {
|
||||
for route in ["menu", "ui.menuDialog", "app dialog from the menu", "app dialog from a panel"] {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services::default()));
|
||||
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
|
||||
for k in 0..40 {
|
||||
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
@@ -1115,7 +1113,7 @@ fn save_and_close_apply_a_merge_on_another_thread_first() {
|
||||
let dir = crate::tests_folder::Folder::adopt(vectorcraft_testkit::temp_dir("control-merge-save"));
|
||||
for then in ["file.saveAs", "file.exportAs", "file.close"] {
|
||||
let services = Services { write: Some(Box::new(|p: &str, b: &[u8]| std::fs::write(p, b).map_err(|e| e.to_string()))), ..Default::default() };
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
|
||||
for k in 0..40 {
|
||||
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
|
||||
@@ -421,8 +421,7 @@ mod tests {
|
||||
|
||||
/// An app with one set holding `steps` as the action "Draw", and a window to show dialogs in.
|
||||
fn app_with(steps: Vec<ActionStep>) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.ui.actions = Default::default();
|
||||
app.ui.actions.push(Action { set: Some("Test".into()), ..Action::new("Draw", steps) }).unwrap();
|
||||
app
|
||||
|
||||
@@ -164,7 +164,7 @@ mod tests {
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context()); // PLAN: assumed path of sh.SH4
|
||||
app = crate::testing::windowed(app); // PLAN: assumed path of sh.SH4
|
||||
app
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@ use super::*;
|
||||
|
||||
/// An app with a window context for the dialog host and no document.
|
||||
pub(in crate::dialogs) fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
/// Answers the open question `D` the way its button does (`Some(choice)`: the button of that choice,
|
||||
|
||||
@@ -4,8 +4,7 @@ use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDia
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -561,8 +561,7 @@ mod tests {
|
||||
|
||||
/// A selected area type object with two paragraphs, in an app with a window for its dialogs.
|
||||
fn app() -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 10, "text": "One\nTwo", "area": {"width": 200, "height": 100}})).unwrap()["id"]
|
||||
.as_u64()
|
||||
|
||||
@@ -458,9 +458,7 @@ mod tests {
|
||||
|
||||
/// An app with a window context, so a dialog can open.
|
||||
fn windowed() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
fn id_of(app: &VectorcraftApp) -> DialogId {
|
||||
|
||||
@@ -8,8 +8,7 @@ use super::*;
|
||||
use crate::tests::picks::{poll, scripted};
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ mod tests {
|
||||
/// A selected 100 pt live square at (100, 100).
|
||||
fn app() -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context()); // PLAN: assumed path of sh.SH4
|
||||
app = crate::testing::windowed(app); // PLAN: assumed path of sh.SH4
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
(app, id)
|
||||
|
||||
@@ -35,8 +35,7 @@ mod tests {
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
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();
|
||||
for n in ["Logo", "Icons", "Text"] {
|
||||
@@ -123,8 +122,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn it_needs_a_saved_selection() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()));
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
assert!(super::open(&mut app).is_err());
|
||||
assert!(!app.any_dialog_open());
|
||||
|
||||
@@ -453,8 +453,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -212,9 +212,7 @@ mod tests {
|
||||
use vectorcraft_engine::doc::NodeKind;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
fn ctx(app: &VectorcraftApp) -> egui::Context {
|
||||
|
||||
@@ -146,8 +146,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn the_trees_set_the_options() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
open(&mut app);
|
||||
// A branch's box sets the flags under it; a mixed branch shows a dash.
|
||||
let mut apply = field_of(&app, KIND, "apply");
|
||||
|
||||
@@ -322,8 +322,7 @@ mod tests {
|
||||
|
||||
/// A document with a half-transparent red square over a blue one, both selected.
|
||||
fn scene() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
for (x, color) in [(10, "#0000ff"), (60, "#ff0000")] {
|
||||
let id = app.run("shape.rectangle", json!({"x": x, "y": x, "width": 100, "height": 100})).unwrap()["id"].clone();
|
||||
|
||||
@@ -119,9 +119,7 @@ mod tests {
|
||||
|
||||
/// An app with a window, whose dialog host the manager opens on.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
fn ctx(app: &VectorcraftApp) -> egui::Context {
|
||||
|
||||
@@ -3,8 +3,7 @@ use craft::ui::dialog::DialogId;
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -505,8 +505,7 @@ mod tests {
|
||||
/// A rectangle with a three-stop gradient from (100, 150) to (200, 150), the Gradient tool
|
||||
/// and stop 1 selected, in an app with the window context that hosts the popover.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap();
|
||||
let stops = json!([{"offset": 0, "color": "#ffffff"}, {"offset": 0.5, "color": "#00ff00"}, {"offset": 1, "color": "#000000"}]);
|
||||
|
||||
@@ -1072,8 +1072,7 @@ mod tests {
|
||||
/// A 400 by 400 document with a selected graph of type `kind`: series a and b over Q1 (1, 2)
|
||||
/// and Q2 (3, 4). The app has a window to host the dialog.
|
||||
fn app_with_graph(kind: &str) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app.run("graph.create", json!({"type": kind, "x": 0, "y": 0, "width": 200, "height": 150, "csv": ",a,b\nQ1,1,2\nQ2,3,4"})).unwrap();
|
||||
app
|
||||
|
||||
@@ -92,8 +92,7 @@ mod tests {
|
||||
|
||||
/// A selected area type object with two paragraphs.
|
||||
fn app() -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
driver::install(&mut app);
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 10, "text": "One\nTwo", "area": {"width": 200, "height": 100}})).unwrap()["id"]
|
||||
.as_u64()
|
||||
|
||||
@@ -127,8 +127,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn commits_the_chosen_palette_as_one_step() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
let img = craft_image_codecs::Image::from_raw(
|
||||
2,
|
||||
|
||||
@@ -219,8 +219,7 @@ mod tests {
|
||||
|
||||
/// A selected area type object with two paragraphs.
|
||||
fn app() -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
driver::install(&mut app);
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 10, "text": "One\nTwo", "area": {"width": 200, "height": 100}})).unwrap()["id"]
|
||||
.as_u64()
|
||||
@@ -315,8 +314,7 @@ mod tests {
|
||||
/// A threaded story of three frames, first selected with the Type tool and Select All; a
|
||||
/// frame joined or left while the dialog is open is read at OK.
|
||||
fn threaded(frames: usize) -> (VectorcraftApp, Vec<u64>) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
driver::install(&mut app);
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 900, "height": 300})).unwrap();
|
||||
let story = "The quick brown fox jumps over the lazy dog and keeps running far beyond the first frame.\n".repeat(6);
|
||||
let area = json!({"x": 10, "y": 10, "text": story, "size": 12, "area": {"width": 150, "height": 60}});
|
||||
@@ -372,8 +370,7 @@ mod tests {
|
||||
/// of its own, and the first frame selected with the Selection tool → the app, the frames and
|
||||
/// the other type object.
|
||||
fn story_selected_in_its_first_frame() -> (VectorcraftApp, [u64; 3], u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
driver::install(&mut app);
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 900, "height": 300})).unwrap();
|
||||
let story = "The quick brown fox jumps over the lazy dog.\n".repeat(12);
|
||||
let area = json!({"x": 10, "y": 10, "text": story, "size": 12, "area": {"width": 150, "height": 60}});
|
||||
|
||||
@@ -4,8 +4,7 @@ use vectorcraft_engine::Session;
|
||||
use super::*;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -604,8 +604,7 @@ mod tests {
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ mod tests {
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -163,9 +163,7 @@ mod tests {
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
/// The open dialog's id and fields.
|
||||
|
||||
@@ -84,8 +84,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -692,9 +692,7 @@ mod tests {
|
||||
|
||||
/// An app with a window context, so New Document has a host to open on.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
fn ctx(app: &VectorcraftApp) -> egui::Context {
|
||||
|
||||
@@ -393,8 +393,7 @@ pub(super) mod tests {
|
||||
|
||||
/// An app with a window context for the dialog host and a blank document.
|
||||
pub(in crate::dialogs) fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -122,9 +122,7 @@ mod tests {
|
||||
use super::super::preset_manager::PresetManager;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
fn ctx(app: &VectorcraftApp) -> egui::Context {
|
||||
|
||||
@@ -80,8 +80,7 @@ mod tests {
|
||||
use vectorcraft_tools::{PointerEvent, PointerKind};
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 800, "height": 600})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ mod tests {
|
||||
.collect();
|
||||
let files: Vec<Value> = paths.iter().map(|p| json!({ "path": p })).collect();
|
||||
let services = crate::Services { read: Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string()))), ..Default::default() };
|
||||
let mut app = host::with_window(VectorcraftApp::new(Session::new(), services));
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
// The choices made last would place the layers without asking with Show Import Options off.
|
||||
app.ui.psd_import = json!({"layers": true, "importSlices": true});
|
||||
|
||||
@@ -133,8 +133,7 @@ mod tests {
|
||||
|
||||
/// An app with a window and a 200 × 200 document.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -264,8 +264,7 @@ mod tests {
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app(artboards: u32) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 100, "height": 50, "artboards": artboards})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -54,8 +54,7 @@ mod tests {
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 100, "height": 50, "artboards": 3})).unwrap();
|
||||
app.select_tool("artboard");
|
||||
app
|
||||
|
||||
@@ -27,8 +27,7 @@ pub(super) fn app(dir: &std::path::Path, web: bool) -> (VectorcraftApp, Log) {
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
// The files go to disk, where the tests read them back.
|
||||
app.services.write = Some(Box::new(|path: &str, bytes: &[u8]| std::fs::write(path, bytes).map_err(|e| e.to_string())));
|
||||
let dir = dir.to_path_buf();
|
||||
|
||||
@@ -47,8 +47,7 @@ fn web() -> (VectorcraftApp, Written) {
|
||||
}
|
||||
|
||||
fn with_art(services: Services) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap();
|
||||
app
|
||||
|
||||
@@ -26,8 +26,7 @@ fn app() -> (VectorcraftApp, Log) {
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 120, "height": 90, "artboards": 3})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
|
||||
(app, written)
|
||||
@@ -309,8 +308,7 @@ fn save_summary_writes_files_on_disk_within_the_automation_roots() {
|
||||
write: Some(Box::new(|p: &str, b: &[u8]| vectorcraft_format::write_atomic(std::path::Path::new(p), b).map_err(|e| e.to_string()))),
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), services).with_automation_roots(roots.clone());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services).with_automation_roots(roots.clone()));
|
||||
app.run("file.new", json!({"width": 120, "height": 90})).unwrap();
|
||||
app.run("file.export.pdf", json!({})).unwrap();
|
||||
let mut save = |path: &std::path::Path| {
|
||||
@@ -483,8 +481,7 @@ fn a_page_of_the_arts_bounds_is_written_in_the_background() {
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.session.prefs.background_export = true;
|
||||
app.run("file.new", json!({"width": 120, "height": 90})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
|
||||
|
||||
@@ -140,8 +140,7 @@ mod tests {
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.session.paint.stroke = vectorcraft_color::Paint::None;
|
||||
let id = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 60, "height": 40})).unwrap()["id"].as_u64().unwrap();
|
||||
|
||||
@@ -89,8 +89,7 @@ mod tests {
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
fn app_with_text(text: &str) -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 40, "text": text, "font": "Source Sans 3"})).unwrap()["id"].as_u64().unwrap();
|
||||
(app, id)
|
||||
|
||||
@@ -440,8 +440,7 @@ mod tests {
|
||||
const SHIFT: &str = r#"<filter id="Shift"><feOffset dx="3"/></filter>"#;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -446,8 +446,7 @@ mod tests {
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 120, "height": 80, "artboards": 2})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 30})).unwrap();
|
||||
(app, written)
|
||||
|
||||
@@ -80,8 +80,7 @@ mod tests {
|
||||
|
||||
/// A selected point type object with four characters.
|
||||
fn app() -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
driver::install(&mut app);
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 50, "text": "2026"})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
|
||||
@@ -50,8 +50,7 @@ pub(super) fn app_saving(artboards: usize, pick: impl Fn(&PickRequest) -> String
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
save_panel(&mut app, move |p| Some(pick(p)));
|
||||
app.run("file.new", json!({"width": 60, "height": 40, "artboards": artboards})).unwrap();
|
||||
app.run("paint.setStroke", json!({"none": true})).unwrap();
|
||||
|
||||
@@ -12,8 +12,7 @@ use super::*;
|
||||
use crate::{VectorcraftApp, io};
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ fn window(app: &VectorcraftApp) -> egui::Context {
|
||||
}
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 800, "height": 600})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ impl PrintService for MockPrint {
|
||||
fn app() -> (VectorcraftApp, Jobs) {
|
||||
let jobs = Jobs::default();
|
||||
let services = Services { print: Some(Box::new(MockPrint(jobs.clone()))), ..Default::default() };
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 120, "height": 90, "artboards": 3})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
|
||||
(app, jobs)
|
||||
@@ -104,8 +103,11 @@ pub(super) fn call(app: &mut VectorcraftApp, method: &str, params: Value) -> Val
|
||||
r["result"].clone()
|
||||
}
|
||||
|
||||
/// Presses the control named `name`, then runs the frame's dialog work.
|
||||
/// Presses the control named `name` in a frame drawn first, as a user presses what the window shows, then runs the
|
||||
/// frame's dialog work.
|
||||
pub(super) fn press(app: &mut VectorcraftApp, name: &str) {
|
||||
let ctx = ctx(app);
|
||||
crate::testing::app_frame(app, &ctx, Default::default());
|
||||
call(app, "ui.click", json!({"control": {"name": name}}));
|
||||
pump(app);
|
||||
}
|
||||
@@ -213,8 +215,7 @@ fn a_landscape_job_goes_upright_to_a_queue_that_does_not_turn_it() {
|
||||
|
||||
#[test]
|
||||
fn without_a_print_service_print_saves_a_pdf() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services::default()));
|
||||
let picker = crate::tests_picks::scripted(&mut app);
|
||||
let written: Written = Rc::default();
|
||||
let w = written.clone();
|
||||
|
||||
@@ -8,8 +8,7 @@ use super::tests_print::{confirm, fields, pump, set};
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 120, "height": 90})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
|
||||
app
|
||||
|
||||
@@ -21,9 +21,7 @@ fn press(app: &mut VectorcraftApp, act: ManagerAction) {
|
||||
}
|
||||
|
||||
fn new_app(services: Services) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), services))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -65,8 +65,7 @@ fn cancel_of(app: &mut VectorcraftApp, kind: &str) {
|
||||
}
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 800, "height": 600})).unwrap();
|
||||
app.select_tool(KIND);
|
||||
// Pointer-up persists tool settings even for a click. Seed them so opening/cancelling can
|
||||
|
||||
@@ -26,8 +26,7 @@ fn app(web: bool) -> (VectorcraftApp, Log, [u64; 2]) {
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
|
||||
app.session.paint.stroke = vectorcraft_color::Paint::None;
|
||||
let mut rect = |x: f64| app.run("shape.rectangle", json!({"x": x, "y": 10, "width": 30, "height": 20})).unwrap()["id"].as_u64().unwrap();
|
||||
|
||||
@@ -39,8 +39,7 @@ fn app(artboards: usize, web: bool) -> (VectorcraftApp, Log) {
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 60, "height": 40, "artboards": artboards})).unwrap();
|
||||
app.run("shape.ellipse", json!({"x": 5, "y": 4, "width": 30, "height": 20})).unwrap();
|
||||
(app, log)
|
||||
|
||||
@@ -142,15 +142,9 @@ pub(super) mod test_support {
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
/// `app` with a window to host dialogs in.
|
||||
pub fn with_window(mut app: VectorcraftApp) -> VectorcraftApp {
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
/// An empty app with a window.
|
||||
pub fn app() -> VectorcraftApp {
|
||||
with_window(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
fn ctx(app: &VectorcraftApp) -> egui::Context {
|
||||
|
||||
@@ -316,7 +316,7 @@ mod tests {
|
||||
fn app_with_variables() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
// PLAN: assumed `crate::testing::ui_context() -> egui::Context` (hub-w1, S-SH4) and `ui_ctx: Option<egui::Context>`
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app = crate::testing::windowed(app);
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("variable.define", json!({"name": "Title", "kind": "text"})).unwrap();
|
||||
app.run("variable.define", json!({"name": "Badge", "kind": "visibility"})).unwrap();
|
||||
|
||||
@@ -132,11 +132,6 @@ pub(super) mod driver {
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
/// Gives the app a window context, so a dialog can open.
|
||||
pub fn install(app: &mut VectorcraftApp) {
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
}
|
||||
|
||||
fn ctx(app: &VectorcraftApp) -> egui::Context {
|
||||
app.ui_ctx.clone().expect("installed")
|
||||
}
|
||||
@@ -193,8 +188,7 @@ mod tests {
|
||||
|
||||
/// A selected point type object with four characters.
|
||||
fn app() -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
driver::install(&mut app);
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 50, "text": "abcd"})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
|
||||
@@ -762,8 +762,8 @@ fn new_window_opens_a_numbered_view_with_its_own_zoom() {
|
||||
|
||||
#[test]
|
||||
fn closing_a_view_leaves_the_document_open() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = crate::testing::windowed(app_with(1));
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
|
||||
@@ -653,9 +653,7 @@ mod tests {
|
||||
|
||||
/// An app whose window has a dialog host (it has a context).
|
||||
fn new_app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
/// Runs `f` on the open Find Font dialog.
|
||||
|
||||
@@ -75,9 +75,7 @@ mod tests {
|
||||
|
||||
/// An app with `services` and a window context, where its dialogs open.
|
||||
fn windowed(services: Services) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), services))
|
||||
}
|
||||
|
||||
/// The message dialog open on the host, closed as its Close button closes it: its message and detail.
|
||||
|
||||
@@ -48,8 +48,7 @@ fn app(format: &str, kind: ErrorKind) -> (VectorcraftApp, Arc<Mutex<Files>>) {
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
app.run("file.new", json!({"width": 40, "height": 40})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 1, "y": 1, "width": 10, "height": 10})).unwrap();
|
||||
let st = app.session.doc_mut().unwrap();
|
||||
|
||||
@@ -430,7 +430,7 @@ fn names_in_menus_are_not_interface_labels() {
|
||||
|
||||
#[test]
|
||||
fn last_effect_dialog_and_view_toggles() {
|
||||
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": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
assert!(!enabled(&app, "effect.last"));
|
||||
|
||||
@@ -78,8 +78,7 @@ fn open_with_runs_the_importer_off_the_ui_thread() {
|
||||
use vectorcraft_plugins::wat::{self as tpl, Given};
|
||||
let rect = r#"{"objects":[{"type":"path","path":{"subpaths":[{"closed":true,"anchors":[{"p":[10,20]},{"p":[110,20]},{"p":[110,70]},{"p":[10,70]}]}]}}]}"#;
|
||||
let (_dir, file) = importer_file("with");
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services::default()));
|
||||
app.services.read = Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string())));
|
||||
let params = r#"{"density":{"type":"number","min":0,"max":10,"default":4}}"#;
|
||||
install_importer(&mut app, &tpl::when_given(&tpl::importer("test.opening.with", r#"["tob"]"#, params), Given::Params, r#""density":7"#, rect));
|
||||
@@ -370,8 +369,7 @@ fn a_file_read_off_the_ui_thread_has_its_links_and_type_as_one_read_at_once() {
|
||||
.unwrap();
|
||||
out
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services::default()));
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
for (name, format) in [("a.tif", Tiff), ("b.bmp", Bmp), ("c.jpg", Jpeg), ("gone.png", Png), ("changed.png", Png)] {
|
||||
std::fs::write(file(&before, name), picture(format, [200, 40, 40])).unwrap();
|
||||
|
||||
@@ -86,8 +86,7 @@ fn menu_insert_rows_open_their_dialog_on_the_selected_step_the_action_end_or_the
|
||||
})
|
||||
};
|
||||
for id in ["actionsPanel.insertStop", "actionsPanel.insertMenuItem", "ui.action.selectObjectDialog"] {
|
||||
let mut app = with_sets();
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(with_sets());
|
||||
app.ui.actions.insert_step(1, 0, craft::automation::actions::ActionStep::new("a.b", json!({}))).unwrap();
|
||||
app.ui.actions_panel.expanded.insert("A in S2".into());
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@ use crate::VectorcraftApp;
|
||||
|
||||
/// An app with the built-in set, in a window whose dialog host the tests drive.
|
||||
pub(crate) fn new_app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
/// An action named `name` with `steps`, each a command and its params, in no set yet.
|
||||
|
||||
@@ -573,7 +573,7 @@ fn the_panel_menu_rows_run_their_commands_and_check_by_state() {
|
||||
use craft::ui::patterns::form_dialogs::HostedParamDialog;
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
// The settings rows open their dialogs on the window's host.
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app = crate::testing::windowed(app);
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "ABC", "size": 13})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
|
||||
@@ -1044,8 +1044,7 @@ mod tests {
|
||||
|
||||
/// An app with a window, on a document holding one rectangle.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap();
|
||||
app
|
||||
|
||||
@@ -361,7 +361,8 @@ fn isolation_keeps_delete_to_the_rows_listed() {
|
||||
/// be outside the isolated art; a sublayer of an isolated sublayer is listed.
|
||||
#[test]
|
||||
fn isolation_keeps_new_layers_to_the_rows_listed() {
|
||||
let (mut app, [_, sub, g, ..]) = nested();
|
||||
let (app, [_, sub, g, ..]) = nested();
|
||||
let mut app = crate::testing::windowed(app);
|
||||
app.session.execute("object.isolate", &json!({"id": g.0})).unwrap();
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!([(false, false), (true, false), (false, true)].map(|(s, t)| new_layer_unlisted(st, s, t)), [true; 3]);
|
||||
|
||||
@@ -10,9 +10,10 @@ use crate::tests_labels::painted_text;
|
||||
|
||||
const SCREEN: egui::Rect = egui::Rect::from_min_max(egui::Pos2::ZERO, egui::pos2(1400.0, 800.0));
|
||||
|
||||
/// An app in a window of its own.
|
||||
fn app() -> VectorcraftApp {
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
VectorcraftApp::new(Session::new(), Default::default())
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()))
|
||||
}
|
||||
|
||||
/// One frame of `draw` with screen-reader nodes on → the nodes.
|
||||
@@ -47,13 +48,6 @@ fn click(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, draw: fn(&mu
|
||||
click_with(app, name, |app, events| frame(app, ctx, events, draw));
|
||||
}
|
||||
|
||||
fn context() -> egui::Context {
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.enable_accesskit();
|
||||
crate::testing::install(&ctx);
|
||||
ctx
|
||||
}
|
||||
|
||||
/// One frame of the whole app with `events`: the shell draws the app bar and applies the panels' toggles.
|
||||
fn shell_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>) -> Vec<Node> {
|
||||
frame(app, ctx, events, |app, ui| app.ui(ui))
|
||||
@@ -113,7 +107,7 @@ fn the_catalog_is_valid() {
|
||||
#[test]
|
||||
fn explore_tutorials_on_the_app_bar_shows_and_hides_the_learn_panel() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
assert!(!shown(&app));
|
||||
click_with(&mut app, "Explore tutorials", |app, events| shell_frame(app, &ctx, events));
|
||||
assert!(shown(&app), "{}", app.ui.status);
|
||||
@@ -150,7 +144,7 @@ fn window_learn_shows_and_hides_the_panel() {
|
||||
#[test]
|
||||
fn window_learn_shows_a_hidden_dock() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let (cmd, params) = window_learn(&app);
|
||||
assert_eq!(app.run("window.learn", json!({"show": true})).unwrap(), json!(true));
|
||||
hide_panels(&mut app, &ctx);
|
||||
@@ -224,7 +218,7 @@ fn the_next_tutorial_is_the_next_one_in_the_same_skill() {
|
||||
#[test]
|
||||
fn view_more_opens_the_tutorial_s_sample_as_a_new_untitled_document() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap();
|
||||
let work = app.session.documents()[0].doc.node_count();
|
||||
@@ -256,7 +250,7 @@ fn view_more_opens_the_tutorial_s_sample_as_a_new_untitled_document() {
|
||||
#[test]
|
||||
fn finishing_a_tutorial_offers_next_up_in_its_skill() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let (skill, tutorial) = catalog::tutorial("pen-paths").unwrap();
|
||||
app.ui.learn = View { tab: Tab::Skills, skill: Some(skill.id), tutorial: Some(tutorial.id) };
|
||||
let text = painted_text(&mut app, show);
|
||||
@@ -281,7 +275,7 @@ fn finishing_a_tutorial_offers_next_up_in_its_skill() {
|
||||
#[test]
|
||||
fn the_last_tutorial_of_a_skill_offers_back_to_skills() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
for id in ["add-headline", "outline-type"] {
|
||||
app.run("learn.openSample", json!({"tutorial": id})).unwrap();
|
||||
assert_eq!(app.run("learn.finish", json!({"tutorial": id})).unwrap(), json!({"tutorial": id, "finished": true, "next": null}));
|
||||
@@ -336,7 +330,7 @@ fn learn_skills_shows_the_list_of_skills() {
|
||||
|
||||
// Back to skills, after a skill's last tutorial.
|
||||
let mut app = self::app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
app.run("learn.openSample", json!({"tutorial": "outline-type"})).unwrap();
|
||||
app.run("learn.finish", json!({"tutorial": "outline-type"})).unwrap();
|
||||
assert!(!shown(&app));
|
||||
@@ -346,7 +340,7 @@ fn learn_skills_shows_the_list_of_skills() {
|
||||
|
||||
// The Quick skill guide card on the For you tab.
|
||||
let mut app = self::app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
assert!(!shown(&app));
|
||||
click(&mut app, &ctx, "Quick skill guide", show);
|
||||
assert_eq!(app.ui.learn, skills);
|
||||
@@ -399,7 +393,7 @@ fn the_tabs_rows_and_back_run_their_commands() {
|
||||
assert!(crate::menus::UI_COMMANDS.iter().any(|c| c.0 == cmd), "{cmd} is in the UI command catalog");
|
||||
}
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let (skill, tutorial) = catalog::tutorial("gradient").unwrap();
|
||||
let press = |app: &mut VectorcraftApp, name: &str, view: View| {
|
||||
app.run("window.learn", json!({"show": false})).unwrap();
|
||||
@@ -473,7 +467,7 @@ fn pen_paths(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
|
||||
#[test]
|
||||
fn a_tool_name_in_a_step_is_a_link_that_locates_the_tool() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let nodes = frame(&mut app, &ctx, vec![], pen_paths);
|
||||
let link = nodes.iter().find(|n| n.label().is_some_and(|l| l == "Pen tool")).expect("the Pen tool link");
|
||||
assert_eq!(link.role(), egui::accesskit::Role::Link);
|
||||
@@ -508,7 +502,7 @@ fn learn_locate_tool_rejects_a_missing_or_unknown_tool() {
|
||||
#[test]
|
||||
fn learn_locate_tool_is_unavailable_while_the_toolbars_are_hidden() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
app.ui.screen_mode = 3;
|
||||
let reply = app.run("learn.locateTool", json!({"tool": "pen"})).unwrap();
|
||||
assert_eq!((reply["location"].as_str(), reply["reason"].is_string()), (Some("unavailable"), true), "{reply}");
|
||||
@@ -541,7 +535,7 @@ fn check_boxes(app: &mut VectorcraftApp, ctx: &egui::Context, draw: fn(&mut Vect
|
||||
#[test]
|
||||
fn a_step_s_check_box_marks_only_that_step() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
assert_eq!(check_boxes(&mut app, &ctx, pen_paths), [(false, false); 3], "off before View more");
|
||||
click(&mut app, &ctx, &pen_step(1), pen_paths);
|
||||
assert!(app.ui.learn_progress.is_empty(), "a check box that is off changes nothing");
|
||||
@@ -576,7 +570,7 @@ fn a_step_s_check_box_marks_only_that_step() {
|
||||
#[test]
|
||||
fn finishing_tutorials_fills_their_skill_s_ring_and_count() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
for id in ["pen-paths", "smooth-curves"] {
|
||||
app.run("learn.openSample", json!({"tutorial": id})).unwrap();
|
||||
for _ in 0..2 {
|
||||
@@ -668,7 +662,7 @@ fn learn_mark_step_checks_its_params() {
|
||||
#[test]
|
||||
fn reset_progress_clears_only_the_progress() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let skills = View { tab: Tab::Skills, skill: None, tutorial: None };
|
||||
app.ui.learn = skills.clone();
|
||||
assert!(!painted_text(&mut app, show).contains("Reset progress"));
|
||||
|
||||
@@ -171,7 +171,7 @@ const SWATCH_IDS: [&str; 9] = [
|
||||
fn save_dialog_writes_user_libraries_that_the_window_menu_lists() {
|
||||
let dir = std::env::temp_dir().join(format!("vc-library-panel-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let mut app = app();
|
||||
let mut app = crate::testing::windowed(app());
|
||||
app.session.swatch_libraries.set_user_dir(Some(dir.to_string_lossy().to_string()));
|
||||
let user_items = |app: &VectorcraftApp| -> Vec<(String, String)> {
|
||||
crate::menus::menu_entries(app)
|
||||
|
||||
@@ -305,7 +305,7 @@ mod tests {
|
||||
/// command flips the option or opens the options dialog.
|
||||
#[test]
|
||||
fn the_panel_menu_rows_check_and_open_what_they_name() {
|
||||
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()));
|
||||
let states = |app: &VectorcraftApp| {
|
||||
let mut states = CommandStates::new();
|
||||
menu_states(app, &mut states);
|
||||
|
||||
@@ -544,7 +544,7 @@ fn more_options_opens_bullets_and_numbering_on_its_tab() {
|
||||
use craft::ui::dialog::StackDialog as _;
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let (mut app, _) = editing_text("One\nTwo");
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app = crate::testing::windowed(app);
|
||||
select_range(&mut app, 0, 0);
|
||||
let shown_tab = |app: &VectorcraftApp| {
|
||||
app.dialogs().expect("a window").with(|host| host.get::<BulletsDialog>().map(|d| d.json_fields().unwrap_or_default()["tab"].clone()))
|
||||
|
||||
@@ -359,8 +359,7 @@ mod tests {
|
||||
|
||||
/// An app with a window, so its dialogs open, and a 200 pt document.
|
||||
fn windowed() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ use vectorcraft_engine::Session;
|
||||
mod context_menu;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ fn the_window_menu_and_the_brushes_panel_open_brush_libraries() {
|
||||
fn save_brushes_writes_a_user_library_that_reopens_and_adds_to_another_document() {
|
||||
let dir = std::env::temp_dir().join(format!("vc-brush-libraries-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let mut app = app();
|
||||
let mut app = crate::testing::windowed(app());
|
||||
app.session.brush_libraries.set_user_dir(Some(dir.to_string_lossy().to_string()));
|
||||
app.run("brush.new", json!({"type": "calligraphic", "name": "Quill", "params": {"angle": 60, "roundness": 30, "size": 5}})).unwrap();
|
||||
app.run("ui.saveBrushLibrary", json!({"names": ["Quill"]})).unwrap();
|
||||
|
||||
@@ -565,7 +565,8 @@ fn edit_original_opens_image_and_document_files_only() {
|
||||
fn placement_options_dialog_sets_the_options() {
|
||||
use crate::tests::picks::{answer_dialog, open_dialogs};
|
||||
let dir = Folder::new("dialog");
|
||||
let (mut app, linked, _) = app(&dir);
|
||||
let (app, linked, _) = app(&dir);
|
||||
let mut app = crate::testing::windowed(app);
|
||||
app.run("select.set", json!({"ids": [linked]})).unwrap();
|
||||
assert!(crate::menus::enabled(&app, "ui.placementOptionsDialog"));
|
||||
app.run("ui.placementOptionsDialog", json!({})).unwrap();
|
||||
|
||||
@@ -150,7 +150,7 @@ fn the_window_menu_and_the_panel_open_every_library() {
|
||||
fn save_dialog_writes_user_libraries_that_the_window_menu_lists() {
|
||||
let dir = std::env::temp_dir().join(format!("vc-style-libraries-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let mut app = app();
|
||||
let mut app = crate::testing::windowed(app());
|
||||
app.session.style_libraries.set_user_dir(Some(dir.to_string_lossy().to_string()));
|
||||
let user_items = |app: &VectorcraftApp| -> Vec<(String, String)> {
|
||||
crate::menus::menu_entries(app)
|
||||
|
||||
@@ -112,7 +112,7 @@ fn the_window_menu_and_the_symbols_panel_open_symbol_libraries() {
|
||||
fn save_symbols_writes_a_user_library_that_reopens_and_adds_to_another_document() {
|
||||
let dir = std::env::temp_dir().join(format!("vc-symbol-libraries-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let mut app = app();
|
||||
let mut app = crate::testing::windowed(app());
|
||||
app.session.symbol_libraries.set_user_dir(Some(dir.to_string_lossy().to_string()));
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap();
|
||||
app.run("symbol.new", json!({"name": "Brick"})).unwrap();
|
||||
|
||||
@@ -550,6 +550,7 @@ fn all_registered_shortcuts_parse() {
|
||||
fn a_single_key_shortcut_reports_what_its_chord_reports() {
|
||||
let status = |shortcut: &str, events: Vec<egui::Event>| {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
ready(&mut app);
|
||||
bind(&mut app, "view.screenMode", "");
|
||||
bind(&mut app, "paint.default", shortcut);
|
||||
app.ui.status.clear();
|
||||
@@ -568,6 +569,7 @@ fn a_shortcut_runs_what_its_menu_item_runs() {
|
||||
let chord = tap(Key::F9, cmd() | Modifiers::ALT | Modifiers::SHIFT);
|
||||
for id in ["object.path.cleanUp", "addon.color.printFixes", "edit.findReplace"] {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_testkit::fixtures::Fixture::Single.session(), Default::default());
|
||||
ready(&mut app);
|
||||
bind(&mut app, id, "Cmd+Alt+Shift+F9");
|
||||
app.ui.status.clear();
|
||||
frame(&mut app, chord.clone());
|
||||
@@ -715,6 +717,7 @@ fn cmd_alt_shift_j_opens_average_and_join() {
|
||||
#[test]
|
||||
fn a_key_assigned_to_the_color_picker_opens_it_for_the_proxy_in_front() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
ready(&mut app);
|
||||
let listed = app.run("shortcuts.list", json!({"query": "ui.colorPicker"})).unwrap();
|
||||
let rows: Vec<_> = listed.as_array().expect("rows").iter().map(|r| r["label"].clone()).collect();
|
||||
assert_eq!(rows, [json!("Color Picker…")], "Keyboard Shortcuts lists it");
|
||||
|
||||
@@ -6,8 +6,7 @@ use vectorcraft_engine::Session;
|
||||
use crate::{VectorcraftApp, dialogs, menus};
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
app
|
||||
|
||||
@@ -41,8 +41,7 @@ fn confined_with(tag: &str, write_shared: Option<SharedWriteFn>) -> (Vectorcraft
|
||||
};
|
||||
let roots = AutomationRoots::new(&[&base.join("in")], &[&base.join("out")]).unwrap();
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let mut app = VectorcraftApp::new(Session::new(), services).with_control(rx).with_automation_roots(roots);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services).with_control(rx).with_automation_roots(roots));
|
||||
(app, tx, base)
|
||||
}
|
||||
|
||||
@@ -1573,8 +1572,7 @@ fn automation_cannot_approve_a_plugin_install() {
|
||||
/// An app with a control channel and a new document.
|
||||
fn controlled() -> (VectorcraftApp, std::sync::mpsc::Sender<ControlRequest>) {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default()).with_control(rx);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()).with_control(rx));
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
(app, tx)
|
||||
}
|
||||
@@ -1850,8 +1848,7 @@ fn a_file_picked_in_a_dialog_automation_opened_stays_automations() {
|
||||
|
||||
let (dropped, page) = <(crate::services::Inbox, crate::services::Inbox)>::default();
|
||||
let services = Services { inbox: Some(dropped.clone()), page_inbox: Some(page.clone()), ..Default::default() };
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
for (inbox, id, origin) in
|
||||
[(&dropped, "test.ui.approval.picked.dropped", InstallOrigin::Person), (&page, "test.ui.approval.picked.page", InstallOrigin::Automation)]
|
||||
{
|
||||
@@ -1874,8 +1871,7 @@ fn a_plugin_automation_opened_by_path_asks_a_question_no_one_approves() {
|
||||
std::fs::write(&wasm, approval_module(id).0).unwrap();
|
||||
let services = Services { read: Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string()))), ..Default::default() };
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let mut app = VectorcraftApp::new(Session::new(), services).with_control(rx);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services).with_control(rx));
|
||||
let r = request(&mut app, &tx, "app.open", json!({"path": s(wasm.clone())}));
|
||||
assert!(r.get("error").is_none(), "{r}");
|
||||
assert!(super::plugins::waiting(&app, id));
|
||||
|
||||
@@ -39,8 +39,7 @@ fn swatch(app: &mut VectorcraftApp, name: &str, hex: &str) {
|
||||
/// A rectangle filled with global swatch Brand (red) and stroked with Ink (black) copied from one
|
||||
/// document, and a second document (active) whose Brand is blue and Ink green; in a window.
|
||||
fn conflicting() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
run(&mut app, "file.new", json!({"width": 200, "height": 200}));
|
||||
swatch(&mut app, "Brand", "#ff0000");
|
||||
swatch(&mut app, "Ink", "#000000");
|
||||
|
||||
@@ -164,6 +164,7 @@ fn right_click_on_a_locked_object_offers_unlock_by_its_name() {
|
||||
fn cmd_alt_shift_u_switches_to_the_next_unit() {
|
||||
use vectorcraft_doc::Unit;
|
||||
let mut app = app();
|
||||
crate::tests_synthetic::key_frame(&mut app, &crate::testing::ui_context(), vec![]);
|
||||
assert_eq!(app.run("shortcuts.conflicts", json!({})).unwrap(), json!([]), "no other default has the key");
|
||||
fn press(app: &mut VectorcraftApp) {
|
||||
let ctx = crate::testing::ui_context();
|
||||
|
||||
@@ -836,6 +836,7 @@ fn click(app: &mut VectorcraftApp) {
|
||||
fn holding_escape_with_the_place_cursor_loaded_discards_one_file() {
|
||||
let mut app = app();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![], &[], false);
|
||||
app.run("shortcuts.set", json!({"id": "select.none", "shortcut": "Escape", "force": true})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap()["id"].clone();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
@@ -864,6 +865,7 @@ fn holding_escape_with_the_place_cursor_loaded_discards_one_file() {
|
||||
fn holding_a_chord_bound_to_a_command_repeats_it_with_the_place_cursor_loaded() {
|
||||
let mut app = app();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![], &[], false);
|
||||
app.run("shortcuts.set", json!({"id": "view.zoomIn", "shortcut": "Shift+Escape", "force": true})).unwrap();
|
||||
let dir = Folder::new("ui-place-held-chord");
|
||||
let paths: Vec<String> = ["chord-a.png", "chord-b.png"].iter().map(|name| dir.file(name, &png(10, 10, 72.0))).collect();
|
||||
|
||||
@@ -32,8 +32,7 @@ fn postscript_is_saved_not_printed() {
|
||||
let written: Written = Rc::default();
|
||||
let w = written.clone();
|
||||
let services = Services { print: Some(Box::new(Counting(sent.clone()))), ..Default::default() };
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), services));
|
||||
let picker = crate::tests_picks::scripted(&mut app);
|
||||
app.services.write = Some(Box::new(move |p: &str, b: &[u8]| {
|
||||
w.borrow_mut().push((p.to_string(), b.to_vec()));
|
||||
|
||||
@@ -19,9 +19,7 @@ fn app() -> VectorcraftApp {
|
||||
write: Some(Box::new(|p: &str, b: &[u8]| std::fs::write(p, b).map_err(|e| e.to_string()))),
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
crate::testing::windowed(VectorcraftApp::new(Session::new(), services))
|
||||
}
|
||||
|
||||
/// A fresh folder for one test.
|
||||
|
||||
@@ -11,8 +11,7 @@ use crate::dialogs::script_run::{self, CLOSE_KIND, CloseQuestion, NOTICE_KIND, S
|
||||
use crate::{VectorcraftApp, menus, script_runs};
|
||||
|
||||
pub(super) fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), crate::Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), crate::Services::default()));
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.session.prefs.show_external_script_warning = false;
|
||||
app
|
||||
|
||||
@@ -16,8 +16,7 @@ use crate::tests::picks::{Picker, scripted};
|
||||
use crate::{VectorcraftApp, menus, script_runs};
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), crate::Services::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), crate::Services::default()));
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ use vectorcraft_engine::Session;
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.paint.stroke = vectorcraft_color::Paint::None;
|
||||
app
|
||||
|
||||
@@ -104,7 +104,7 @@ fn answer(app: &mut VectorcraftApp, ok: bool) {
|
||||
/// (each with what it needs selected), the view fits for Hand and Zoom, and a tool without options refuses.
|
||||
#[test]
|
||||
fn tools_open_their_options() {
|
||||
let mut app = app_with(300, 200);
|
||||
let mut app = windowed(app_with(300, 200));
|
||||
let kind = |app: &mut VectorcraftApp, tool: &str| open_options(app, tool).unwrap()["dialog"].clone();
|
||||
// Without the Artboard tool, the window's artboard; with it, its active artboard.
|
||||
assert_eq!(kind(&mut app, "artboard"), "artboardOptions");
|
||||
|
||||
Reference in New Issue
Block a user