mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 22:08:42 +00:00
Port tests to the ruler's relative indents, the dialogs' own fields and numeric params
Ruler edits move the first-line indent relative to the left one (RulerValues); swatch dialogs are read by their name and from fields, a new swatch's group is checked after OK; the bullets loop picks None last; 3D settings compare as numbers, as whole numbers are stored as integers.
This commit is contained in:
@@ -476,7 +476,8 @@ fn the_bullets_button_and_its_presets_set_the_list_and_reset_panel_clears_it() {
|
||||
toggle_list(&mut app, ListKind::Bullets);
|
||||
assert_eq!(lists(&app), (Some(ParaList::bulleted(Bullet::Dot)), None), "the caret's paragraph");
|
||||
assert_eq!(bullets_shown(&app), Some(Some(Bullet::Dot)), "the button shows pressed");
|
||||
for (_, key, bullet) in bullet_presets() {
|
||||
// None, the first preset, is picked last.
|
||||
for (_, key, bullet) in bullet_presets().into_iter().rev() {
|
||||
set_bullet(&mut app, key);
|
||||
assert_eq!(lists(&app), (bullet.map(ParaList::bulleted), None), "{key}");
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ fn double_click_opens_swatch_options_and_ok_edits_linked_art() {
|
||||
app.run("paint.setFill", json!({"ids": [id], "swatch": "Red"})).unwrap();
|
||||
let ctx = context(&app);
|
||||
activated(&mut app, "Red");
|
||||
assert_eq!((dialog_field(&app, KIND, "__swatch"), dialog_field(&app, KIND, "mode")), (json!("Red"), json!("rgb")));
|
||||
assert_eq!((dialog_field(&app, KIND, "name"), dialog_field(&app, KIND, "mode")), (json!("Red"), json!("rgb")));
|
||||
// The dialog previews live on the canvas; OK keeps the edit as one undo step.
|
||||
let undo = undo_steps(&app);
|
||||
dialog_frame(&mut app, &ctx);
|
||||
@@ -354,7 +354,8 @@ fn new_swatch_dialog_prefills_the_active_colour_and_saves_into_the_selected_grou
|
||||
let key = crate::dialogs::new_swatch::KIND;
|
||||
app.run("paint.setFill", json!({"color": "#ff8000"})).unwrap();
|
||||
new_swatch(&mut app, &["Bright Red".into()], cmd());
|
||||
assert_eq!((dialog_field(&app, key, "name"), dialog_field(&app, key, "group")), (json!("R=255 G=128 B=0"), json!("Brights")));
|
||||
// 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)),
|
||||
@@ -429,7 +430,7 @@ fn new_color_group_dialog_makes_a_group_from_swatches_or_artwork() {
|
||||
let ctx = context(&app);
|
||||
let key = crate::dialogs::new_color_group::KIND;
|
||||
app.run("ui.newColorGroup", json!({"swatches": ["Red", "Sunset"]})).unwrap();
|
||||
assert_eq!((dialog_field(&app, key, "name"), dialog_field(&app, key, "fromArtwork")), (json!("Color Group"), json!(false)));
|
||||
assert_eq!((dialog_field(&app, key, "name"), dialog_field(&app, key, "from")), (json!("Color Group"), json!("swatches")));
|
||||
dialog_frame(&mut app, &ctx);
|
||||
confirm(&mut app, key);
|
||||
let d = doc(&app);
|
||||
@@ -442,8 +443,8 @@ fn new_color_group_dialog_makes_a_group_from_swatches_or_artwork() {
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
app.run("ui.newColorGroup", json!({})).unwrap();
|
||||
assert_eq!(
|
||||
(dialog_field(&app, key, "name"), dialog_field(&app, key, "fromArtwork"), dialog_field(&app, key, "toGlobal")),
|
||||
(json!("Color Group 2"), json!(true), json!(true))
|
||||
(dialog_field(&app, key, "name"), dialog_field(&app, key, "from"), dialog_field(&app, key, "toGlobal")),
|
||||
(json!("Color Group 2"), json!("artwork"), json!(true))
|
||||
);
|
||||
dialog_frame(&mut app, &ctx);
|
||||
confirm(&mut app, key);
|
||||
@@ -880,7 +881,7 @@ fn the_active_tint_or_gradient_swatch_is_highlighted_and_a_tint_edits_its_base()
|
||||
app.run("paint.setFill", json!({"swatch": "Sunset"})).unwrap();
|
||||
assert_eq!(active_swatch(&app).as_deref(), Some("Sunset"), "the applied gradient swatch");
|
||||
app.run("ui.swatchOptions", json!({"name": "Ink 40%"})).unwrap();
|
||||
assert_eq!(dialog_field(&app, KIND, "__swatch"), json!("Ink"), "a tint swatch opens its base's options");
|
||||
assert_eq!(dialog_field(&app, KIND, "name"), json!("Ink"), "a tint swatch opens its base's options");
|
||||
}
|
||||
|
||||
/// Selecting art scrolls the tiles to its swatch, once, and clears the panel's own selection so
|
||||
@@ -1025,12 +1026,12 @@ fn color_group_options_opens_on_a_sole_selected_group() {
|
||||
}
|
||||
select_rows(&mut app, &["Grays"]);
|
||||
app.run("ui.colorGroupOptions", json!({})).unwrap();
|
||||
assert_eq!(dialog_field(&app, key, "__group"), json!("Grays"));
|
||||
assert_eq!(dialog_field(&app, key, "name"), json!("Grays"));
|
||||
set_field(&mut app, key, "name", json!("Neutrals"));
|
||||
confirm(&mut app, key);
|
||||
assert_eq!(selected(&app), ["Neutrals"]);
|
||||
app.run("ui.colorGroupOptions", json!({})).unwrap();
|
||||
assert_eq!(dialog_field(&app, key, "__group"), json!("Neutrals"));
|
||||
assert_eq!(dialog_field(&app, key, "name"), json!("Neutrals"));
|
||||
cancel(&mut app, key);
|
||||
// The command run on its own, and as batch steps, keeps the selection the same way.
|
||||
app.run("swatch.renameGroup", json!({"group": "Neutrals", "name": "Stone"})).unwrap();
|
||||
@@ -1051,7 +1052,7 @@ fn color_group_options_without_a_group_opens_on_the_selected_group() {
|
||||
let key = crate::dialogs::color_group_options::KIND;
|
||||
select_rows(&mut app, &["Grays"]);
|
||||
app.run("ui.colorGroupOptions", json!({})).unwrap();
|
||||
assert_eq!(dialog_field(&app, key, "__group"), json!("Grays"));
|
||||
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);
|
||||
|
||||
@@ -17,6 +17,18 @@ fn move_box(v: &mut RulerValues, by: f32) {
|
||||
v.left_indent += by;
|
||||
}
|
||||
|
||||
/// Moves the upper (first-line) marker to `at` points, as its drag does: the first line's indent is
|
||||
/// relative to the left one.
|
||||
fn upper_to(v: &mut RulerValues, at: f32) {
|
||||
v.first_line_indent = at - v.left_indent;
|
||||
}
|
||||
|
||||
/// Moves the lower (left) marker alone to `at` points, as its drag does: the first line stays where it is.
|
||||
fn lower_to(v: &mut RulerValues, at: f32) {
|
||||
v.first_line_indent -= at - v.left_indent;
|
||||
v.left_indent = at;
|
||||
}
|
||||
|
||||
/// A left-aligned stop with no leader at `position`, as a click on the ruler adds one.
|
||||
fn stop_at(position: f32) -> RulerStop {
|
||||
RulerStop::new(position, RulerAlign::Left, TabLeader::None)
|
||||
@@ -116,13 +128,13 @@ fn indent_values(app: &VectorcraftApp, paragraph: usize) -> (f64, f64) {
|
||||
fn upper_and_lower_marker_drags_map_indents_and_undo_once() {
|
||||
let mut app = indent_app(24.0, 12.0);
|
||||
let before = app.session.active().unwrap().history.undo.len();
|
||||
edit_ruler(&mut app, |v| v.first_line_indent = 60.0);
|
||||
edit_ruler(&mut app, |v| upper_to(v, 60.0));
|
||||
assert_eq!(indent_values(&app, 0), (24.0, 36.0));
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), before + 1);
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(indent_values(&app, 0), (24.0, 12.0));
|
||||
let before = app.session.active().unwrap().history.undo.len();
|
||||
edit_ruler(&mut app, |v| v.left_indent = 40.0);
|
||||
edit_ruler(&mut app, |v| lower_to(v, 40.0));
|
||||
assert_eq!(indent_values(&app, 0), (40.0, -4.0));
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), before + 1);
|
||||
let before = app.session.active().unwrap().history.undo.len();
|
||||
@@ -137,7 +149,7 @@ fn mixed_indent_upper_marker_keeps_each_left_indent_in_one_undo_step() {
|
||||
let id = current(&app).unwrap().0.id.0;
|
||||
app.run("text.setFormat", json!({"id": id, "start": 4, "end": 4, "leftIndent": 60, "firstLineIndent": -10})).unwrap();
|
||||
let before = app.session.active().unwrap().history.undo.len();
|
||||
edit_ruler(&mut app, |v| v.first_line_indent = 70.0);
|
||||
edit_ruler(&mut app, |v| upper_to(v, 70.0));
|
||||
assert_eq!(indent_values(&app, 0), (24.0, 46.0));
|
||||
assert_eq!(indent_values(&app, 1), (60.0, 10.0));
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), before + 1);
|
||||
@@ -153,7 +165,7 @@ fn mixed_indent_upper_marker_keeps_each_left_indent_in_one_undo_step() {
|
||||
app.run("text.setFormat", json!({"id": b, "leftIndent": 60, "firstLineIndent": -10})).unwrap();
|
||||
app.run("select.set", json!({"ids": [a, b.clone()]})).unwrap();
|
||||
assert_eq!(current_para(&app).unwrap().1.left_indent, 24.0);
|
||||
edit_ruler(&mut app, |v| v.first_line_indent = 70.0);
|
||||
edit_ruler(&mut app, |v| upper_to(v, 70.0));
|
||||
assert_eq!(indent_values(&app, 0), (24.0, 46.0));
|
||||
let second = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(b.as_u64().unwrap())).unwrap();
|
||||
let NodeKind::Text(second) = &second.kind else { panic!("second text") };
|
||||
@@ -168,7 +180,7 @@ fn lower_marker_keeps_each_first_line_position_in_one_undo_step() {
|
||||
assert_eq!(indent_values(&app, 0), (24.0, 12.0));
|
||||
assert_eq!(indent_values(&app, 1), (24.0, 28.0));
|
||||
let before = app.session.active().unwrap().history.undo.len();
|
||||
edit_ruler(&mut app, |v| v.left_indent = 40.0);
|
||||
edit_ruler(&mut app, |v| lower_to(v, 40.0));
|
||||
assert_eq!(indent_values(&app, 0), (40.0, -4.0));
|
||||
assert_eq!(indent_values(&app, 1), (40.0, 12.0));
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), before + 1);
|
||||
@@ -590,9 +602,9 @@ fn indent_markers_show_and_set_a_list_paragraphs_laid_out_indent() {
|
||||
assert_eq!((marker_position(IndentMarker::Lower, ¶), marker_position(IndentMarker::Upper, ¶)), (28.0, 34.0));
|
||||
edit_ruler(&mut app, |v| move_box(v, 12.0));
|
||||
assert_eq!(indent_values(&app, 0), (22.0, 6.0), "the ruler's 40 pt is the paragraph's 22 pt and the level's 18");
|
||||
edit_ruler(&mut app, |v| v.first_line_indent = 70.0);
|
||||
edit_ruler(&mut app, |v| upper_to(v, 70.0));
|
||||
assert_eq!(indent_values(&app, 0), (22.0, 30.0));
|
||||
edit_ruler(&mut app, |v| v.left_indent = 20.0);
|
||||
edit_ruler(&mut app, |v| lower_to(v, 20.0));
|
||||
assert_eq!(indent_values(&app, 0), (2.0, 50.0), "the first line stays at 70 pt");
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ fn a_drag_previews_and_records_one_undo_step_when_released() {
|
||||
commit(&mut app, GESTURE, before);
|
||||
assert_eq!(undo_len(&app), history + 1);
|
||||
let (_, params) = effect(&app);
|
||||
assert_eq!((params["depth"].clone(), params["twist"].clone()), (json!(120.0), json!(45.0)));
|
||||
assert_eq!((params["depth"].as_f64(), params["twist"].as_f64()), (Some(120.0), Some(45.0)));
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(effect(&app).1["depth"], 50.0);
|
||||
// A typed value is one undo step at once.
|
||||
@@ -588,10 +588,12 @@ fn the_bevel_reset_restores_only_the_bevel_settings_of_each_selected_effect() {
|
||||
};
|
||||
for id in [a, b] {
|
||||
for key in ["bevel", "bevelWidth", "bevelHeight", "bevelRepeat", "bevelSpace", "bevelInside", "bevelBothSides"] {
|
||||
assert_eq!(merged(&app, id)[key], defaults[key], "{key} of {id}");
|
||||
// A whole number the panel wrote is a JSON integer: the same number as the default's.
|
||||
let (got, want) = (&merged(&app, id)[key], &defaults[key]);
|
||||
assert!(got == want || got.as_f64().is_some_and(|v| Some(v) == want.as_f64()), "{key} of {id}: {got} for {want}");
|
||||
}
|
||||
}
|
||||
assert_eq!((merged(&app, a)["depth"].clone(), merged(&app, b)["depth"].clone()), (json!(70.0), json!(30.0)));
|
||||
assert_eq!((merged(&app, a)["depth"].as_f64(), merged(&app, b)["depth"].as_f64()), (Some(70.0), Some(30.0)));
|
||||
assert_eq!(merged(&app, a)["rotationX"], 15.0);
|
||||
let nodes = controls(&mut app, &ctx);
|
||||
assert!(named(&nodes, "Reset").is_disabled(), "every bevel setting at its default: Reset is off");
|
||||
|
||||
Reference in New Issue
Block a user