Tests: check representative raster effects in the catalog test

listed_applied_edited_and_undone checks five representative catalog entries and an unknown effect id instead of every raster effect, and applies out-of-range parameters to Radial Blur and Unsharp Mask. Every effect is still drawn by each_effect_changes_the_canvas_and_draws_the_same_twice.
This commit is contained in:
dotCooCoo committed 2026-11-30 21:36:06 -08:00
1 parent 84335645da
commit 9b65da9150
1 file changed
+14 -24
+14 -24
View File
@@ -119,33 +119,23 @@ fn mean_diff(a: &Rendered, b: &Rendered) -> f64 {
fn listed_applied_edited_and_undone() {
let (mut s, g) = striped();
let list = s.execute("effect.list", &json!({})).unwrap();
for (id, _) in EFFECTS {
let e = list["catalog"].as_array().unwrap().iter().find(|e| e["id"] == id).unwrap_or_else(|| panic!("{id} listed"));
assert_eq!(e["raster"], json!(true), "{id}");
assert!(e["params"].as_str().unwrap().contains("radius") || id == "blur.radial", "{id}");
}
let menus: Vec<Value> =
EFFECTS.iter().map(|(id, _)| list["catalog"].as_array().unwrap().iter().find(|e| e["id"] == *id).unwrap()["menu"].clone()).collect();
assert_eq!(menus, [json!(["Effect", "Blur"]), json!(["Effect", "Blur"]), json!(["Effect", "Sharpen"])]);
for (group, menu) in [
(ARTISTIC.as_slice(), "Artistic"),
(BRUSH_STROKES.as_slice(), "Brush Strokes"),
(DISTORT.as_slice(), "Distort"),
(PIXELATE.as_slice(), "Pixelate"),
(SKETCH.as_slice(), "Sketch"),
(TEXTURE.as_slice(), "Texture"),
(VIDEO.as_slice(), "Video"),
([("video.ntscColors", "{}")].as_slice(), "Video"),
// A few representative entries, one per kind of submenu, are listed as raster effects.
for (id, menu) in [
("blur.radial", "Blur"),
("sharpen.unsharpMask", "Sharpen"),
("artistic.cutout", "Artistic"),
("sketch.chrome", "Sketch"),
("video.ntscColors", "Video"),
] {
for (id, _) in group {
let e = list["catalog"].as_array().unwrap().iter().find(|e| e["id"] == *id).unwrap_or_else(|| panic!("{id} listed"));
assert_eq!((&e["raster"], &e["menu"]), (&json!(true), &json!(["Effect", menu])), "{id}");
}
let e = list["catalog"].as_array().unwrap().iter().find(|e| e["id"] == id).unwrap_or_else(|| panic!("{id} listed"));
assert_eq!((&e["raster"], &e["menu"]), (&json!(true), &json!(["Effect", menu])), "{id}");
}
assert!(list["catalog"].as_array().unwrap().iter().all(|e| e["id"] != "blur.notAnEffect"));
assert!(s.execute("effect.apply", &json!({"effect": "blur.notAnEffect", "ids": [g]})).is_err());
// Numbers far out of range are stored as given and read clamped; the canvas still draws.
// Radial Blur's Blur Center is refused outside 0 to 1 instead.
let center = |id: &str, k: &str| id == "blur.radial" && matches!(k, "centerX" | "centerY");
for (id, _) in EFFECTS {
for id in ["blur.radial", "sharpen.unsharpMask"] {
let defaults = vectorcraft_render::effects::default_params(id).unwrap();
let junk: serde_json::Map<String, Value> = defaults
.as_object()
@@ -161,11 +151,11 @@ fn listed_applied_edited_and_undone() {
assert!(s.execute("effect.apply", &json!({"effect": "blur.radial", "ids": [g], "params": {"centerX": 1e308}})).is_err());
let _ = render(&s);
let n = s.doc().unwrap().doc.node(NodeId(g)).unwrap().clone();
assert_eq!(n.appearance.effects.len(), 3);
assert_eq!(n.appearance.effects.len(), 2);
assert_eq!(n.appearance.effects[0].params["method"], json!("spin"), "defaults fill the rest");
s.execute("effect.setParams", &json!({"index": 0, "ids": [g], "params": {"method": "zoom"}})).unwrap();
assert_eq!(s.doc().unwrap().doc.node(NodeId(g)).unwrap().appearance.effects[0].params["method"], json!("zoom"));
for _ in 0..4 {
for _ in 0..3 {
s.execute("edit.undo", &json!({})).unwrap();
}
assert!(s.doc().unwrap().doc.node(NodeId(g)).unwrap().appearance.effects.is_empty());