mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Place Path Ops regression tests after the implementation
This commit is contained in:
1 parent
78ebac9eab
commit
00d41a7c7c
1 file changed
+96
-96
@@ -374,102 +374,6 @@ pub(crate) fn open_simplify(app: &mut VectorcraftApp, tolerance: f64) {
|
||||
open_dialog(app, PathOp::Simplify, simplify_dialog(tolerance), None);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod preview_document_tests {
|
||||
use super::*;
|
||||
use crate::dialogs::tests::{app, cancel, confirm, frame, set};
|
||||
|
||||
fn dense_path(app: &mut VectorcraftApp, top: f64) -> u64 {
|
||||
let anchors: Vec<_> = (0..20).map(|i| json!({"x": 30 + i * 15, "y": top + (i % 2) as f64 * 0.1})).collect();
|
||||
let id = app.run("path.create", json!({"anchors": anchors})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.anchors", json!({"id": id, "anchors": [[0, 19]]})).unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
fn drawings() -> (VectorcraftApp, NodeId) {
|
||||
let mut app = app();
|
||||
let id = dense_path(&mut app, 50.0);
|
||||
app.run("file.new", json!({"width": 500, "height": 400})).unwrap();
|
||||
let other = dense_path(&mut app, 180.0);
|
||||
assert_eq!(id, other, "the two drawings use the same path ID");
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
(app, NodeId(id))
|
||||
}
|
||||
|
||||
fn more_options(app: &mut VectorcraftApp) {
|
||||
crate::menus::invoke(app, "object.path.simplify", json!({}));
|
||||
crate::dialogs::simplify_slider::more_options(app).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simplify_options_skip_the_other_drawings_artwork() {
|
||||
for from_slider in [false, true] {
|
||||
let (mut app, _) = drawings();
|
||||
if from_slider {
|
||||
more_options(&mut app);
|
||||
} else {
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
set_saved_value(&ctx, &SIMPLIFY_KEY, Some(simplify_dialog(DEFAULT_TOLERANCE)));
|
||||
crate::menus::invoke(&mut app, "object.path.simplify", json!({}));
|
||||
}
|
||||
set(&mut app, "preview", json!(true));
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
let other = app.session.doc().unwrap().doc.clone();
|
||||
let undo = app.session.doc().unwrap().history.undo.len();
|
||||
|
||||
frame(&mut app, vec![]);
|
||||
|
||||
assert!(app.session.doc().unwrap().doc == other, "Simplify preview leaves the other drawing unchanged");
|
||||
assert!(!app.session.in_interaction());
|
||||
assert!(!confirm(&mut app), "the draft stays with the opening drawing");
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo);
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
frame(&mut app, vec![]);
|
||||
assert!(app.session.in_interaction());
|
||||
assert!(confirm(&mut app));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simplify_options_never_outline_another_drawings_same_id() {
|
||||
let (mut app, id) = drawings();
|
||||
more_options(&mut app);
|
||||
set(&mut app, "showOriginal", json!(true));
|
||||
set(&mut app, "preview", json!(true));
|
||||
frame(&mut app, vec![]);
|
||||
assert_eq!(original_paths(&app).iter().map(|(path, _)| *path).collect::<Vec<_>>(), [id]);
|
||||
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
app.session.begin_interaction("Other edit").unwrap();
|
||||
|
||||
assert!(original_paths(&app).is_empty(), "Show Original leaves the other drawing's canvas alone");
|
||||
assert!(cancel(&mut app));
|
||||
assert!(app.session.in_interaction(), "Cancel leaves the other drawing's edit in progress");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offset_path_skips_the_other_drawings_artwork() {
|
||||
let mut app = app();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 20, "width": 100, "height": 60})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
crate::menus::invoke(&mut app, "object.path.offsetPath", json!({}));
|
||||
set(&mut app, "offset", json!(12.0));
|
||||
set(&mut app, "preview", json!(true));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 140, "y": 30, "width": 80, "height": 100})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
let other = app.session.doc().unwrap().doc.clone();
|
||||
|
||||
frame(&mut app, vec![]);
|
||||
|
||||
assert!(app.session.doc().unwrap().doc == other, "Offset Path preview leaves the other drawing unchanged");
|
||||
assert!(!confirm(&mut app));
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
assert!(confirm(&mut app));
|
||||
assert_eq!(app.session.doc().unwrap().doc.layers[0].children().unwrap().len(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
fn open_dialog(app: &mut VectorcraftApp, op: PathOp, fields: DialogFields, remember: Option<SaveKey>) {
|
||||
let Some(ctx) = app.ui_ctx.clone() else {
|
||||
app.status("There is no window to show the dialog in.");
|
||||
@@ -677,3 +581,99 @@ pub(crate) fn original_paths(app: &VectorcraftApp) -> Vec<(NodeId, &PathData)> {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod preview_document_tests {
|
||||
use super::*;
|
||||
use crate::dialogs::tests::{app, cancel, confirm, frame, set};
|
||||
|
||||
fn dense_path(app: &mut VectorcraftApp, top: f64) -> u64 {
|
||||
let anchors: Vec<_> = (0..20).map(|i| json!({"x": 30 + i * 15, "y": top + (i % 2) as f64 * 0.1})).collect();
|
||||
let id = app.run("path.create", json!({"anchors": anchors})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.anchors", json!({"id": id, "anchors": [[0, 19]]})).unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
fn drawings() -> (VectorcraftApp, NodeId) {
|
||||
let mut app = app();
|
||||
let id = dense_path(&mut app, 50.0);
|
||||
app.run("file.new", json!({"width": 500, "height": 400})).unwrap();
|
||||
let other = dense_path(&mut app, 180.0);
|
||||
assert_eq!(id, other, "the two drawings use the same path ID");
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
(app, NodeId(id))
|
||||
}
|
||||
|
||||
fn more_options(app: &mut VectorcraftApp) {
|
||||
crate::menus::invoke(app, "object.path.simplify", json!({}));
|
||||
crate::dialogs::simplify_slider::more_options(app).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simplify_options_skip_the_other_drawings_artwork() {
|
||||
for from_slider in [false, true] {
|
||||
let (mut app, _) = drawings();
|
||||
if from_slider {
|
||||
more_options(&mut app);
|
||||
} else {
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
set_saved_value(&ctx, &SIMPLIFY_KEY, Some(simplify_dialog(DEFAULT_TOLERANCE)));
|
||||
crate::menus::invoke(&mut app, "object.path.simplify", json!({}));
|
||||
}
|
||||
set(&mut app, "preview", json!(true));
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
let other = app.session.doc().unwrap().doc.clone();
|
||||
let undo = app.session.doc().unwrap().history.undo.len();
|
||||
|
||||
frame(&mut app, vec![]);
|
||||
|
||||
assert!(app.session.doc().unwrap().doc == other, "Simplify preview leaves the other drawing unchanged");
|
||||
assert!(!app.session.in_interaction());
|
||||
assert!(!confirm(&mut app), "the draft stays with the opening drawing");
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo);
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
frame(&mut app, vec![]);
|
||||
assert!(app.session.in_interaction());
|
||||
assert!(confirm(&mut app));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simplify_options_never_outline_another_drawings_same_id() {
|
||||
let (mut app, id) = drawings();
|
||||
more_options(&mut app);
|
||||
set(&mut app, "showOriginal", json!(true));
|
||||
set(&mut app, "preview", json!(true));
|
||||
frame(&mut app, vec![]);
|
||||
assert_eq!(original_paths(&app).iter().map(|(path, _)| *path).collect::<Vec<_>>(), [id]);
|
||||
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
app.session.begin_interaction("Other edit").unwrap();
|
||||
|
||||
assert!(original_paths(&app).is_empty(), "Show Original leaves the other drawing's canvas alone");
|
||||
assert!(cancel(&mut app));
|
||||
assert!(app.session.in_interaction(), "Cancel leaves the other drawing's edit in progress");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offset_path_skips_the_other_drawings_artwork() {
|
||||
let mut app = app();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 20, "width": 100, "height": 60})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
crate::menus::invoke(&mut app, "object.path.offsetPath", json!({}));
|
||||
set(&mut app, "offset", json!(12.0));
|
||||
set(&mut app, "preview", json!(true));
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 140, "y": 30, "width": 80, "height": 100})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
let other = app.session.doc().unwrap().doc.clone();
|
||||
|
||||
frame(&mut app, vec![]);
|
||||
|
||||
assert!(app.session.doc().unwrap().doc == other, "Offset Path preview leaves the other drawing unchanged");
|
||||
assert!(!confirm(&mut app));
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
assert!(confirm(&mut app));
|
||||
assert_eq!(app.session.doc().unwrap().doc.layers[0].children().unwrap().len(), 2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user