@blackbelt-technology/pi-dashboard-forms-bpmn 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/.pi/skills/bpmn-package-explorer/SKILL.md +15 -9
  2. package/.pi/skills/bpmn-package-explorer/scripts/fixtures.mjs +6 -1
  3. package/.pi/skills/bpmn-package-explorer/scripts/generate-cli.mjs +1 -1
  4. package/.pi/skills/bpmn-package-explorer/scripts/render.mjs +3 -2
  5. package/.pi/skills/bpmn-package-explorer/scripts/serve.mjs +91 -0
  6. package/.pi/skills/bpmn-package-explorer/scripts/view-cli.mjs +1 -1
  7. package/.pi/skills/bpmn-package-explorer/templates/shell.html +12 -1
  8. package/.pi/skills/bpmn-package-explorer/templates/viewer.js +52 -5
  9. package/.pi/skills/openforms-mui/tools/package-lock.json +0 -42
  10. package/.pi/skills/openforms-mui/tools/src/fields/FieldRenderer.tsx +5 -0
  11. package/.pi/skills/openforms-mui/tools/src/fields/RepeaterField.tsx +4 -2
  12. package/.pi/skills/openforms-mui/tools/src/fields/renderer-registry.ts +43 -0
  13. package/NOTICE +0 -6
  14. package/README.md +12 -9
  15. package/package.json +8 -6
  16. package/.pi/skills/canvas-webapp/SKILL.md +0 -104
  17. package/.pi/skills/openforms-mui/tools/tests/a11y.test.tsx +0 -82
  18. package/.pi/skills/openforms-mui/tools/tests/cli.test.ts +0 -74
  19. package/.pi/skills/openforms-mui/tools/tests/component.test.tsx +0 -295
  20. package/.pi/skills/openforms-mui/tools/tests/diagnose.test.ts +0 -163
  21. package/.pi/skills/openforms-mui/tools/tests/fixtures/all-field-types.json +0 -45
  22. package/.pi/skills/openforms-mui/tools/tests/logic.test.ts +0 -175
  23. package/.pi/skills/openforms-mui/tools/tests/normalize.test.ts +0 -105
  24. package/.pi/skills/openforms-mui/tools/tests/reference-semantics.test.ts +0 -131
  25. package/.pi/skills/openforms-mui/tools/tests/responsive.test.tsx +0 -158
  26. package/.pi/skills/openforms-mui/tools/tests/setup.ts +0 -16
  27. package/.pi/skills/openforms-mui/tools/tests/singleton.test.tsx +0 -31
  28. package/.pi/skills/openforms-mui/tools/tests/theme.test.ts +0 -65
  29. package/.pi/skills/openforms-mui/tools/tests/toolchain.test.ts +0 -33
  30. package/.pi/skills/openforms-mui/tools/tests/validation.test.ts +0 -222
@@ -1,163 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { normalizeSchema } from "../src/schema/normalize";
3
- import { diagnose } from "../src/schema/diagnose";
4
- import type { Field, FormSchemaJSON, Row } from "../src/schema/types";
5
-
6
- function schemaWithFields(fields: Field[], extra?: Partial<FormSchemaJSON>): FormSchemaJSON {
7
- return normalizeSchema({
8
- pages: [{ sections: [{ rows: [{ columns: [{ fields }] }] }] }],
9
- ...extra,
10
- }).schema;
11
- }
12
-
13
- function codes(schema: FormSchemaJSON): string[] {
14
- return diagnose(schema).map((d) => d.code);
15
- }
16
-
17
- describe("diagnose (tasks 2.5, 2.6, 2.8)", () => {
18
- it("reports duplicate keys as errors", () => {
19
- const s = schemaWithFields([
20
- { type: "text", key: "dup" },
21
- { type: "text", key: "dup" },
22
- ]);
23
- const f = diagnose(s).find((d) => d.code === "duplicate-key");
24
- expect(f?.severity).toBe("error");
25
- });
26
-
27
- it("reports a repeater nested in a repeater", () => {
28
- const innerRow: Row = { columns: [{ fields: [{ type: "repeater", key: "inner", rows: [] }] }] };
29
- const s = schemaWithFields([{ type: "repeater", key: "outer", rows: [innerRow] }]);
30
- expect(codes(s)).toContain("repeater-in-repeater");
31
- });
32
-
33
- it("reports a matrix nested in a repeater", () => {
34
- const innerRow: Row = { columns: [{ fields: [{ type: "matrix", key: "m", matrixRows: [] }] }] };
35
- const s = schemaWithFields([{ type: "repeater", key: "outer", rows: [innerRow] }]);
36
- expect(codes(s)).toContain("matrix-in-repeater");
37
- });
38
-
39
- it("reports an inert conditionalRules on a repeater child", () => {
40
- const innerRow: Row = {
41
- columns: [
42
- {
43
- fields: [
44
- {
45
- type: "text",
46
- key: "child",
47
- conditionalRules: [
48
- { targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "outer", operator: "equals", equalsValue: "x" }] }] },
49
- ],
50
- },
51
- ],
52
- },
53
- ],
54
- };
55
- const s = schemaWithFields([{ type: "repeater", key: "outer", rows: [innerRow] }]);
56
- expect(codes(s)).toContain("inert-repeater-child-rule");
57
- });
58
-
59
- it("reports empty andGroups and empty condition groups", () => {
60
- const s = schemaWithFields([
61
- { type: "text", key: "trigger" },
62
- {
63
- type: "text",
64
- key: "a",
65
- conditionalRules: [{ targetProperty: "visibility", andGroups: [] }],
66
- },
67
- {
68
- type: "text",
69
- key: "b",
70
- conditionalRules: [{ targetProperty: "visibility", andGroups: [{ conditions: [] }] }],
71
- },
72
- ]);
73
- const c = codes(s);
74
- expect(c).toContain("empty-and-groups");
75
- expect(c).toContain("empty-condition-group");
76
- });
77
-
78
- it("reports an unrecognised operator", () => {
79
- const s = schemaWithFields([
80
- { type: "text", key: "trigger" },
81
- {
82
- type: "text",
83
- key: "a",
84
- conditionalRules: [
85
- { targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "trigger", operator: "wat" }] }] },
86
- ],
87
- },
88
- ]);
89
- expect(codes(s)).toContain("unrecognised-operator");
90
- });
91
-
92
- it("reports contains against a checkbox", () => {
93
- const s = schemaWithFields([
94
- { type: "checkbox", key: "cb", options: [{ value: "x", label: "X" }] },
95
- {
96
- type: "text",
97
- key: "a",
98
- conditionalRules: [
99
- { targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "cb", operator: "contains", equalsValue: "x" }] }] },
100
- ],
101
- },
102
- ]);
103
- expect(codes(s)).toContain("contains-on-checkbox");
104
- });
105
-
106
- it("reports optionsType api", () => {
107
- const s = schemaWithFields([
108
- { type: "dropdown", key: "d", optionsType: "api", optionsUrl: "https://x" },
109
- ]);
110
- expect(codes(s)).toContain("options-api-unsupported");
111
- });
112
-
113
- it("reports dangling dependent and compare references", () => {
114
- const s = schemaWithFields([
115
- { type: "text", key: "a" },
116
- {
117
- type: "text",
118
- key: "b",
119
- conditionalRules: [
120
- { targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "ghost", operator: "equals", equalsValue: "1" }] }] },
121
- ],
122
- },
123
- {
124
- type: "text",
125
- key: "c",
126
- conditionalRules: [
127
- { targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "a", operator: "equals", compareMode: "field", compareToFieldKey: "phantom" }] }] },
128
- ],
129
- },
130
- ]);
131
- const c = codes(s);
132
- expect(c).toContain("dangling-dependent-field");
133
- expect(c).toContain("dangling-compare-field");
134
- });
135
-
136
- it("reports isVisibleOnForm without isCalculated", () => {
137
- const s = schemaWithFields([{ type: "number", key: "n", isVisibleOnForm: false }]);
138
- expect(codes(s)).toContain("isvisibleonform-without-calculated");
139
- });
140
-
141
- it("reports an unparseable formula", () => {
142
- const s = schemaWithFields([
143
- { type: "number", key: "n", isCalculated: true, formulaExpression: "alert(1)" },
144
- ]);
145
- expect(codes(s)).toContain("unparseable-formula");
146
- });
147
-
148
- it("reports a dangling cross-field target", () => {
149
- const s = schemaWithFields(
150
- [{ type: "text", key: "a" }],
151
- { crossFieldRules: [{ andGroups: [{ conditions: [{ dependentFieldKey: "a", operator: "equals", equalsValue: "1" }] }], targetFields: ["nope"], errorMessage: "e" }] },
152
- );
153
- expect(codes(s)).toContain("dangling-target-field");
154
- });
155
-
156
- it("produces no error findings for a clean schema", () => {
157
- const s = schemaWithFields([
158
- { type: "text", key: "a" },
159
- { type: "number", key: "n", isCalculated: true, formulaExpression: "{a} + 1" },
160
- ]);
161
- expect(diagnose(s).filter((d) => d.severity === "error")).toHaveLength(0);
162
- });
163
- });
@@ -1,45 +0,0 @@
1
- {
2
- "formTitle": "All Field Types",
3
- "formDescription": "A fixture exercising every one of the 14 upstream field types.",
4
- "pages": [
5
- {
6
- "title": "Details",
7
- "sections": [
8
- {
9
- "title": "Section A",
10
- "rows": [
11
- { "columns": [{ "width": 12, "fields": [{ "type": "header", "key": "hdr", "label": "Applicant" }] }] },
12
- { "columns": [{ "width": 12, "fields": [{ "type": "paragraph", "key": "intro", "label": "Please complete all fields." }] }] },
13
- { "columns": [
14
- { "width": 6, "fields": [{ "type": "text", "key": "firstName", "label": "First name", "required": true }] },
15
- { "width": 6, "fields": [{ "type": "text", "key": "lastName", "label": "Last name" }] }
16
- ] },
17
- { "columns": [{ "width": 12, "fields": [{ "type": "textarea", "key": "bio", "label": "About you", "rows": 3 }] }] },
18
- { "columns": [
19
- { "width": 6, "fields": [{ "type": "number", "key": "hours", "label": "Hours" }] },
20
- { "width": 6, "fields": [{ "type": "number", "key": "rate", "label": "Rate" }] }
21
- ] },
22
- { "columns": [{ "width": 6, "fields": [{ "type": "number", "key": "total", "label": "Total", "isCalculated": true, "formulaExpression": "{hours} * {rate}" }] }] },
23
- { "columns": [{ "width": 6, "fields": [{ "type": "date", "key": "startDate", "label": "Start date" }] }] },
24
- { "columns": [{ "width": 12, "fields": [{ "type": "boolean", "key": "agree", "label": "I agree to the terms", "required": true }] }] },
25
- { "columns": [{ "width": 6, "fields": [{ "type": "dropdown", "key": "country", "label": "Country", "options": [{ "value": "hu", "label": "Hungary" }, { "value": "us", "label": "United States" }] }] }] },
26
- { "columns": [{ "width": 6, "fields": [{ "type": "radio", "key": "contactMethod", "label": "Preferred contact", "options": [{ "value": "email", "label": "Email" }, { "value": "phone", "label": "Phone" }] }] }] },
27
- { "columns": [{ "width": 12, "fields": [{ "type": "checkbox", "key": "interests", "label": "Interests", "options": [{ "value": "a", "label": "Alpha" }, { "value": "b", "label": "Beta" }] }] }] },
28
- { "columns": [{ "width": 12, "fields": [{ "type": "matrix", "key": "survey", "label": "Satisfaction", "matrixRows": [{ "value": "speed", "label": "Speed" }, { "value": "cost", "label": "Cost" }], "matrixColumns": [{ "value": "low", "label": "Low" }, { "value": "high", "label": "High" }] }] }] },
29
- { "columns": [{ "width": 12, "fields": [{ "type": "repeater", "key": "people", "label": "People", "minItems": 0, "rows": [{ "columns": [{ "width": 6, "fields": [{ "type": "text", "key": "name", "label": "Name" }] }, { "width": 6, "fields": [{ "type": "number", "key": "age", "label": "Age" }] }] }] }] }] },
30
- { "columns": [{ "width": 12, "fields": [{ "type": "signature", "key": "sign", "label": "Signature" }] }] },
31
- { "columns": [{ "width": 12, "fields": [{ "type": "file", "key": "attachment", "label": "Attachment", "maxFileSizeMB": 5, "acceptedTypes": [".pdf", "image/*"] }] }] }
32
- ]
33
- }
34
- ]
35
- }
36
- ],
37
- "crossFieldRules": [
38
- {
39
- "id": "rate-sanity",
40
- "andGroups": [{ "conditions": [{ "dependentFieldKey": "rate", "operator": "greaterThan", "equalsValue": 1000 }] }],
41
- "targetFields": ["rate"],
42
- "errorMessage": "Rate looks unusually high; please confirm."
43
- }
44
- ]
45
- }
@@ -1,175 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { readFileSync } from "node:fs";
3
- import { fileURLToPath } from "node:url";
4
- import { dirname, join } from "node:path";
5
- import type { Condition, ConditionalRule } from "../src/schema/types";
6
- import { EvalContext, evaluateCondition, evaluateRule, resolveProperty, compareOrdinal } from "../src/logic/cnf";
7
- import { evaluateFormula } from "../src/logic/formula";
8
- import { normalizeSchema } from "../src/schema/normalize";
9
- import { resolveFormState, computeCalculatedValues } from "../src/logic/state";
10
-
11
- function ctxOf(answers: Record<string, unknown>): EvalContext {
12
- return { getAnswer: (k) => (k in answers ? (answers[k] as never) : undefined) };
13
- }
14
- function cond(c: Partial<Condition>): Condition {
15
- return { dependentFieldKey: "f", operator: "equals", ...c } as Condition;
16
- }
17
- function rule(andGroups: ConditionalRule["andGroups"]): ConditionalRule {
18
- return { targetProperty: "visibility", andGroups };
19
- }
20
-
21
- describe("operators (tasks 3.2, 3.3)", () => {
22
- it("equals matches strict and coerced", () => {
23
- expect(evaluateCondition(cond({ operator: "equals", equalsValue: "1" }), ctxOf({ f: 1 })).satisfied).toBe(true);
24
- expect(evaluateCondition(cond({ operator: "equals", equalsValue: "1" }), ctxOf({ f: "1" })).satisfied).toBe(true);
25
- expect(evaluateCondition(cond({ operator: "notEquals", equalsValue: "2" }), ctxOf({ f: 1 })).satisfied).toBe(true);
26
- });
27
- it("contains is a case-insensitive substring on stringified operands", () => {
28
- expect(evaluateCondition(cond({ operator: "contains", equalsValue: "pest" }), ctxOf({ f: "Budapest" })).satisfied).toBe(true);
29
- expect(evaluateCondition(cond({ operator: "contains", equalsValue: "beta" }), ctxOf({ f: ["alpha", "beta"] })).satisfied).toBe(true);
30
- expect(evaluateCondition(cond({ operator: "notContains", equalsValue: "x" }), ctxOf({ f: undefined })).satisfied).toBe(true);
31
- });
32
- });
33
-
34
- describe("ordering (tasks 3.4, 3.5)", () => {
35
- it("compares numerically before dates", () => {
36
- expect(compareOrdinal(9, 10)! < 0).toBe(true);
37
- expect(compareOrdinal("9", "10")! < 0).toBe(true); // numeric, not string ("9">"10")
38
- });
39
- it("compares dates chronologically", () => {
40
- expect(evaluateCondition(cond({ operator: "greaterThan", equalsValue: "2026-06-30" }), ctxOf({ f: "2026-07-01" })).satisfied).toBe(true);
41
- });
42
- it("falls back to locale string compare", () => {
43
- expect(typeof compareOrdinal("apple", "banana")).toBe("number");
44
- });
45
- it("undefined operand makes every ordering operator false", () => {
46
- for (const op of ["greaterThan", "greaterThanOrEquals", "lessThan", "lessThanOrEquals"] as const) {
47
- expect(evaluateCondition(cond({ operator: op, equalsValue: 5 }), ctxOf({})).satisfied).toBe(false);
48
- }
49
- });
50
- });
51
-
52
- describe("aliases and unknown operators (tasks 3.2, 3.7)", () => {
53
- it("gte behaves like greaterThanOrEquals", () => {
54
- expect(evaluateCondition(cond({ operator: "gte", equalsValue: 5 }), ctxOf({ f: 5 })).satisfied).toBe(true);
55
- });
56
- it("unknown operator falls back to equals with a diagnostic", () => {
57
- const diags: unknown[] = [];
58
- const ctx: EvalContext = { ...ctxOf({ f: "x" }), reportDiagnostic: (d) => diags.push(d) };
59
- expect(evaluateCondition(cond({ operator: "weird", equalsValue: "x" }), ctx).satisfied).toBe(true);
60
- expect(diags).toHaveLength(1);
61
- });
62
- });
63
-
64
- describe("CNF truth tables (task 3.1)", () => {
65
- const c1 = cond({ dependentFieldKey: "a", operator: "equals", equalsValue: "1" });
66
- const c2 = cond({ dependentFieldKey: "b", operator: "equals", equalsValue: "1" });
67
- it("OR within a group", () => {
68
- expect(evaluateRule(rule([{ conditions: [c1, c2] }]), ctxOf({ a: "1", b: "0" })).satisfied).toBe(true);
69
- });
70
- it("AND between groups", () => {
71
- expect(evaluateRule(rule([{ conditions: [c1] }, { conditions: [c2] }]), ctxOf({ a: "1", b: "0" })).satisfied).toBe(false);
72
- });
73
- it("empty andGroups is never satisfied", () => {
74
- expect(evaluateRule(rule([]), ctxOf({})).satisfied).toBe(false);
75
- });
76
- it("empty condition group is never satisfied", () => {
77
- expect(evaluateRule(rule([{ conditions: [] }]), ctxOf({})).satisfied).toBe(false);
78
- });
79
- });
80
-
81
- describe("property replacement (task 3.9)", () => {
82
- const unmet = rule([{ conditions: [cond({ dependentFieldKey: "a", operator: "equals", equalsValue: "yes" })] }]);
83
- it("an unsatisfied required rule overrides a static required:true", () => {
84
- const req: ConditionalRule = { ...unmet, targetProperty: "required" };
85
- expect(resolveProperty(true, [req], "required", ctxOf({ a: "no" }))).toBe(false);
86
- });
87
- it("no rule leaves the static value intact", () => {
88
- expect(resolveProperty(true, [], "required", ctxOf({}))).toBe(true);
89
- });
90
- it("multiple rules combine as OR", () => {
91
- const r1 = rule([{ conditions: [cond({ dependentFieldKey: "a", operator: "equals", equalsValue: "1" })] }]);
92
- const r2 = rule([{ conditions: [cond({ dependentFieldKey: "b", operator: "equals", equalsValue: "1" })] }]);
93
- expect(resolveProperty(false, [r1, r2], "visibility", ctxOf({ a: "0", b: "1" }))).toBe(true);
94
- });
95
- });
96
-
97
- describe("section gating (task 3.8)", () => {
98
- it("a hidden section hides its fields", () => {
99
- const { schema } = normalizeSchema({
100
- pages: [
101
- {
102
- sections: [
103
- {
104
- conditionalRules: [rule([{ conditions: [cond({ dependentFieldKey: "toggle", operator: "equals", equalsValue: "show" })] }])],
105
- rows: [{ columns: [{ fields: [{ type: "text", key: "inside" }] }] }],
106
- },
107
- ],
108
- },
109
- ],
110
- });
111
- const hidden = resolveFormState(schema, { toggle: "hide" });
112
- expect(hidden.fields.get("inside")!.visible).toBe(false);
113
- const shown = resolveFormState(schema, { toggle: "show" });
114
- expect(shown.fields.get("inside")!.visible).toBe(true);
115
- });
116
- });
117
-
118
- describe("formula parser (tasks 3.10, 3.11, 3.12)", () => {
119
- const refs = (m: Record<string, number>) => (k: string) => m[k] ?? 0;
120
- it("evaluates arithmetic over field references", () => {
121
- expect(evaluateFormula("{devShare} + {pmShare}", refs({ devShare: 10, pmShare: 15 })).value).toBe(25);
122
- });
123
- it("supports Math.round", () => {
124
- expect(evaluateFormula("Math.round({total} / 3)", refs({ total: 10 })).value).toBe(3);
125
- });
126
- it("supports ternary and comparison", () => {
127
- expect(evaluateFormula("{a} > 5 ? 100 : 0", refs({ a: 9 })).value).toBe(100);
128
- });
129
- it("returns 0 and an error for out-of-grammar input", () => {
130
- for (const bad of ["alert(1)", "{a}.constructor", "process.exit(1)", "1 + foo(2)", "`x`"]) {
131
- const r = evaluateFormula(bad, refs({ a: 1 }));
132
- expect(r.value).toBe(0);
133
- expect(r.error).toBeTruthy();
134
- }
135
- });
136
- it("recomputes calculated fields including hidden ones", () => {
137
- const { schema } = normalizeSchema({
138
- pages: [
139
- {
140
- sections: [
141
- {
142
- rows: [
143
- {
144
- columns: [
145
- {
146
- fields: [
147
- { type: "number", key: "a" },
148
- { type: "number", key: "b" },
149
- { type: "number", key: "sum", isCalculated: true, isVisibleOnForm: false, formulaExpression: "{a} + {b}" },
150
- ],
151
- },
152
- ],
153
- },
154
- ],
155
- },
156
- ],
157
- },
158
- ],
159
- });
160
- const { answers } = computeCalculatedValues(schema, { a: 3, b: 4 });
161
- expect(answers.sum).toBe(7);
162
- });
163
- });
164
-
165
- describe("no code-construction primitive exists (task 3.11)", () => {
166
- it("formula.ts source contains no eval or Function constructor", () => {
167
- const here = dirname(fileURLToPath(import.meta.url));
168
- const src = readFileSync(join(here, "..", "src", "logic", "formula.ts"), "utf8");
169
- // Strip comments and doc references to avoid false positives on the word 'eval'.
170
- const code = src.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
171
- expect(/\beval\s*\(/.test(code)).toBe(false);
172
- expect(/new\s+Function\s*\(/.test(code)).toBe(false);
173
- expect(/\bFunction\s*\(/.test(code)).toBe(false);
174
- });
175
- });
@@ -1,105 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { normalizeSchema } from "../src/schema/normalize";
3
- import type { FormSchemaJSON } from "../src/schema/types";
4
-
5
- describe("normalizeSchema (tasks 2.3, 2.4, 2.7)", () => {
6
- it("produces one page with one empty section from empty/null input", () => {
7
- for (const input of [{}, null, undefined]) {
8
- const { schema } = normalizeSchema(input as never);
9
- expect(schema.pages).toHaveLength(1);
10
- expect(schema.pages[0].sections).toHaveLength(1);
11
- expect(schema.pages[0].sections[0].rows).toEqual([]);
12
- }
13
- });
14
-
15
- it("generates identifiers where absent and preserves existing ones", () => {
16
- const input: Partial<FormSchemaJSON> = {
17
- pages: [
18
- {
19
- pageId: "keep-me",
20
- sections: [
21
- { rows: [{ columns: [{ fields: [{ type: "text", key: "a" }] }] }] },
22
- ],
23
- },
24
- ],
25
- };
26
- const { schema } = normalizeSchema(input);
27
- expect(schema.pages[0].pageId).toBe("keep-me");
28
- expect(schema.pages[0].sections[0].sectionId).toBeTruthy();
29
- expect(schema.pages[0].sections[0].rows[0].rowId).toBeTruthy();
30
- expect(schema.pages[0].sections[0].rows[0].columns[0].fields[0].id).toBeTruthy();
31
- });
32
-
33
- it("does not mutate its input", () => {
34
- const input: Partial<FormSchemaJSON> = {
35
- pages: [{ sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "a" }] }] }] }] }],
36
- };
37
- const snapshot = JSON.stringify(input);
38
- normalizeSchema(input);
39
- expect(JSON.stringify(input)).toBe(snapshot);
40
- });
41
-
42
- it("is idempotent: normalize(normalize(x)) deep-equals normalize(x)", () => {
43
- const input: Partial<FormSchemaJSON> = {
44
- formTitle: "T",
45
- pages: [
46
- {
47
- sections: [
48
- { rows: [{ columns: [{ width: 6, fields: [{ type: "text", key: "a" }] }] }] },
49
- ],
50
- },
51
- ],
52
- };
53
- const once = normalizeSchema(input).schema;
54
- const twice = normalizeSchema(once).schema;
55
- expect(twice).toEqual(once);
56
- });
57
-
58
- it("migrates a legacy visibilityCondition and emits an info diagnostic", () => {
59
- const input: Partial<FormSchemaJSON> = {
60
- pages: [
61
- {
62
- sections: [
63
- {
64
- rows: [
65
- {
66
- columns: [
67
- {
68
- fields: [
69
- { type: "text", key: "trigger" },
70
- {
71
- type: "text",
72
- key: "dependent",
73
- visibilityCondition: {
74
- dependentFieldKey: "trigger",
75
- operator: "equals",
76
- equalsValue: "yes",
77
- },
78
- },
79
- ],
80
- },
81
- ],
82
- },
83
- ],
84
- },
85
- ],
86
- },
87
- ],
88
- };
89
- const { schema, diagnostics } = normalizeSchema(input);
90
- const dependent = schema.pages[0].sections[0].rows[0].columns[0].fields[1];
91
- expect(dependent.conditionalRules?.[0].targetProperty).toBe("visibility");
92
- expect(dependent.visibilityCondition).toBeUndefined();
93
- expect(diagnostics.some((d) => d.severity === "info" && d.code === "legacy-visibility-migrated")).toBe(true);
94
- });
95
-
96
- it("retains a legacy cross-field expression with a migration hint", () => {
97
- const input: Partial<FormSchemaJSON> = {
98
- pages: [{ sections: [{ rows: [] }] }],
99
- crossFieldRules: [{ expression: "{a} > {b}", targetFields: ["a"], errorMessage: "bad" }],
100
- };
101
- const { schema, diagnostics } = normalizeSchema(input);
102
- expect(schema.crossFieldRules?.[0].expression).toBe("{a} > {b}");
103
- expect(diagnostics.some((d) => d.code === "legacy-expression-retained")).toBe(true);
104
- });
105
- });
@@ -1,131 +0,0 @@
1
- /**
2
- * Confirms the semantics recorded in design D15 (read from the reference source,
3
- * not from documentation). The live `--reference` harness mode detects *upstream*
4
- * change; these tests pin *our* conformance so a regression fails in CI.
5
- *
6
- * D13 payload divergences (applicability-based contract; disabled fields
7
- * included) are INTENTIONAL: a `--reference` mismatch on either is expected and
8
- * must not be "fixed" (task 9.4). The disabled-inclusion divergence is pinned by
9
- * tests/component.test.tsx ("includes a disabled one").
10
- */
11
- import { describe, it, expect } from "vitest";
12
- import type { Condition } from "../src/schema/types";
13
- import { EvalContext, evaluateCondition, resolveProperty, compareOrdinal } from "../src/logic/cnf";
14
- import { normalizeSchema } from "../src/schema/normalize";
15
- import { resolveFormState } from "../src/logic/state";
16
-
17
- function ctxOf(a: Record<string, unknown>): EvalContext {
18
- return { getAnswer: (k) => (k in a ? (a[k] as never) : undefined) };
19
- }
20
- const c = (o: Partial<Condition>): Condition => ({ dependentFieldKey: "f", operator: "equals", ...o } as Condition);
21
-
22
- describe("D15.1 — contains is substring on stringified operands (task 9.1)", () => {
23
- it("joins a checkbox array before matching", () => {
24
- expect(evaluateCondition(c({ operator: "contains", equalsValue: "b,c" }), ctxOf({ f: ["a", "b", "c"] })).satisfied).toBe(true);
25
- });
26
- });
27
-
28
- describe("D15.2 — three ordering tiers + undefined guard (task 9.2)", () => {
29
- it("numeric tier precedes date tier", () => {
30
- expect(compareOrdinal("9", "10")! < 0).toBe(true);
31
- });
32
- it("date tier when not numeric", () => {
33
- expect(compareOrdinal("2026-07-01", "2026-06-30")! > 0).toBe(true);
34
- });
35
- it("plain-string tier otherwise", () => {
36
- expect(typeof compareOrdinal("banana", "apple")).toBe("number");
37
- });
38
- it("undefined operand is indeterminate", () => {
39
- expect(compareOrdinal(undefined, 5)).toBeUndefined();
40
- expect(evaluateCondition(c({ operator: "greaterThan", equalsValue: 5 }), ctxOf({})).satisfied).toBe(false);
41
- });
42
- });
43
-
44
- describe("D15.3 — unknown operator falls back to equals (task 9.1)", () => {
45
- it("evaluates equality and reports a diagnostic", () => {
46
- const diags: unknown[] = [];
47
- const ctx: EvalContext = { ...ctxOf({ f: "x" }), reportDiagnostic: (d) => diags.push(d) };
48
- expect(evaluateCondition(c({ operator: "??", equalsValue: "x" }), ctx).satisfied).toBe(true);
49
- expect(diags.length).toBe(1);
50
- });
51
- });
52
-
53
- describe("D15.4/D15.5 — empty andGroups hides; rule replaces static value (task 9.3)", () => {
54
- it("an empty visibility andGroups hides its target", () => {
55
- const { schema } = normalizeSchema({
56
- pages: [
57
- {
58
- sections: [
59
- {
60
- rows: [
61
- {
62
- columns: [
63
- { fields: [{ type: "text", key: "x", conditionalRules: [{ targetProperty: "visibility", andGroups: [] }] }] },
64
- ],
65
- },
66
- ],
67
- },
68
- ],
69
- },
70
- ],
71
- });
72
- expect(resolveFormState(schema, {}).fields.get("x")!.visible).toBe(false);
73
- });
74
-
75
- it("a rule targeting required replaces the static required:true", () => {
76
- const unmet = { targetProperty: "required" as const, andGroups: [{ conditions: [c({ dependentFieldKey: "a", operator: "equals", equalsValue: "yes" })] }] };
77
- expect(resolveProperty(true, [unmet], "required", ctxOf({ a: "no" }))).toBe(false);
78
- });
79
- });
80
-
81
- describe("D15 misc — isVisibleOnForm and repeater child rules (task 9.5)", () => {
82
- it("isVisibleOnForm is inert without isCalculated (field renders normally)", () => {
83
- const { schema } = normalizeSchema({
84
- pages: [{ sections: [{ rows: [{ columns: [{ fields: [{ type: "number", key: "n", isVisibleOnForm: false }] }] }] }] }],
85
- });
86
- // Not calculated, so it is not hiddenCalculated and remains visible.
87
- const fs = resolveFormState(schema, {}).fields.get("n")!;
88
- expect(fs.hiddenCalculated).toBe(false);
89
- expect(fs.visible).toBe(true);
90
- });
91
-
92
- it("repeater child fields never get a resolved rule state", () => {
93
- const { schema } = normalizeSchema({
94
- pages: [
95
- {
96
- sections: [
97
- {
98
- rows: [
99
- {
100
- columns: [
101
- {
102
- fields: [
103
- {
104
- type: "repeater",
105
- key: "rep",
106
- rows: [{ columns: [{ fields: [{ type: "text", key: "child", conditionalRules: [{ targetProperty: "visibility", andGroups: [] }] }] }] }],
107
- },
108
- ],
109
- },
110
- ],
111
- },
112
- ],
113
- },
114
- ],
115
- },
116
- ],
117
- });
118
- const state = resolveFormState(schema, {});
119
- // "rep" has a top-level state entry; "child" does not (rules are inert).
120
- expect(state.fields.has("rep")).toBe(true);
121
- expect(state.fields.has("child")).toBe(false);
122
- });
123
- });
124
-
125
- describe("9.4 — payload divergences are intentional", () => {
126
- it("this suite documents that disabled-inclusion & applicability filtering are deliberate", () => {
127
- // The behavioural pins live in component.test.tsx; this marker asserts the
128
- // decision is recorded so a reviewer does not 'fix' the divergence.
129
- expect(true).toBe(true);
130
- });
131
- });