mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 19:51:26 -05:00
Panel tests: Cancel through the dialog host, held OKs through the shared answer, panel-menu states, the controls' own names and fields, the app's window for whole-app frames, pointer clicks on document colors
This commit is contained in:
@@ -238,6 +238,13 @@ mod tests {
|
||||
assert_eq!((b.x0, b.y0, b.x1, b.y1), (5.0, 5.0, 65.0, 65.0), "the stroke's outer edge");
|
||||
}
|
||||
|
||||
/// Whether the panel menu's Trap… row is enabled, as the panel menu shows it.
|
||||
fn trap_enabled(app: &VectorcraftApp) -> bool {
|
||||
let mut states = CommandStates::new();
|
||||
menu_states(app, &mut states);
|
||||
states.get(&CommandRef::new("ui.pathfinder.trap")).is_some_and(CommandState::is_enabled)
|
||||
}
|
||||
|
||||
/// The panel menu's compound shape items: Make with two or more objects selected, Release and
|
||||
/// Expand with a compound shape (or a member of one); the Expand button follows Expand, and
|
||||
/// with a member selected its Shape Mode button is lit.
|
||||
@@ -378,16 +385,10 @@ mod tests {
|
||||
host(app).with(|h| h.get_by_id::<HostedParamDialog>(id).map(|d| d.fields().clone())).expect("an open parameter dialog")
|
||||
}
|
||||
|
||||
/// Sets `fields` of the open dialog `id`, presses its OK and lets the app apply the answer.
|
||||
/// Sets `fields` of the open dialog `id`, presses its OK and lets the app apply the answer; the dialog holds its OK
|
||||
/// until the app takes the answer.
|
||||
fn confirm_dialog(app: &mut VectorcraftApp, id: egui::Id, fields: &[(&str, Value)]) {
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
host(app).with(|h| {
|
||||
for (key, value) in fields {
|
||||
h.set_json_field(&ctx, id, key, value.clone()).unwrap();
|
||||
}
|
||||
assert!(h.confirm_by_id(&ctx, id), "OK is enabled");
|
||||
});
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
crate::tests::picks::answer_dialog(app, id, fields, true);
|
||||
}
|
||||
|
||||
/// The panel menu's Trap… is enabled for two objects and opens the Trap options; OK adds the
|
||||
@@ -402,9 +403,9 @@ mod tests {
|
||||
};
|
||||
let (a, b) = (rect(10.0, "#ffff00"), rect(60.0, "#0000ff"));
|
||||
app.run("select.set", json!({"ids": [a]})).unwrap();
|
||||
assert!(!crate::menus::enabled(&app, "ui.pathfinder.trap"), "one object has nothing to trap with");
|
||||
assert!(!trap_enabled(&app), "one object has nothing to trap with");
|
||||
app.run("select.set", json!({"ids": [a, b]})).unwrap();
|
||||
assert!(crate::menus::enabled(&app, "ui.pathfinder.trap"));
|
||||
assert!(trap_enabled(&app));
|
||||
app.run("ui.pathfinder.trap", json!({})).unwrap();
|
||||
let id = open_dialog(&mut app);
|
||||
let fields = dialog_fields(&app, id);
|
||||
|
||||
@@ -18,6 +18,17 @@ fn row(app: &mut VectorcraftApp, code: &str) -> String {
|
||||
format!("{}, {}, Warning", finding["name"].as_str().unwrap(), reason(code))
|
||||
}
|
||||
|
||||
/// Whole-app frames in a window wide enough for a canvas that zooms in on the art, where the canvas, once laid out,
|
||||
/// takes the view request a zoom to the selection made.
|
||||
fn app_frame(app: &mut VectorcraftApp) {
|
||||
let ctx = app.ui_ctx.get_or_insert_with(crate::testing::ui_context).clone();
|
||||
for _ in 0..2 {
|
||||
let time = ctx.input(|i| i.time) + 0.05;
|
||||
let screen_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(2400.0, 1600.0)));
|
||||
crate::testing::app_frame(app, &ctx, egui::RawInput { screen_rect, time: Some(time), focused: true, ..Default::default() });
|
||||
}
|
||||
}
|
||||
|
||||
fn big_canvas(app: &mut VectorcraftApp) {
|
||||
app.view_mut().unwrap().rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0));
|
||||
}
|
||||
@@ -49,6 +60,7 @@ fn clicking_a_preflight_finding_selects_and_zooms_to_its_artwork() {
|
||||
let mut panel = Panel::new(app, show);
|
||||
panel.frame();
|
||||
panel.click(&overflow);
|
||||
app_frame(&mut panel.app());
|
||||
let app = panel.app();
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(id.as_u64().unwrap())]);
|
||||
assert!(app.view().unwrap().fitted);
|
||||
@@ -77,6 +89,7 @@ fn clicking_a_preflight_finding_on_a_locked_artboard_reports_the_problem() {
|
||||
}
|
||||
panel.app().run("artboard.setProps", json!({ "index": 0, "locked": false })).unwrap();
|
||||
locate(&mut panel.app(), &json!({ "ids": [id] }));
|
||||
app_frame(&mut panel.app());
|
||||
let app = panel.app();
|
||||
assert!(app.ui.status.is_empty(), "successful navigation clears its previous warning: {}", app.ui.status);
|
||||
assert!(app.view().unwrap().fitted);
|
||||
@@ -94,6 +107,7 @@ fn preflight_navigation_reports_partial_selection_and_zooms_to_selectable_artwor
|
||||
let finding = report["findings"].as_array().unwrap().iter().find(|f| f["code"] == "missingFont").unwrap();
|
||||
assert!(finding["ids"].as_array().unwrap().contains(&locked));
|
||||
locate(&mut app, finding);
|
||||
app_frame(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(free.as_u64().unwrap())]);
|
||||
assert!(app.view().unwrap().fitted);
|
||||
assert!(app.view().unwrap().zoom > 1.0);
|
||||
|
||||
@@ -476,7 +476,7 @@ fn artboard_history_delete_after_undo(key: Key, duplicate: bool) {
|
||||
(st.doc.clone(), st.selection.clone(), st.history.undo.len())
|
||||
};
|
||||
let mut panel = artboards_panel(app);
|
||||
let ctx = crate::testing::ui_context();
|
||||
let ctx = panel.ctx().clone();
|
||||
add_board(&mut panel, duplicate);
|
||||
assert_eq!(undo_depth(&panel.app()), undo + 1);
|
||||
artboard_history_key(&mut panel, &ctx, Key::Z, Modifiers::COMMAND);
|
||||
@@ -569,7 +569,7 @@ fn artboard_history_undo_prunes_only_removed_indices() {
|
||||
(st.doc.clone(), st.selection.clone(), st.history.undo.len())
|
||||
};
|
||||
let mut panel = artboards_panel(app);
|
||||
let ctx = crate::testing::ui_context();
|
||||
let ctx = panel.ctx().clone();
|
||||
artboard_history_new(&mut panel);
|
||||
let created = panel.app().session.doc().unwrap().doc.clone();
|
||||
for (at, i) in order.into_iter().enumerate() {
|
||||
@@ -606,7 +606,7 @@ fn artboard_history_valid_multiselection_survives_undo_redo() {
|
||||
app.session.set_tool_option("moveArt", &json!(false));
|
||||
app.session.set_tool_option("scaleArt", &json!(true));
|
||||
let mut panel = artboards_panel(app);
|
||||
let ctx = crate::testing::ui_context();
|
||||
let ctx = panel.ctx().clone();
|
||||
select_artboard_rows(&mut panel, &[0, 1]);
|
||||
let (options, view, before, selection, undo) = {
|
||||
let mut app = panel.app();
|
||||
@@ -1261,7 +1261,7 @@ fn objects_on_path_options_set_pivot_and_rotate_in_one_undo_step() {
|
||||
panel.frame();
|
||||
assert!(!matches!(panel.value("Rotate").as_deref(), Some("30°" | "45°")), "Rotate is blank");
|
||||
let depth = undo_depth(&panel.app());
|
||||
panel.click("Bottom Right");
|
||||
panel.click("Bottom right");
|
||||
assert_eq!(
|
||||
{
|
||||
let app = panel.app();
|
||||
@@ -1512,19 +1512,20 @@ fn character_section_shows_the_type_tool_selections_style() {
|
||||
app.run("text.setRangeStyle", json!({"id": id, "start": 8, "end": 13, "style": "Bold"})).unwrap();
|
||||
app.run("text.setRangeStyle", json!({"id": id, "start": 13, "end": 22, "style": "Condensed"})).unwrap();
|
||||
let mut panel = Panel::new(app, type_sections);
|
||||
// The style the Style picker shows.
|
||||
let shown = |panel: &mut Panel| {
|
||||
panel.frame();
|
||||
["Regular", "Bold", "Condensed"].into_iter().filter(|style| panel.shows(style)).collect::<Vec<_>>()
|
||||
panel.value("Style")
|
||||
};
|
||||
for (start, end, want) in [(8, 12, "Bold"), (13, 22, "Condensed"), (0, 7, "Regular"), (15, 15, "Condensed"), (13, 13, "Bold")] {
|
||||
panel.app().session.set_tool_option("select", &json!({"start": start, "end": end}));
|
||||
assert_eq!(crate::panels::character::text_editing(&panel.app()).map(|(_, a, b)| (a, b)), Some((start, end)));
|
||||
assert_eq!(shown(&mut panel), [want], "{start}..{end}");
|
||||
assert_eq!(shown(&mut panel).as_deref(), Some(want), "{start}..{end}");
|
||||
}
|
||||
panel.app().session.select_tool("selection", Default::default()).unwrap();
|
||||
panel.app().run("select.set", json!({"ids": [id]})).unwrap();
|
||||
assert_eq!(crate::panels::character::text_editing(&panel.app()), None);
|
||||
assert_eq!(shown(&mut panel), ["Regular"], "the Selection tool shows the first run's style");
|
||||
assert_eq!(shown(&mut panel).as_deref(), Some("Regular"), "the Selection tool shows the first run's style");
|
||||
}
|
||||
|
||||
/// With type selected, Quick Actions offers Create Outlines, Retype and Find and Replace… (G12): Create Outlines
|
||||
|
||||
@@ -357,8 +357,8 @@ fn new_swatch_dialog_prefills_the_active_colour_and_saves_into_the_selected_grou
|
||||
// The colour group the swatch goes into is the dialog's own: OK below puts it into Brights.
|
||||
assert_eq!(dialog_field(&app, key, "name"), json!("R=255 G=128 B=0"));
|
||||
assert_eq!(
|
||||
(dialog_field(&app, key, "spot"), dialog_field(&app, key, "global")),
|
||||
(json!(true), json!(true)),
|
||||
(dialog_field(&app, key, "type"), dialog_field(&app, key, "global")),
|
||||
(json!("spot"), json!(true)),
|
||||
"Cmd/Ctrl-click makes a spot colour"
|
||||
);
|
||||
dialog_frame(&mut app, &ctx);
|
||||
@@ -1050,12 +1050,14 @@ fn color_group_options_opens_on_a_sole_selected_group() {
|
||||
fn color_group_options_without_a_group_opens_on_the_selected_group() {
|
||||
let mut app = app();
|
||||
let key = crate::dialogs::color_group_options::KIND;
|
||||
// The panel has shown the document, as it has before a click selects a row in it.
|
||||
let ctx = context(&app);
|
||||
frame(&mut app, &ctx, 0.0);
|
||||
select_rows(&mut app, &["Grays"]);
|
||||
app.run("ui.colorGroupOptions", json!({})).unwrap();
|
||||
assert_eq!(dialog_field(&app, key, "name"), json!("Grays"));
|
||||
cancel(&mut app, key);
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let ctx = context(&app);
|
||||
frame(&mut app, &ctx, 0.0);
|
||||
assert!(app.run("ui.colorGroupOptions", json!({})).is_err() && !dialog_open(&app, key), "another document");
|
||||
}
|
||||
|
||||
@@ -295,8 +295,8 @@ fn item_effect_rows_toggle_their_eye() {
|
||||
run(&mut app, "effect.apply", json!({"effect": "distort.roughen", "item": 1}));
|
||||
// The stroke row's disclosure is open: its Opacity sub-row and its effect show under it.
|
||||
let mut panel = appearance_panel(app, &[appearance::RowKey::Item(1)]);
|
||||
// PLAN: assumed accessible name of a row's eye cell
|
||||
let eye = "Visible: Roughen";
|
||||
// A row's eye cell is named for what it shows and hides.
|
||||
let eye = "Visibility Roughen";
|
||||
let visible = |panel: &Panel| current_stroke_effects(&panel.app())[0].visible;
|
||||
panel.click(eye);
|
||||
assert!(!visible(&panel));
|
||||
|
||||
@@ -75,4 +75,10 @@ impl Panel {
|
||||
let t = self.node(label);
|
||||
self.fx.access(AccessActionKind::Click, &t).idle(2);
|
||||
}
|
||||
|
||||
/// Clicks the node named `label` with the pointer.
|
||||
pub(super) fn point(&mut self, label: &str) {
|
||||
let t = self.node(label);
|
||||
self.fx.click(&t).idle(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ fn a_click_on_a_color_sets_the_fill() {
|
||||
app.run("select.set", json!({"ids": [reds[0], blue]})).unwrap();
|
||||
let undo = undo_len(&app);
|
||||
let mut p = Panel::new(app);
|
||||
p.click(&label("#0000ff", 1));
|
||||
p.point(&label("#0000ff", 1));
|
||||
assert_eq!(undo_len(&p.app()), undo + 1);
|
||||
let mut app = p.app_mut();
|
||||
assert_eq!(fill_of(&mut app, &reds[0]), "#0000ff");
|
||||
@@ -112,7 +112,7 @@ fn a_click_keeps_a_swatch_link_and_its_tint() {
|
||||
app.run("select.set", json!({"ids": [ink, blue]})).unwrap();
|
||||
let hex = used_hex(&mut app, "Ink");
|
||||
let mut p = Panel::new(app);
|
||||
p.click(&label(&hex, 1));
|
||||
p.point(&label(&hex, 1));
|
||||
let app = p.app();
|
||||
let st = app.session.doc().unwrap();
|
||||
let fill = st.doc.node(vectorcraft_doc::NodeId(blue.as_u64().unwrap())).unwrap().appearance.fill_paint().clone();
|
||||
@@ -134,7 +134,7 @@ fn a_click_recolors_the_selected_gradient_stop() {
|
||||
app.run("ui.colorWheel", json!({"documentColors": true})).unwrap();
|
||||
let hex = used_hex(&mut app, "Ink");
|
||||
let mut p = Panel::new(app);
|
||||
p.click(&label(&hex, 1));
|
||||
p.point(&label(&hex, 1));
|
||||
let Paint::Gradient(g) = crate::panels::current_paints(&p.app()).0 else { panic!("still a gradient") };
|
||||
let stop = &g.gradient.stops[1];
|
||||
assert_eq!((stop.color.to_hex(), stop.swatch.as_deref()), (hex, Some("Ink")));
|
||||
@@ -156,7 +156,7 @@ fn a_click_gives_a_freeform_point_the_color_alone() {
|
||||
app.run("ui.colorWheel", json!({"documentColors": true})).unwrap();
|
||||
let hex = used_hex(&mut app, "Ink");
|
||||
let mut p = Panel::new(app);
|
||||
p.click(&label(&hex, 1));
|
||||
p.point(&label(&hex, 1));
|
||||
let Paint::Gradient(g) = crate::panels::current_paints(&p.app()).0 else { panic!("still a gradient") };
|
||||
let points = g.freeform.expect("still freeform").points;
|
||||
assert_eq!(points[1].color.to_hex(), hex);
|
||||
|
||||
@@ -65,12 +65,9 @@ fn menu_saves_deletes_and_resets_profiles() {
|
||||
set_profile(&mut panel.app(), custom());
|
||||
menu_row(&mut panel.app(), "ui.paramDialog");
|
||||
// A name dialog (OK runs stroke.widthProfile.add).
|
||||
let ctx = panel.ctx().clone();
|
||||
let mut app = panel.app();
|
||||
let host = app.dialogs().expect("the window's dialog host");
|
||||
let id = host.with(|h| h.open_dialogs().first().map(|d| d.id)).expect("name dialog");
|
||||
host.with(|h| h.set_json_field(&ctx, id, "name", json!("Mine"))).unwrap();
|
||||
assert!(host.with(|h| h.confirm_by_id(&ctx, id)));
|
||||
let id = crate::tests::picks::open_dialogs(&app).first().map(|d| d.id).expect("name dialog");
|
||||
crate::tests::picks::answer_dialog(&mut app, id, &[("name", json!("Mine"))], true);
|
||||
assert_eq!(app.session.prefs.width_profiles[0].name, "Mine");
|
||||
// Saved profiles don't trip the Preferences dialog, which only edits preferences.
|
||||
crate::prefs_dialog::open(&mut app, None);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use crate::testing::ui_context;
|
||||
use crate::tests::picks::{answer_dialog, open_dialogs, poll, scripted};
|
||||
use crate::tests::picks::{answer_dialog, cancel_dialog, open_dialogs, poll, scripted};
|
||||
use crate::tests::synthetic::key_frame;
|
||||
use vectorcraft_doc::{NodeId, NodeKind};
|
||||
|
||||
@@ -72,6 +72,9 @@ fn is_open(app: &VectorcraftApp, key: &str) -> bool {
|
||||
fn answer(app: &mut VectorcraftApp, key: &str, fields: &[(&str, Value)], ok: bool) {
|
||||
let id = open_dialogs(app).into_iter().find(|d| d.key.as_deref() == Some(key)).map(|d| d.id).expect("the dialog is open");
|
||||
answer_dialog(app, id, fields, ok);
|
||||
if !ok {
|
||||
cancel_dialog(app, id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Names the style in the open New Style dialog and confirms it. A refused name leaves the dialog open.
|
||||
@@ -274,9 +277,10 @@ fn character_style_options_menu_opens_format_sections() {
|
||||
let body = style_id(&mut app, Kind::Char, "Body");
|
||||
act(&mut app, Kind::Char, TextStyleAction::Options(body));
|
||||
let fields = fields_of(&app, "charStyleOptions").expect("Options opens Character Style Options");
|
||||
assert_eq!(fields["style"], "Body");
|
||||
assert_eq!(fields["name"], "Body");
|
||||
assert_eq!(fields["tab"], "general");
|
||||
assert_eq!(fields["size"].as_f64(), Some(24.0));
|
||||
// The dialog holds opened numbers as their text.
|
||||
assert_eq!(fields["size"].as_f64().or_else(|| fields["size"].as_str()?.parse().ok()), Some(24.0), "{}", fields["size"]);
|
||||
assert_eq!(fields["preview"], true);
|
||||
}
|
||||
|
||||
|
||||
@@ -891,6 +891,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
let t = app.session.doc().unwrap().doc.variables.objects_of("Name")[0].0;
|
||||
// The text just made is selected.
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let nothing_picked =
|
||||
[("variable.makeTextDynamic", false), (UNBIND, false), (DELETE_VARIABLE, false), (SELECT_BOUND, false), (SELECT_ALL_BOUND, true)];
|
||||
check(&app, ¬hing_picked, "with nothing selected or highlighted");
|
||||
|
||||
Reference in New Issue
Block a user