@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.
- package/.pi/skills/bpmn-package-explorer/SKILL.md +15 -9
- package/.pi/skills/bpmn-package-explorer/scripts/fixtures.mjs +6 -1
- package/.pi/skills/bpmn-package-explorer/scripts/generate-cli.mjs +1 -1
- package/.pi/skills/bpmn-package-explorer/scripts/render.mjs +3 -2
- package/.pi/skills/bpmn-package-explorer/scripts/serve.mjs +91 -0
- package/.pi/skills/bpmn-package-explorer/scripts/view-cli.mjs +1 -1
- package/.pi/skills/bpmn-package-explorer/templates/shell.html +12 -1
- package/.pi/skills/bpmn-package-explorer/templates/viewer.js +52 -5
- package/.pi/skills/openforms-mui/tools/package-lock.json +0 -42
- package/.pi/skills/openforms-mui/tools/src/fields/FieldRenderer.tsx +5 -0
- package/.pi/skills/openforms-mui/tools/src/fields/RepeaterField.tsx +4 -2
- package/.pi/skills/openforms-mui/tools/src/fields/renderer-registry.ts +43 -0
- package/NOTICE +0 -6
- package/README.md +12 -9
- package/package.json +8 -6
- package/.pi/skills/canvas-webapp/SKILL.md +0 -104
- package/.pi/skills/openforms-mui/tools/tests/a11y.test.tsx +0 -82
- package/.pi/skills/openforms-mui/tools/tests/cli.test.ts +0 -74
- package/.pi/skills/openforms-mui/tools/tests/component.test.tsx +0 -295
- package/.pi/skills/openforms-mui/tools/tests/diagnose.test.ts +0 -163
- package/.pi/skills/openforms-mui/tools/tests/fixtures/all-field-types.json +0 -45
- package/.pi/skills/openforms-mui/tools/tests/logic.test.ts +0 -175
- package/.pi/skills/openforms-mui/tools/tests/normalize.test.ts +0 -105
- package/.pi/skills/openforms-mui/tools/tests/reference-semantics.test.ts +0 -131
- package/.pi/skills/openforms-mui/tools/tests/responsive.test.tsx +0 -158
- package/.pi/skills/openforms-mui/tools/tests/setup.ts +0 -16
- package/.pi/skills/openforms-mui/tools/tests/singleton.test.tsx +0 -31
- package/.pi/skills/openforms-mui/tools/tests/theme.test.ts +0 -65
- package/.pi/skills/openforms-mui/tools/tests/toolchain.test.ts +0 -33
- package/.pi/skills/openforms-mui/tools/tests/validation.test.ts +0 -222
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
|
|
6
|
-
import { ThemeProvider } from "@mui/material/styles";
|
|
7
|
-
import { OpenFormsMui } from "../src/OpenFormsMui";
|
|
8
|
-
import { RenderPanel } from "../preview/RenderPanel";
|
|
9
|
-
import { defaultTheme } from "../src/theme/from-tokens";
|
|
10
|
-
import type { FormSchemaJSON } from "../src/schema/types";
|
|
11
|
-
|
|
12
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
|
|
14
|
-
afterEach(cleanup);
|
|
15
|
-
|
|
16
|
-
function setNarrow(narrow: boolean) {
|
|
17
|
-
window.matchMedia = (query: string) =>
|
|
18
|
-
({
|
|
19
|
-
matches: narrow && /max-width/.test(query),
|
|
20
|
-
media: query,
|
|
21
|
-
onchange: null,
|
|
22
|
-
addListener: () => {},
|
|
23
|
-
removeListener: () => {},
|
|
24
|
-
addEventListener: () => {},
|
|
25
|
-
removeEventListener: () => {},
|
|
26
|
-
dispatchEvent: () => false,
|
|
27
|
-
}) as unknown as MediaQueryList;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const matrixSchema: FormSchemaJSON = {
|
|
31
|
-
pages: [
|
|
32
|
-
{
|
|
33
|
-
sections: [
|
|
34
|
-
{
|
|
35
|
-
rows: [
|
|
36
|
-
{
|
|
37
|
-
columns: [
|
|
38
|
-
{
|
|
39
|
-
fields: [
|
|
40
|
-
{
|
|
41
|
-
type: "matrix",
|
|
42
|
-
key: "survey",
|
|
43
|
-
label: "Satisfaction",
|
|
44
|
-
matrixRows: [{ value: "speed", label: "Speed" }],
|
|
45
|
-
matrixColumns: [{ value: "low", label: "Low" }, { value: "high", label: "High" }],
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
} as FormSchemaJSON;
|
|
57
|
-
|
|
58
|
-
describe("matrix narrow presentation (tasks 10.7, 10.8)", () => {
|
|
59
|
-
it("renders cards (not a table) below md and keeps the row label associated", () => {
|
|
60
|
-
setNarrow(true);
|
|
61
|
-
render(
|
|
62
|
-
<ThemeProvider theme={defaultTheme()}>
|
|
63
|
-
<OpenFormsMui schema={matrixSchema} />
|
|
64
|
-
</ThemeProvider>,
|
|
65
|
-
);
|
|
66
|
-
// No table in the narrow presentation — one radiogroup labelled by the row.
|
|
67
|
-
expect(screen.queryByRole("table")).toBeNull();
|
|
68
|
-
const rowGroup = screen.getByRole("radiogroup", { name: "Speed" });
|
|
69
|
-
expect(rowGroup).toBeInTheDocument();
|
|
70
|
-
setNarrow(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("the wide table makes the whole cell the activation target", () => {
|
|
74
|
-
setNarrow(false);
|
|
75
|
-
render(
|
|
76
|
-
<ThemeProvider theme={defaultTheme()}>
|
|
77
|
-
<OpenFormsMui schema={matrixSchema} />
|
|
78
|
-
</ThemeProvider>,
|
|
79
|
-
);
|
|
80
|
-
expect(screen.getByRole("table", { name: "Satisfaction" })).toBeInTheDocument();
|
|
81
|
-
// Each radio sits inside a <label> spanning the cell.
|
|
82
|
-
const radios = screen.getAllByRole("radio");
|
|
83
|
-
for (const r of radios) {
|
|
84
|
-
expect(r.closest("label")).not.toBeNull();
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("the 48px activation floor is present in the matrix source", () => {
|
|
89
|
-
const src = readFileSync(join(here, "..", "src", "fields", "MatrixField.tsx"), "utf8");
|
|
90
|
-
expect(src).toMatch(/minHeight:\s*48/);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe("action bar DOM order (task 10.5)", () => {
|
|
95
|
-
it("Back precedes the primary action in the DOM", () => {
|
|
96
|
-
const multi: FormSchemaJSON = {
|
|
97
|
-
pages: [
|
|
98
|
-
{ title: "A", sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "a" }] }] }] }] },
|
|
99
|
-
{ title: "B", sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "b" }] }] }] }] },
|
|
100
|
-
],
|
|
101
|
-
} as FormSchemaJSON;
|
|
102
|
-
const { container } = render(
|
|
103
|
-
<ThemeProvider theme={defaultTheme()}>
|
|
104
|
-
<OpenFormsMui schema={multi} />
|
|
105
|
-
</ThemeProvider>,
|
|
106
|
-
);
|
|
107
|
-
// Advance to page 2 so both Back and Submit exist.
|
|
108
|
-
fireEvent.click(screen.getByRole("button", { name: "Next" }));
|
|
109
|
-
const buttons = Array.from(container.querySelectorAll("button")).map((b) => b.textContent);
|
|
110
|
-
const back = buttons.indexOf("Back");
|
|
111
|
-
const submit = buttons.indexOf("Submit");
|
|
112
|
-
expect(back).toBeGreaterThanOrEqual(0);
|
|
113
|
-
expect(submit).toBeGreaterThan(back);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("render-panel view switch (tasks 10.11, 10.12, 10.13)", () => {
|
|
118
|
-
const schema = JSON.parse(readFileSync(join(here, "fixtures", "all-field-types.json"), "utf8")) as FormSchemaJSON;
|
|
119
|
-
|
|
120
|
-
function renderPanel() {
|
|
121
|
-
return render(
|
|
122
|
-
<ThemeProvider theme={defaultTheme()}>
|
|
123
|
-
<RenderPanel schema={schema}>
|
|
124
|
-
<div>form-body</div>
|
|
125
|
-
</RenderPanel>
|
|
126
|
-
</ThemeProvider>,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
it("is an APG tablist with a roving tabindex", () => {
|
|
131
|
-
renderPanel();
|
|
132
|
-
const tabs = screen.getAllByRole("tab");
|
|
133
|
-
expect(tabs).toHaveLength(2);
|
|
134
|
-
// Selected tab is in the tab sequence; the other is not.
|
|
135
|
-
const selected = tabs.find((t) => t.getAttribute("aria-selected") === "true")!;
|
|
136
|
-
const unselected = tabs.find((t) => t.getAttribute("aria-selected") === "false")!;
|
|
137
|
-
expect(selected.getAttribute("tabindex")).toBe("0");
|
|
138
|
-
expect(unselected.getAttribute("tabindex")).toBe("-1");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("arrow keys move selection", () => {
|
|
142
|
-
renderPanel();
|
|
143
|
-
const [formTab, schemaTab] = screen.getAllByRole("tab");
|
|
144
|
-
fireEvent.keyDown(formTab, { key: "ArrowRight" });
|
|
145
|
-
expect(schemaTab.getAttribute("aria-selected")).toBe("true");
|
|
146
|
-
// Schema source is shown with preserved whitespace.
|
|
147
|
-
const pre = document.getElementById("ofm-panel-schema")!.querySelector("pre")!;
|
|
148
|
-
expect(getComputedStyle(pre).whiteSpace === "pre" || pre.style.whiteSpace === "pre" || true).toBe(true);
|
|
149
|
-
expect(pre.textContent).toContain("formTitle");
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("tab labels are unique on the screen (no collision)", () => {
|
|
153
|
-
renderPanel();
|
|
154
|
-
const labels = screen.getAllByRole("tab").map((t) => t.textContent);
|
|
155
|
-
expect(new Set(labels).size).toBe(labels.length);
|
|
156
|
-
expect(labels).toEqual(["Rendered form", "Schema source"]);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import "@testing-library/jest-dom/vitest";
|
|
2
|
-
|
|
3
|
-
// jsdom has no matchMedia; MUI useMediaQuery needs it. Default to "not narrow".
|
|
4
|
-
if (!window.matchMedia) {
|
|
5
|
-
window.matchMedia = (query: string) =>
|
|
6
|
-
({
|
|
7
|
-
matches: false,
|
|
8
|
-
media: query,
|
|
9
|
-
onchange: null,
|
|
10
|
-
addListener: () => {},
|
|
11
|
-
removeListener: () => {},
|
|
12
|
-
addEventListener: () => {},
|
|
13
|
-
removeEventListener: () => {},
|
|
14
|
-
dispatchEvent: () => false,
|
|
15
|
-
}) as unknown as MediaQueryList;
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { render, screen } from "@testing-library/react";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import { OpenFormsMui } from "../src/OpenFormsMui";
|
|
6
|
-
import type { FormSchemaJSON } from "../src/schema/types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Regression for the D14 singleton hazard: importing the component out of the
|
|
10
|
-
* skill directory must resolve React to ONE instance. A second React instance
|
|
11
|
-
* would make hooks throw "invalid hook call". Here we assert both the structural
|
|
12
|
-
* guarantee (a single resolved `react`) and the behavioural one (the component
|
|
13
|
-
* mounts and its hooks run without an invalid-hook-call).
|
|
14
|
-
*/
|
|
15
|
-
describe("single React instance (task 1.5)", () => {
|
|
16
|
-
it("resolves react from the skill's own node_modules exactly once", () => {
|
|
17
|
-
const require = createRequire(import.meta.url);
|
|
18
|
-
const resolved = require.resolve("react");
|
|
19
|
-
expect(resolved).toContain("openforms-mui/tools/node_modules/react");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("mounts the component without an invalid hook call", () => {
|
|
23
|
-
const schema: FormSchemaJSON = {
|
|
24
|
-
pages: [{ sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "t", label: "T" }] }] }] }] }],
|
|
25
|
-
} as FormSchemaJSON;
|
|
26
|
-
// React.version is defined once; a duplicate instance would desync hooks.
|
|
27
|
-
expect(typeof React.version).toBe("string");
|
|
28
|
-
render(<OpenFormsMui schema={schema} />);
|
|
29
|
-
expect(screen.getByLabelText(/T/)).toBeInTheDocument();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { readdirSync, readFileSync, existsSync } from "node:fs";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { themeFromTokens, defaultTheme } from "../src/theme/from-tokens";
|
|
6
|
-
|
|
7
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const srcDir = join(here, "..", "src");
|
|
9
|
-
|
|
10
|
-
describe("theme bridge (tasks 5.1, 5.2)", () => {
|
|
11
|
-
it("produces a MUI theme from DTCG tokens", () => {
|
|
12
|
-
const theme = themeFromTokens({
|
|
13
|
-
color: {
|
|
14
|
-
primary: { $value: "#0a7d33" },
|
|
15
|
-
secondary: { $value: "#333333" },
|
|
16
|
-
},
|
|
17
|
-
radius: { base: { $value: 12 } },
|
|
18
|
-
});
|
|
19
|
-
expect(theme.palette.primary.main).toBe("#0a7d33");
|
|
20
|
-
expect(theme.shape.borderRadius).toBe(12);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("falls back to a documented default when no tokens are present", () => {
|
|
24
|
-
const theme = themeFromTokens(null);
|
|
25
|
-
expect(theme.palette.primary.main).toBe(defaultTheme().palette.primary.main);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("token-lint: no literal colour in component sources (task 5.3)", () => {
|
|
30
|
-
// Colour literals belong only in the token/theme layer. Component widgets must
|
|
31
|
-
// read from the theme. Scan field components + the root component.
|
|
32
|
-
const COMPONENT_DIRS = [join(srcDir, "fields")];
|
|
33
|
-
const COMPONENT_FILES = [join(srcDir, "OpenFormsMui.tsx")];
|
|
34
|
-
|
|
35
|
-
function collectSources(): string[] {
|
|
36
|
-
const files: string[] = [];
|
|
37
|
-
for (const dir of COMPONENT_DIRS) {
|
|
38
|
-
if (!existsSync(dir)) continue;
|
|
39
|
-
for (const f of readdirSync(dir)) {
|
|
40
|
-
if (f.endsWith(".tsx") || f.endsWith(".ts")) files.push(join(dir, f));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
for (const f of COMPONENT_FILES) if (existsSync(f)) files.push(f);
|
|
44
|
-
return files;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const HEX = /#[0-9a-fA-F]{3,8}\b/;
|
|
48
|
-
const RGB = /\brgba?\(/;
|
|
49
|
-
const HSL = /\bhsla?\(/;
|
|
50
|
-
|
|
51
|
-
it("contains no hex / rgb / hsl colour literals", () => {
|
|
52
|
-
const offenders: string[] = [];
|
|
53
|
-
for (const file of collectSources()) {
|
|
54
|
-
const code = readFileSync(file, "utf8")
|
|
55
|
-
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
56
|
-
.replace(/\/\/.*$/gm, "");
|
|
57
|
-
code.split("\n").forEach((line, i) => {
|
|
58
|
-
if (HEX.test(line) || RGB.test(line) || HSL.test(line)) {
|
|
59
|
-
offenders.push(`${file}:${i + 1}: ${line.trim()}`);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
expect(offenders, offenders.join("\n")).toEqual([]);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,33 +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 { UPSTREAM_PROVENANCE } from "../src/provenance";
|
|
6
|
-
|
|
7
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
|
|
9
|
-
|
|
10
|
-
const SINGLETONS = [
|
|
11
|
-
"react",
|
|
12
|
-
"react-dom",
|
|
13
|
-
"@mui/material",
|
|
14
|
-
"@mui/x-date-pickers",
|
|
15
|
-
"@emotion/react",
|
|
16
|
-
"@emotion/styled",
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
describe("toolchain (task 1.3, 1.7, 1.8)", () => {
|
|
20
|
-
it("declares each singleton as peer + dev and never as a plain dependency", () => {
|
|
21
|
-
for (const name of SINGLETONS) {
|
|
22
|
-
expect(pkg.peerDependencies?.[name], `${name} peer`).toBeTruthy();
|
|
23
|
-
expect(pkg.devDependencies?.[name], `${name} dev`).toBeTruthy();
|
|
24
|
-
expect(pkg.dependencies?.[name], `${name} must not be a plain dependency`).toBeUndefined();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("pins the upstream provenance in a single constant", () => {
|
|
29
|
-
expect(UPSTREAM_PROVENANCE.repository).toBe("henriquefps/open-forms");
|
|
30
|
-
expect(UPSTREAM_PROVENANCE.version).toBe("1.0.7");
|
|
31
|
-
expect(UPSTREAM_PROVENANCE.license).toBe("Apache-2.0");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import type { Field, FormSchemaJSON } from "../src/schema/types";
|
|
3
|
-
import { normalizeSchema } from "../src/schema/normalize";
|
|
4
|
-
import { resolveFormState } from "../src/logic/state";
|
|
5
|
-
import {
|
|
6
|
-
deriveZodSchema,
|
|
7
|
-
createMemoizedDeriver,
|
|
8
|
-
FORM_LEVEL_PATH,
|
|
9
|
-
} from "../src/validation/zod-from-schema";
|
|
10
|
-
import { collectFieldDiagnostics } from "../src/validation/diagnostics";
|
|
11
|
-
|
|
12
|
-
function form(fields: Field[], extra?: Partial<FormSchemaJSON>): FormSchemaJSON {
|
|
13
|
-
return normalizeSchema({
|
|
14
|
-
pages: [{ sections: [{ rows: [{ columns: [{ fields }] }] }] }],
|
|
15
|
-
...extra,
|
|
16
|
-
}).schema;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe("Zod derivation (tasks 4.0, 4.1)", () => {
|
|
20
|
-
it("maps field types to validators and accepts declared empty values", () => {
|
|
21
|
-
const s = form([
|
|
22
|
-
{ type: "text", key: "t" },
|
|
23
|
-
{ type: "number", key: "n" },
|
|
24
|
-
{ type: "date", key: "d" },
|
|
25
|
-
{ type: "boolean", key: "b" },
|
|
26
|
-
{ type: "checkbox", key: "c", options: [] },
|
|
27
|
-
]);
|
|
28
|
-
const zod = deriveZodSchema(s, resolveFormState(s, {}));
|
|
29
|
-
const ok = zod.safeParse({ t: "", n: null, d: "", b: false, c: [] });
|
|
30
|
-
expect(ok.success).toBe(true);
|
|
31
|
-
// number rejects a wrong shape
|
|
32
|
-
const bad = zod.safeParse({ t: "", n: "notnum", d: "", b: false, c: [] });
|
|
33
|
-
expect(bad.success).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("excludes header and paragraph fields", () => {
|
|
37
|
-
const s = form([{ type: "header", key: "h" }, { type: "paragraph", key: "p" }, { type: "text", key: "t" }]);
|
|
38
|
-
const zod = deriveZodSchema(s, resolveFormState(s, {}));
|
|
39
|
-
// Parsing an object without h/p keys succeeds (no required key for them).
|
|
40
|
-
expect(zod.safeParse({ t: "" }).success).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("visibility-aware validation (tasks 4.2, 4.8)", () => {
|
|
45
|
-
const schema = form([
|
|
46
|
-
{ type: "text", key: "toggle" },
|
|
47
|
-
{
|
|
48
|
-
type: "text",
|
|
49
|
-
key: "secret",
|
|
50
|
-
required: true,
|
|
51
|
-
validationRegex: "^[0-9]+$",
|
|
52
|
-
errorMessage: "digits only",
|
|
53
|
-
conditionalRules: [
|
|
54
|
-
{ targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "toggle", operator: "equals", equalsValue: "show" }] }] },
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
]);
|
|
58
|
-
|
|
59
|
-
it("a hidden field holding an invalid value does not block submission", () => {
|
|
60
|
-
const state = resolveFormState(schema, { toggle: "hide", secret: "not-digits" });
|
|
61
|
-
const zod = deriveZodSchema(schema, state);
|
|
62
|
-
expect(zod.safeParse({ toggle: "hide", secret: "not-digits" }).success).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("the field becomes required and constrained when revealed", () => {
|
|
66
|
-
const state = resolveFormState(schema, { toggle: "show", secret: "" });
|
|
67
|
-
const zod = deriveZodSchema(schema, state);
|
|
68
|
-
expect(zod.safeParse({ toggle: "show", secret: "" }).success).toBe(false);
|
|
69
|
-
expect(zod.safeParse({ toggle: "show", secret: "abc" }).success).toBe(false);
|
|
70
|
-
expect(zod.safeParse({ toggle: "show", secret: "123" }).success).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe("memoization on derived state (tasks 4.5, 4.7)", () => {
|
|
75
|
-
const schema = form([
|
|
76
|
-
{ type: "text", key: "toggle" },
|
|
77
|
-
{
|
|
78
|
-
type: "text",
|
|
79
|
-
key: "dep",
|
|
80
|
-
conditionalRules: [
|
|
81
|
-
{ targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "toggle", operator: "equals", equalsValue: "x" }] }] },
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
it("typing into a visible field does not rebuild the schema", () => {
|
|
87
|
-
const deriver = createMemoizedDeriver(schema);
|
|
88
|
-
const rebuildCount = () => (deriver as unknown as { rebuildCount(): number }).rebuildCount();
|
|
89
|
-
deriver(resolveFormState(schema, { toggle: "a" }));
|
|
90
|
-
expect(rebuildCount()).toBe(1);
|
|
91
|
-
deriver(resolveFormState(schema, { toggle: "ab" })); // still hidden, same state
|
|
92
|
-
expect(rebuildCount()).toBe(1);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("a visibility transition rebuilds the schema", () => {
|
|
96
|
-
const deriver = createMemoizedDeriver(schema);
|
|
97
|
-
const rebuildCount = () => (deriver as unknown as { rebuildCount(): number }).rebuildCount();
|
|
98
|
-
deriver(resolveFormState(schema, { toggle: "a" }));
|
|
99
|
-
deriver(resolveFormState(schema, { toggle: "x" })); // dep now visible
|
|
100
|
-
expect(rebuildCount()).toBe(2);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("cross-field rules (task 4.4)", () => {
|
|
105
|
-
const schema = form(
|
|
106
|
-
[
|
|
107
|
-
{ type: "date", key: "startDate" },
|
|
108
|
-
{ type: "date", key: "endDate" },
|
|
109
|
-
],
|
|
110
|
-
{
|
|
111
|
-
crossFieldRules: [
|
|
112
|
-
{
|
|
113
|
-
andGroups: [{ conditions: [{ dependentFieldKey: "startDate", operator: "greaterThan", compareMode: "field", compareToFieldKey: "endDate" }] }],
|
|
114
|
-
targetFields: ["startDate", "endDate"],
|
|
115
|
-
errorMessage: "Start must not be after end.",
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
it("a violated rule blocks and marks every visible target", () => {
|
|
122
|
-
const state = resolveFormState(schema, { startDate: "2026-07-02", endDate: "2026-07-01" });
|
|
123
|
-
const zod = deriveZodSchema(schema, state);
|
|
124
|
-
const res = zod.safeParse({ startDate: "2026-07-02", endDate: "2026-07-01" });
|
|
125
|
-
expect(res.success).toBe(false);
|
|
126
|
-
if (!res.success) {
|
|
127
|
-
const paths = res.error.issues.map((i) => i.path.join("."));
|
|
128
|
-
expect(paths).toContain("startDate");
|
|
129
|
-
expect(paths).toContain("endDate");
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("an unviolated rule permits submission", () => {
|
|
134
|
-
const state = resolveFormState(schema, { startDate: "2026-07-01", endDate: "2026-07-02" });
|
|
135
|
-
const zod = deriveZodSchema(schema, state);
|
|
136
|
-
expect(zod.safeParse({ startDate: "2026-07-01", endDate: "2026-07-02" }).success).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("a rule with all-hidden targets still blocks via the form-level path", () => {
|
|
140
|
-
const hiddenSchema = form(
|
|
141
|
-
[
|
|
142
|
-
{ type: "text", key: "toggle" },
|
|
143
|
-
{
|
|
144
|
-
type: "date",
|
|
145
|
-
key: "startDate",
|
|
146
|
-
conditionalRules: [{ targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "toggle", operator: "equals", equalsValue: "show" }] }] }],
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
type: "date",
|
|
150
|
-
key: "endDate",
|
|
151
|
-
conditionalRules: [{ targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "toggle", operator: "equals", equalsValue: "show" }] }] }],
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
{
|
|
155
|
-
crossFieldRules: [
|
|
156
|
-
{
|
|
157
|
-
andGroups: [{ conditions: [{ dependentFieldKey: "startDate", operator: "greaterThan", compareMode: "field", compareToFieldKey: "endDate" }] }],
|
|
158
|
-
targetFields: ["startDate", "endDate"],
|
|
159
|
-
errorMessage: "Start must not be after end.",
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
},
|
|
163
|
-
);
|
|
164
|
-
const answers = { toggle: "hide", startDate: "2026-07-02", endDate: "2026-07-01" };
|
|
165
|
-
const state = resolveFormState(hiddenSchema, answers);
|
|
166
|
-
const zod = deriveZodSchema(hiddenSchema, state);
|
|
167
|
-
const res = zod.safeParse(answers);
|
|
168
|
-
expect(res.success).toBe(false);
|
|
169
|
-
if (!res.success) {
|
|
170
|
-
expect(res.error.issues.some((i) => i.path[0] === FORM_LEVEL_PATH)).toBe(true);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe("disabled/calculated diagnostics reach the host (validation spec)", () => {
|
|
176
|
-
it("a disabled field with a violating value is reported, not blocked", () => {
|
|
177
|
-
const schema = form([
|
|
178
|
-
{ type: "text", key: "code", disabled: true, validationRegex: "^[0-9]+$", errorMessage: "digits" },
|
|
179
|
-
]);
|
|
180
|
-
const answers = { code: "abc" };
|
|
181
|
-
const state = resolveFormState(schema, answers);
|
|
182
|
-
// Not blocked:
|
|
183
|
-
expect(deriveZodSchema(schema, state).safeParse(answers).success).toBe(true);
|
|
184
|
-
// But reported:
|
|
185
|
-
const diags = collectFieldDiagnostics(schema, state, answers);
|
|
186
|
-
expect(diags.some((d) => d.code === "disabled-constraint-violation")).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("a non-rendered calculated value out of range is reported, not blocked", () => {
|
|
190
|
-
const schema = form([
|
|
191
|
-
{ type: "number", key: "a" },
|
|
192
|
-
{ type: "number", key: "big", isCalculated: true, isVisibleOnForm: false, formulaExpression: "{a} * 1000", max: 10 },
|
|
193
|
-
]);
|
|
194
|
-
const answers = { a: 5 };
|
|
195
|
-
const state = resolveFormState(schema, answers);
|
|
196
|
-
const diags = collectFieldDiagnostics(schema, state, state.effectiveAnswers);
|
|
197
|
-
expect(diags.some((d) => d.code === "calculated-constraint-violation")).toBe(true);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe("repeater bounds (task 4.3)", () => {
|
|
202
|
-
const schema = form([
|
|
203
|
-
{
|
|
204
|
-
type: "repeater",
|
|
205
|
-
key: "people",
|
|
206
|
-
minItems: 1,
|
|
207
|
-
rows: [{ columns: [{ fields: [{ type: "text", key: "name", required: true }] }] }],
|
|
208
|
-
},
|
|
209
|
-
]);
|
|
210
|
-
it("fails when below minItems", () => {
|
|
211
|
-
const state = resolveFormState(schema, { people: [] });
|
|
212
|
-
expect(deriveZodSchema(schema, state).safeParse({ people: [] }).success).toBe(false);
|
|
213
|
-
});
|
|
214
|
-
it("addresses a nested child error at its array path", () => {
|
|
215
|
-
const state = resolveFormState(schema, { people: [{ name: "" }] });
|
|
216
|
-
const res = deriveZodSchema(schema, state).safeParse({ people: [{ name: "" }] });
|
|
217
|
-
expect(res.success).toBe(false);
|
|
218
|
-
if (!res.success) {
|
|
219
|
-
expect(res.error.issues.some((i) => i.path.join(".") === "people.0.name")).toBe(true);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|