Scripts: tests index page items topmost first and check the preset fallback

Cause of the script_dom and script_dom_paths failures: main's 9872e6b679
("page items report their own members, and lists start with the topmost
object") made pageItems, pathItems and the selection list art topmost first.
The branch's tests still indexed the objects bottom first, so pageItems[1]
and pathItems[0] named the other object. The tests now make the objects in
the order the lists read them, and index them topmost first.

The own-members test asked about rotate, which this branch makes available,
so it now asks about transform, which is not available yet.

The fallback test for addDocument relied on five 1,000,000 pt artboards not
fitting, but a new DocumentPreset puts them in one column. It now unsets the
layout so the built-in preset puts them in one row, and the test fails when
addDocument falls back to the saved preset of the same name.
This commit is contained in:
dotCooCoo committed 2026-11-29 04:41:14 -08:00
1 parent 4b7ac69692
commit dd93247cbf
2 files changed
+16 -7

No files matched your search

+11 -4
View File
@@ -1081,10 +1081,11 @@ fn selecting_an_item_keeps_the_direct_selected_anchors_of_others() {
s.execute("select.add", &json!({"ids": [b.0]})).unwrap();
let anchors = s.active().unwrap().selection.anchors.clone();
assert!(anchors.contains_key(&a));
log(&mut s, "app.activeDocument.pageItems[1].selected = false;");
// Lists start with the topmost object, so `b` is `pageItems[0]`.
log(&mut s, "app.activeDocument.pageItems[0].selected = false;");
let sel = &s.active().unwrap().selection;
assert_eq!((sel.objects.clone(), sel.anchors.clone()), (vec![a], anchors.clone()));
log(&mut s, "app.activeDocument.pageItems[1].selected = true;");
log(&mut s, "app.activeDocument.pageItems[0].selected = true;");
let sel = &s.active().unwrap().selection;
assert_eq!((sel.objects.clone(), sel.anchors.get(&a)), (vec![a, b], anchors.get(&a)));
}
@@ -1506,7 +1507,13 @@ fn document_preset_applies_only_its_given_fields() {
assert_eq!(s.documents().len(), 2, "a refused preset makes no document");
// A saved preset with the built-in preset's name does not make the refused settings fit.
s.execute("file.newPresets.save", &json!({"name": "Letter", "artboardLayout": "column"})).unwrap();
let e = failure(&mut s, "var p = new DocumentPreset(); p.width = 1000000; p.numArtboards = 5; app.documents.addDocument('Print', p);");
// With the layout unset, the built-in preset puts the five 1,000,000 pt artboards in one row,
// which does not fit, while the saved preset would put them in one column.
let e = failure(
&mut s,
"var p = new DocumentPreset(); p.width = 1000000; p.numArtboards = 5;\
p.artboardLayout = undefined; p.artboardRowsOrCols = undefined; app.documents.addDocument('Print', p);",
);
assert!(e.contains("don't fit"), "{e}");
assert_eq!(s.documents().len(), 2, "settings the built-in preset refuses make no document");
}
@@ -2181,7 +2188,7 @@ fn page_items_report_their_available_members_as_their_own() {
vc.log([p.hasOwnProperty('opacity'), p.hasOwnProperty('typename'), p.hasOwnProperty('duplicate'),\
Object.prototype.hasOwnProperty.call(p, 'name'), p.propertyIsEnumerable('opacity'), d.hasOwnProperty('selection'),\
app.hasOwnProperty('activeDocument')]);\
vc.log([p.hasOwnProperty('isIsolated'), p.hasOwnProperty('rotate'), d.hasOwnProperty('layers'),\
vc.log([p.hasOwnProperty('isIsolated'), p.hasOwnProperty('transform'), d.hasOwnProperty('layers'),\
p.hasOwnProperty('nosuch'), p.hasOwnProperty('hasOwnProperty'), p.hasOwnProperty('constructor')]);\
vc.log([keys.indexOf('opacity') >= 0, keys.indexOf('typename') >= 0, keys.indexOf('duplicate'), keys.indexOf('isIsolated')]);",
);
+5 -3
View File
@@ -26,12 +26,13 @@ fn rect(s: &mut Session, x: f64, y: f64, w: f64, h: f64) -> NodeId {
NodeId(s.execute("shape.rectangle", &json!({"x": x, "y": y, "width": w, "height": h})).unwrap()["id"].as_u64().unwrap())
}
/// A 400 × 300 pt document with two rectangles.
/// A 400 × 300 pt document with two rectangles, `a` above `b`. Lists start with the topmost
/// object, so `a` is `pathItems[0]` and `b` is `pathItems[1]`.
fn doc() -> (Session, NodeId, NodeId) {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
let a = rect(&mut s, 10.0, 20.0, 30.0, 40.0);
let b = rect(&mut s, 100.0, 100.0, 50.0, 50.0);
let a = rect(&mut s, 10.0, 20.0, 30.0, 40.0);
s.execute("select.none", &json!({})).unwrap();
(s, a, b)
}
@@ -880,7 +881,8 @@ fn locked_paths_and_wrong_objects_are_refused() {
}
assert_eq!(art(&s), before);
s.execute("text.create", &json!({"x": 10, "y": 250, "text": "hi"})).unwrap();
let e = failure(&mut s, "var t = app.activeDocument.pageItems[2]; Object.getOwnPropertyDescriptor(PathItem.prototype, 'closed').get.call(t);");
// The text is the topmost object, and lists start with the topmost object.
let e = failure(&mut s, "var t = app.activeDocument.pageItems[0]; Object.getOwnPropertyDescriptor(PathItem.prototype, 'closed').get.call(t);");
assert!(e.contains("not a PathItem"), "{e}");
let e = failure(&mut s, "Object.getOwnPropertyDescriptor(PathPoint.prototype, 'anchor').get.call({});");
assert!(e.contains("not a PathPoint"), "{e}");