mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-19 00:27:49 +00:00
Merge pull request #2438 from B-uchi/pr/inspect-dashcap
M8: inspect fields accepts dashCap, which node.get already writes
This commit is contained in:
2 files changed
+40
No files matched your search
@@ -27,6 +27,7 @@ pub const NODE_KEYS: &[&str] = &[
|
||||
"constraints",
|
||||
"cornerRadius",
|
||||
"cornerSmoothing",
|
||||
"dashCap",
|
||||
"dashes",
|
||||
"description",
|
||||
"devChanged",
|
||||
|
||||
@@ -561,3 +561,42 @@ fn modes_property_bindings_and_exposed_instances_are_read() {
|
||||
s.execute("component.exposeInstance", &json!({"id": nested.clone()})).unwrap();
|
||||
assert_eq!(s.execute("node.get", &json!({"id": nested})).unwrap()["exposedInstance"], true);
|
||||
}
|
||||
|
||||
/// Every key a layer's JSON can have is one `fields` accepts: a key missing from `NODE_KEYS` can be
|
||||
/// read in full output but is refused when asked for by name (`dashCap` was).
|
||||
#[test]
|
||||
fn every_key_node_get_writes_can_be_asked_for() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({})).unwrap();
|
||||
let frame = s
|
||||
.execute("node.create", &json!({"type": "frame", "width": 200, "height": 100, "props": {"layout": {"mode": "horizontal"}, "gap": 4}}))
|
||||
.unwrap()["id"]
|
||||
.clone();
|
||||
let line = s
|
||||
.execute(
|
||||
"node.create",
|
||||
&json!({"type": "line", "parent": frame, "width": 80, "props": {
|
||||
"strokes": ["#000000"], "strokeWeight": 2, "dashes": [4, 2], "dashCap": "round", "strokeJoin": "round",
|
||||
"opacity": 0.5, "visible": false, "locked": true}}),
|
||||
)
|
||||
.unwrap()["id"]
|
||||
.clone();
|
||||
s.execute("node.create", &json!({"type": "text", "parent": frame, "text": "Hi", "props": {"textDecoration": "underline"}})).unwrap();
|
||||
s.execute("annotation.add", &json!({"id": line, "label": "Note"})).unwrap();
|
||||
let mut keys = std::collections::BTreeSet::new();
|
||||
fn walk(v: &Value, keys: &mut std::collections::BTreeSet<String>) {
|
||||
if let Some(o) = v.as_object() {
|
||||
keys.extend(o.keys().cloned());
|
||||
for c in o.get("children").and_then(Value::as_array).into_iter().flatten() {
|
||||
walk(c, keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(&node_json(s.doc().unwrap(), crate::params::id_of(&frame).unwrap(), 4), &mut keys);
|
||||
assert!(keys.contains("dashCap"), "the test sets a dash cap: {keys:?}");
|
||||
for key in keys {
|
||||
assert!(crate::inspect::NODE_KEYS.contains(&key.as_str()), "`{key}` is written but `fields` refuses it");
|
||||
let one = InspectOptions::parse(&json!({"fields": [key]}));
|
||||
assert!(one.is_ok(), "{key}: {one:?}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user