@blackbelt-technology/pi-dashboard-forms-bpmn 0.7.0 → 0.9.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 +8 -4
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-workflow.mjs +14 -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
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-forms-bpmn",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Two pi skills bundled together: openforms-mui (render/author OpenForms FormSchemaJSON as themed, accessible MUI) and bpmn-package-explorer (generate/view vendor-neutral BPMN 2.0 + DMN process packages).
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Two pi skills bundled together: openforms-mui (render/author OpenForms FormSchemaJSON as themed, accessible MUI) and bpmn-package-explorer (generate/view vendor-neutral BPMN 2.0 + DMN process packages). Rendering either on the pi-dashboard canvas is documented by the dashboard extension's own canvas-webapp skill.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/BlackBeltTechnology/pi-agent-dashboard",
|
|
8
|
+
"url": "git+https://github.com/BlackBeltTechnology/pi-agent-dashboard.git",
|
|
9
9
|
"directory": "packages/pi-forms-bpmn"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
@@ -30,8 +30,7 @@
|
|
|
30
30
|
"pi": {
|
|
31
31
|
"skills": [
|
|
32
32
|
".pi/skills/openforms-mui",
|
|
33
|
-
".pi/skills/bpmn-package-explorer"
|
|
34
|
-
".pi/skills/canvas-webapp"
|
|
33
|
+
".pi/skills/bpmn-package-explorer"
|
|
35
34
|
]
|
|
36
35
|
},
|
|
37
36
|
"scripts": {
|
|
@@ -41,6 +40,9 @@
|
|
|
41
40
|
".pi/skills/",
|
|
42
41
|
"scripts/",
|
|
43
42
|
"README.md",
|
|
44
|
-
"NOTICE"
|
|
43
|
+
"NOTICE",
|
|
44
|
+
"!**/AGENTS.md",
|
|
45
|
+
"!**/*.AGENTS.md",
|
|
46
|
+
"!**/tools/tests"
|
|
45
47
|
]
|
|
46
48
|
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: canvas-webapp
|
|
3
|
-
description: >-
|
|
4
|
-
Render a React/Vite (or any bundled) web app on the pi-dashboard canvas, which
|
|
5
|
-
loads loopback URLs in a sandboxed opaque-origin iframe. Use when a
|
|
6
|
-
canvas(target:{kind:"url"|"server"}) target shows up blank white, an empty
|
|
7
|
-
surface, or a /live/<id> 500 ECONNREFUSED. Covers why Vite dev servers and
|
|
8
|
-
non-CORS static servers fail there, and the static-build + CORS-server recipe
|
|
9
|
-
that works.
|
|
10
|
-
license: MIT
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
# canvas-webapp — show a web app on the dashboard canvas
|
|
14
|
-
|
|
15
|
-
The dashboard opens a loopback `canvas(kind:"url")` target inside a
|
|
16
|
-
`sandbox="allow-scripts"` iframe with **no `allow-same-origin`** (opaque origin),
|
|
17
|
-
proxied under `/live/<id>/` (`LiveServerViewer.tsx` → `live-server-proxy`). That
|
|
18
|
-
sandbox breaks two common serving strategies; this skill is the fix.
|
|
19
|
-
|
|
20
|
-
## When to Use
|
|
21
|
-
|
|
22
|
-
Use when you must display a running web app / React / Vite / MUI mockup on the
|
|
23
|
-
pi-dashboard canvas via `canvas(target:{kind:"url"|"server"})` and it shows up
|
|
24
|
-
blank white, an empty surface, or a `/live/<id>` 500 ECONNREFUSED.
|
|
25
|
-
|
|
26
|
-
## Procedure
|
|
27
|
-
|
|
28
|
-
1. **Do NOT point the canvas at a Vite DEV server.** The dashboard proxies
|
|
29
|
-
loopback targets under `/live/<id>/`, but Vite dev emits ABSOLUTE asset paths
|
|
30
|
-
(`/main.tsx`, `/@vite/client`, and runtime fetches like `/__schema.json`) that
|
|
31
|
-
resolve against the dashboard root, not the proxy prefix → 404 → blank page.
|
|
32
|
-
2. **Produce a STATIC production build with a RELATIVE base:** a vite config with
|
|
33
|
-
`base:'./'`, a dedicated `index.html` entry, and the runtime data
|
|
34
|
-
(schema/props) IMPORTED statically (no fetch of an absolute path). Run
|
|
35
|
-
`npx vite build --config <config>`.
|
|
36
|
-
3. **Verify** the built `index.html` references `./assets/...` (relative). Copy
|
|
37
|
-
the entry html to `index.html` so the proxy root (`/live/<id>/`) serves it.
|
|
38
|
-
4. **Serve the dist with a tiny node static server that sets
|
|
39
|
-
`Access-Control-Allow-Origin: *`** (and `Cross-Origin-Resource-Policy:
|
|
40
|
-
cross-origin`) on every response. This is REQUIRED: the opaque-origin iframe
|
|
41
|
-
fetches `<script type=module>` in CORS mode with `Origin: null`, so without
|
|
42
|
-
ACAO:* the module is blocked → blank white even though the build is correct. A
|
|
43
|
-
plain `python3 -m http.server` does NOT set CORS and renders blank.
|
|
44
|
-
5. **Point the canvas:** `canvas(target:{kind:'url',
|
|
45
|
-
url:'http://127.0.0.1:<port>/'}, mode:'replace')`. Loopback is required (SSRF
|
|
46
|
-
gate); `127.0.0.1` is safest.
|
|
47
|
-
6. **Self-verify** by iframing your own harness before touching the canvas:
|
|
48
|
-
serve an HTML with `<iframe sandbox="allow-scripts allow-forms allow-popups"
|
|
49
|
-
src="http://127.0.0.1:<port>/">` on another port, open it in the browser tool,
|
|
50
|
-
and screenshot — this reproduces the exact dashboard sandbox.
|
|
51
|
-
|
|
52
|
-
## Minimal CORS static server
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
// canvas-serve.mjs — node canvas-serve.mjs <port> (serves ./canvas-dist/)
|
|
56
|
-
import { createServer } from "node:http";
|
|
57
|
-
import { readFile, stat } from "node:fs/promises";
|
|
58
|
-
import { extname, join, normalize } from "node:path";
|
|
59
|
-
const ROOT = new URL("./canvas-dist/", import.meta.url).pathname;
|
|
60
|
-
const PORT = Number(process.argv[2] ?? 5181);
|
|
61
|
-
const MIME = { ".html":"text/html;charset=utf-8", ".js":"text/javascript;charset=utf-8",
|
|
62
|
-
".css":"text/css;charset=utf-8", ".json":"application/json", ".woff":"font/woff",
|
|
63
|
-
".woff2":"font/woff2", ".svg":"image/svg+xml", ".png":"image/png", ".ico":"image/x-icon" };
|
|
64
|
-
createServer(async (req, res) => {
|
|
65
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
66
|
-
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
|
|
67
|
-
let p = decodeURIComponent((req.url ?? "/").split("?")[0]);
|
|
68
|
-
if (p.endsWith("/")) p += "index.html";
|
|
69
|
-
const full = normalize(join(ROOT, p));
|
|
70
|
-
if (!full.startsWith(ROOT)) { res.statusCode = 403; return res.end("forbidden"); }
|
|
71
|
-
const s = await stat(full).catch(() => null);
|
|
72
|
-
if (!s?.isFile()) { res.statusCode = 404; return res.end("not found"); }
|
|
73
|
-
res.setHeader("Content-Type", MIME[extname(full)] ?? "application/octet-stream");
|
|
74
|
-
res.end(await readFile(full));
|
|
75
|
-
}).listen(PORT, "127.0.0.1", () => console.log(`CORS static on http://127.0.0.1:${PORT}/`));
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Pitfalls
|
|
79
|
-
|
|
80
|
-
- bash `kill %1` job control does NOT carry across separate Bash tool calls — a
|
|
81
|
-
dev server started in one call cannot be killed by `%1` in another. Kill stale
|
|
82
|
-
servers by PID: `lsof -tiTCP:<port> -sTCP:LISTEN | xargs kill -9`.
|
|
83
|
-
- Vite dev may bind IPv6 `[::1]:<port>` only, while the dashboard proxy dials
|
|
84
|
-
IPv4 `127.0.0.1:<port>` → the `/live/<id>` route returns 500
|
|
85
|
-
`FST_REPLY_FROM_INTERNAL_SERVER_ERROR 'connect ECONNREFUSED 127.0.0.1:<port>'`.
|
|
86
|
-
Another reason to avoid dev servers and bind static servers explicitly to
|
|
87
|
-
`127.0.0.1`.
|
|
88
|
-
- `canvas(target:{kind:'server', port})` produces a tap-to-open CHIP on desktop,
|
|
89
|
-
not an auto-opened view; `kind:'url'` with a loopback URL auto-opens via
|
|
90
|
-
`openLiveTarget`. Prefer `kind:'url'`.
|
|
91
|
-
- The build succeeds and renders fine in a NORMAL browser tab yet is blank in the
|
|
92
|
-
dashboard — that difference is the sandbox/CORS issue, not a build bug. Don't
|
|
93
|
-
chase the build.
|
|
94
|
-
- Non-loopback/remote URLs are refused by the dashboard SSRF gate
|
|
95
|
-
(`validateLiveTarget`).
|
|
96
|
-
|
|
97
|
-
## Verification
|
|
98
|
-
|
|
99
|
-
1. The static server responds 200 with header `Access-Control-Allow-Origin: *`
|
|
100
|
-
(`curl -D - -o /dev/null`).
|
|
101
|
-
2. An `<iframe sandbox="allow-scripts">` pointed at the server renders the app
|
|
102
|
-
(browser-tool screenshot), matching the dashboard's opaque-origin sandbox.
|
|
103
|
-
3. After `canvas(kind:'url')`, the user confirms the app is visible on the canvas
|
|
104
|
-
(not blank, no 500).
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } 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 } from "@testing-library/react";
|
|
6
|
-
import axe from "axe-core";
|
|
7
|
-
import { OpenFormsMui } from "../src/OpenFormsMui";
|
|
8
|
-
import { themeFromTokens, defaultTheme } from "../src/theme/from-tokens";
|
|
9
|
-
import type { FormSchemaJSON } from "../src/schema/types";
|
|
10
|
-
|
|
11
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const allTypes = JSON.parse(
|
|
13
|
-
readFileSync(join(here, "fixtures", "all-field-types.json"), "utf8"),
|
|
14
|
-
) as FormSchemaJSON;
|
|
15
|
-
|
|
16
|
-
async function runAxe(container: HTMLElement) {
|
|
17
|
-
// Colour-contrast cannot run without layout in jsdom; disable it and assert on
|
|
18
|
-
// the structural rules (labels, roles, names) that DO run.
|
|
19
|
-
const results = await axe.run(container, {
|
|
20
|
-
rules: { "color-contrast": { enabled: false } },
|
|
21
|
-
});
|
|
22
|
-
return results.violations.filter((v) => v.impact === "serious" || v.impact === "critical");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("token layer ports 1:1 into the default theme (task 10.0)", () => {
|
|
26
|
-
it("themeFromTokens(ui-contract.tokens.json) equals the default theme palette", () => {
|
|
27
|
-
const tokens = JSON.parse(readFileSync(join(here, "..", "mockups", "ui-contract.tokens.json"), "utf8"));
|
|
28
|
-
const fromTokens = themeFromTokens(tokens);
|
|
29
|
-
const dft = defaultTheme();
|
|
30
|
-
expect(fromTokens.palette.primary.main).toBe(dft.palette.primary.main);
|
|
31
|
-
expect(fromTokens.palette.warning.main).toBe(dft.palette.warning.main);
|
|
32
|
-
expect(fromTokens.shape.borderRadius).toBe(dft.shape.borderRadius);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe("automated accessibility gate (tasks 10.1, 10.4)", () => {
|
|
37
|
-
let container: HTMLElement;
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
const view = render(<OpenFormsMui schema={allTypes} />);
|
|
40
|
-
container = view.container;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("reports no serious or critical violations across all 14 field types", async () => {
|
|
44
|
-
const violations = await runAxe(container);
|
|
45
|
-
expect(violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe("grouped controls expose accessible names (task 10.2)", () => {
|
|
50
|
-
it("matrix, radio and checkbox groups are labelled", () => {
|
|
51
|
-
render(<OpenFormsMui schema={allTypes} />);
|
|
52
|
-
// Radio group legend.
|
|
53
|
-
expect(screen.getByText("Preferred contact")).toBeInTheDocument();
|
|
54
|
-
// Matrix is a labelled table.
|
|
55
|
-
expect(screen.getByRole("table", { name: "Satisfaction" })).toBeInTheDocument();
|
|
56
|
-
// Repeater legend.
|
|
57
|
-
expect(screen.getByText("People")).toBeInTheDocument();
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe("signature has an accessible name and clear control (task 10.3)", () => {
|
|
62
|
-
it("exposes role img with a name and a keyboard-reachable clear button", () => {
|
|
63
|
-
render(<OpenFormsMui schema={allTypes} />);
|
|
64
|
-
expect(screen.getByRole("img", { name: /signature/i })).toBeInTheDocument();
|
|
65
|
-
expect(screen.getByRole("button", { name: "Clear" })).toBeInTheDocument();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("error summary uses the error surface, warnings do not (task 10.9)", () => {
|
|
70
|
-
it("a blocked submit renders an alert on the error surface", async () => {
|
|
71
|
-
const schema: FormSchemaJSON = {
|
|
72
|
-
pages: [{ sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "r", label: "R", required: true }] }] }] }] }],
|
|
73
|
-
} as FormSchemaJSON;
|
|
74
|
-
const { container } = render(<OpenFormsMui schema={schema} />);
|
|
75
|
-
const form = container.querySelector("form")!;
|
|
76
|
-
form.requestSubmit();
|
|
77
|
-
const alert = await screen.findByRole("alert");
|
|
78
|
-
// MUI error Alert carries the error colour class; never the warning one.
|
|
79
|
-
expect(alert.className).toMatch(/MuiAlert-(standardError|colorError|filledError|outlinedError)/);
|
|
80
|
-
expect(alert.className).not.toMatch(/Warning/);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { readdirSync, readFileSync, writeFileSync, mkdtempSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { dirname, join } from "node:path";
|
|
7
|
-
|
|
8
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const root = join(here, "..");
|
|
10
|
-
const cli = join(root, "preview", "cli.ts");
|
|
11
|
-
const tsx = join(root, "node_modules", ".bin", "tsx");
|
|
12
|
-
const fixture = join(here, "fixtures", "all-field-types.json");
|
|
13
|
-
|
|
14
|
-
function runCli(args: string[]): { status: number; stdout: string; stderr: string } {
|
|
15
|
-
try {
|
|
16
|
-
const stdout = execFileSync(tsx, [cli, ...args], { encoding: "utf8" });
|
|
17
|
-
return { status: 0, stdout, stderr: "" };
|
|
18
|
-
} catch (e) {
|
|
19
|
-
const err = e as { status?: number; stdout?: string; stderr?: string };
|
|
20
|
-
return { status: err.status ?? 1, stdout: err.stdout ?? "", stderr: err.stderr ?? "" };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe("CLI diagnose (task 8.1)", () => {
|
|
25
|
-
it("reports no error findings for a clean fixture and exits 0", () => {
|
|
26
|
-
const { status, stdout } = runCli(["diagnose", fixture]);
|
|
27
|
-
expect(status).toBe(0);
|
|
28
|
-
expect(stdout).not.toContain("[ERROR]");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("exits non-zero when a schema has an error finding (duplicate key)", () => {
|
|
32
|
-
const dir = mkdtempSync(join(tmpdir(), "ofm-"));
|
|
33
|
-
const bad = join(dir, "bad.json");
|
|
34
|
-
writeFileSync(
|
|
35
|
-
bad,
|
|
36
|
-
JSON.stringify({
|
|
37
|
-
pages: [{ sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "d" }, { type: "text", key: "d" }] }] }] }] }],
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
40
|
-
const { status, stdout } = runCli(["diagnose", bad]);
|
|
41
|
-
expect(status).toBe(1);
|
|
42
|
-
expect(stdout).toContain("duplicate-key");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("reports invalid input clearly without a stack trace", () => {
|
|
46
|
-
const dir = mkdtempSync(join(tmpdir(), "ofm-"));
|
|
47
|
-
const bad = join(dir, "notjson.json");
|
|
48
|
-
writeFileSync(bad, "{ not valid json");
|
|
49
|
-
const { status, stderr } = runCli(["diagnose", bad]);
|
|
50
|
-
expect(status).toBe(1);
|
|
51
|
-
expect(stderr).toContain("not valid JSON");
|
|
52
|
-
expect(stderr).not.toContain("at Object.");
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("reference renderer is excluded from the library (task 8.4)", () => {
|
|
57
|
-
it("no src/ file loads the upstream renderer CDN", () => {
|
|
58
|
-
const offenders: string[] = [];
|
|
59
|
-
const walk = (dir: string) => {
|
|
60
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
61
|
-
const full = join(dir, entry.name);
|
|
62
|
-
if (entry.isDirectory()) walk(full);
|
|
63
|
-
else if (/\.(ts|tsx)$/.test(entry.name)) {
|
|
64
|
-
const code = readFileSync(full, "utf8");
|
|
65
|
-
// The provenance constant may NAME the CDN base; but no src file may
|
|
66
|
-
// actually load renderer.js or reference the vanilla globals.
|
|
67
|
-
if (/renderer\.js/.test(code) || /OpenFormRenderer/.test(code)) offenders.push(full);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
walk(join(root, "src"));
|
|
72
|
-
expect(offenders, offenders.join("\n")).toEqual([]);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
import type { Field, FormAnswers, FormSchemaJSON } from "../src/schema/types";
|
|
5
|
-
import { OpenFormsMui } from "../src/OpenFormsMui";
|
|
6
|
-
import type { SubmissionMeta } from "../src/payload";
|
|
7
|
-
|
|
8
|
-
function form(fields: Field[], extra?: Partial<FormSchemaJSON>): FormSchemaJSON {
|
|
9
|
-
return { pages: [{ sections: [{ rows: [{ columns: [{ fields }] }] }] }], ...extra } as FormSchemaJSON;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function renderForm(schema: FormSchemaJSON, props: Record<string, unknown> = {}) {
|
|
13
|
-
const onSubmit = vi.fn<(a: FormAnswers, m: SubmissionMeta) => void>();
|
|
14
|
-
render(<OpenFormsMui schema={schema} onSubmit={onSubmit} {...props} />);
|
|
15
|
-
return { onSubmit };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function submit() {
|
|
19
|
-
await userEvent.click(screen.getByRole("button", { name: "Submit" }));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe("value shapes on submit (task 6.13)", () => {
|
|
23
|
-
it("text, number, boolean and checkbox produce their documented shapes", async () => {
|
|
24
|
-
const schema = form([
|
|
25
|
-
{ type: "text", key: "name" },
|
|
26
|
-
{ type: "number", key: "age" },
|
|
27
|
-
{ type: "boolean", key: "agree" },
|
|
28
|
-
{ type: "checkbox", key: "picks", options: [{ value: "a", label: "A" }, { value: "b", label: "B" }] },
|
|
29
|
-
]);
|
|
30
|
-
const { onSubmit } = renderForm(schema);
|
|
31
|
-
await userEvent.type(screen.getByLabelText("name"), "Ada");
|
|
32
|
-
await userEvent.type(screen.getByLabelText("age"), "42");
|
|
33
|
-
await userEvent.click(screen.getByLabelText("agree"));
|
|
34
|
-
await userEvent.click(screen.getByLabelText("A"));
|
|
35
|
-
await submit();
|
|
36
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
37
|
-
const [answers] = onSubmit.mock.calls[0];
|
|
38
|
-
expect(answers).toMatchObject({ name: "Ada", age: 42, agree: true, picks: ["a"] });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("header and paragraph contribute no answer keys", async () => {
|
|
42
|
-
const schema = form([
|
|
43
|
-
{ type: "header", key: "h" },
|
|
44
|
-
{ type: "paragraph", key: "p" },
|
|
45
|
-
{ type: "text", key: "t" },
|
|
46
|
-
]);
|
|
47
|
-
const { onSubmit } = renderForm(schema);
|
|
48
|
-
await submit();
|
|
49
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
50
|
-
const [answers] = onSubmit.mock.calls[0];
|
|
51
|
-
expect(answers).not.toHaveProperty("h");
|
|
52
|
-
expect(answers).not.toHaveProperty("p");
|
|
53
|
-
expect(answers).toHaveProperty("t", "");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("signature carries a prefilled base64 PNG through to the payload", async () => {
|
|
57
|
-
const dataUrl = "data:image/png;base64,AAAA";
|
|
58
|
-
const schema = form([{ type: "signature", key: "sig" }]);
|
|
59
|
-
const { onSubmit } = renderForm(schema, { answers: { sig: dataUrl } });
|
|
60
|
-
await submit();
|
|
61
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
62
|
-
expect(onSubmit.mock.calls[0][0].sig).toBe(dataUrl);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("file produces { name, size, type, content } and not a raw File", async () => {
|
|
66
|
-
const schema = form([{ type: "file", key: "doc", maxFileSizeMB: 5 }]);
|
|
67
|
-
const { onSubmit } = renderForm(schema);
|
|
68
|
-
const input = document.getElementById("doc") as HTMLInputElement;
|
|
69
|
-
const file = new File(["hello"], "hello.txt", { type: "text/plain" });
|
|
70
|
-
fireEvent.change(input, { target: { files: [file] } });
|
|
71
|
-
await screen.findAllByText(/hello\.txt/);
|
|
72
|
-
await submit();
|
|
73
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
74
|
-
const doc = onSubmit.mock.calls[0][0].doc as { name: string; size: number; type: string; content: string };
|
|
75
|
-
expect(doc.name).toBe("hello.txt");
|
|
76
|
-
expect(doc.type).toBe("text/plain");
|
|
77
|
-
expect(typeof doc.content).toBe("string");
|
|
78
|
-
expect(doc.content.startsWith("data:")).toBe(true);
|
|
79
|
-
expect(doc instanceof File).toBe(false);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("rejects an oversized file without encoding it", async () => {
|
|
83
|
-
const schema = form([{ type: "file", key: "doc", maxFileSizeMB: 0.00001 }]);
|
|
84
|
-
const { onSubmit } = renderForm(schema);
|
|
85
|
-
const input = document.getElementById("doc") as HTMLInputElement;
|
|
86
|
-
const big = new File([new Uint8Array(1024)], "big.bin", { type: "application/octet-stream" });
|
|
87
|
-
fireEvent.change(input, { target: { files: [big] } });
|
|
88
|
-
await screen.findByText(/too large/i);
|
|
89
|
-
await submit();
|
|
90
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
91
|
-
expect(onSubmit.mock.calls[0][0].doc).toBeNull();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe("payload contract (tasks 7.4, 7.4a, 7.4b, 7.4c, 7.4h)", () => {
|
|
96
|
-
it("omits a conditionally hidden field and includes a disabled one", async () => {
|
|
97
|
-
const schema = form([
|
|
98
|
-
{ type: "text", key: "toggle" },
|
|
99
|
-
{ type: "text", key: "prefilled", disabled: true },
|
|
100
|
-
{
|
|
101
|
-
type: "text",
|
|
102
|
-
key: "secret",
|
|
103
|
-
conditionalRules: [
|
|
104
|
-
{ targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "toggle", operator: "equals", equalsValue: "show" }] }] },
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
]);
|
|
108
|
-
const { onSubmit } = renderForm(schema, { answers: { prefilled: "sys", secret: "kept" } });
|
|
109
|
-
await submit();
|
|
110
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
111
|
-
const [answers] = onSubmit.mock.calls[0];
|
|
112
|
-
expect(answers).toHaveProperty("prefilled", "sys"); // disabled included (7.4b)
|
|
113
|
-
expect(answers).not.toHaveProperty("secret"); // hidden omitted
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("includes a hidden calculated field but omits it in a hidden branch (7.4a)", async () => {
|
|
117
|
-
const visibleCalc = form([
|
|
118
|
-
{ type: "number", key: "a" },
|
|
119
|
-
{ type: "number", key: "sum", isCalculated: true, isVisibleOnForm: false, formulaExpression: "{a} + 1" },
|
|
120
|
-
]);
|
|
121
|
-
const { onSubmit } = renderForm(visibleCalc, { answers: { a: 4 } });
|
|
122
|
-
await submit();
|
|
123
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
124
|
-
expect(onSubmit.mock.calls[0][0].sum).toBe(5);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("emits per-type empty values that survive JSON round-trip", async () => {
|
|
128
|
-
const schema = form([
|
|
129
|
-
{ type: "text", key: "t" },
|
|
130
|
-
{ type: "number", key: "n" },
|
|
131
|
-
{ type: "checkbox", key: "c", options: [] },
|
|
132
|
-
]);
|
|
133
|
-
const { onSubmit } = renderForm(schema);
|
|
134
|
-
await submit();
|
|
135
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
136
|
-
const [answers] = onSubmit.mock.calls[0];
|
|
137
|
-
const round = JSON.parse(JSON.stringify(answers));
|
|
138
|
-
expect(round).toHaveProperty("t", "");
|
|
139
|
-
expect(round).toHaveProperty("n", null);
|
|
140
|
-
expect(round).toHaveProperty("c");
|
|
141
|
-
expect(round.c).toEqual([]);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("repeater yields one array of rows with every child key (number child null)", async () => {
|
|
145
|
-
const schema = form([
|
|
146
|
-
{
|
|
147
|
-
type: "repeater",
|
|
148
|
-
key: "people",
|
|
149
|
-
rows: [{ columns: [{ fields: [{ type: "text", key: "name" }, { type: "number", key: "qty" }] }] }],
|
|
150
|
-
},
|
|
151
|
-
]);
|
|
152
|
-
const { onSubmit } = renderForm(schema);
|
|
153
|
-
await userEvent.click(screen.getByRole("button", { name: "Add" }));
|
|
154
|
-
await submit();
|
|
155
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
156
|
-
const [answers] = onSubmit.mock.calls[0];
|
|
157
|
-
const people = answers.people as Array<Record<string, unknown>>;
|
|
158
|
-
expect(Array.isArray(people)).toBe(true);
|
|
159
|
-
expect(people).toHaveLength(1);
|
|
160
|
-
expect(people[0]).toEqual({ name: "", qty: null });
|
|
161
|
-
expect(answers).not.toHaveProperty("name");
|
|
162
|
-
expect(answers).not.toHaveProperty("qty");
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe("submission gating and segregation (tasks 7.4f, 7.4g, 7.4e, 7.6, 7.7)", () => {
|
|
167
|
-
it("blocks on duplicate keys and never calls onSubmit", async () => {
|
|
168
|
-
const schema = form([{ type: "text", key: "dup" }, { type: "text", key: "dup" }]);
|
|
169
|
-
const { onSubmit } = renderForm(schema);
|
|
170
|
-
await submit();
|
|
171
|
-
await screen.findByRole("alert");
|
|
172
|
-
expect(onSubmit).not.toHaveBeenCalled();
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("readOnly renders no submit control", () => {
|
|
176
|
-
const schema = form([{ type: "text", key: "t" }]);
|
|
177
|
-
renderForm(schema, { readOnly: true, answers: { t: "x" } });
|
|
178
|
-
expect(screen.queryByRole("button", { name: "Submit" })).toBeNull();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("delivers submissionContext and diagnostics as the second argument, segregated from answers", async () => {
|
|
182
|
-
const schema = form([{ type: "text", key: "ctxKey" }]);
|
|
183
|
-
const context = { ctxKey: "not-an-answer", tenant: "acme" };
|
|
184
|
-
const { onSubmit } = renderForm(schema, { submissionContext: context, answers: { ctxKey: "real" } });
|
|
185
|
-
await submit();
|
|
186
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
187
|
-
const [answers, meta] = onSubmit.mock.calls[0];
|
|
188
|
-
expect(answers.ctxKey).toBe("real"); // untouched by the context member of the same name
|
|
189
|
-
expect(meta.submissionContext).toEqual(context);
|
|
190
|
-
expect(Array.isArray(meta.diagnostics)).toBe(true);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe("change notifications (task 7.4i)", () => {
|
|
195
|
-
it("onFieldChange reports retained hidden values", async () => {
|
|
196
|
-
const schema = form([
|
|
197
|
-
{ type: "text", key: "toggle" },
|
|
198
|
-
{
|
|
199
|
-
type: "text",
|
|
200
|
-
key: "dep",
|
|
201
|
-
conditionalRules: [
|
|
202
|
-
{ targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "toggle", operator: "equals", equalsValue: "show" }] }] },
|
|
203
|
-
],
|
|
204
|
-
},
|
|
205
|
-
]);
|
|
206
|
-
const onFieldChange = vi.fn();
|
|
207
|
-
render(<OpenFormsMui schema={schema} answers={{ toggle: "show" }} onFieldChange={onFieldChange} />);
|
|
208
|
-
await userEvent.type(screen.getByLabelText("dep"), "hi");
|
|
209
|
-
// Hide it again:
|
|
210
|
-
await userEvent.clear(screen.getByLabelText("toggle"));
|
|
211
|
-
await userEvent.type(screen.getByLabelText("toggle"), "hide");
|
|
212
|
-
await waitFor(() => {
|
|
213
|
-
const last = onFieldChange.mock.calls.at(-1)?.[0];
|
|
214
|
-
expect(last).toBeDefined();
|
|
215
|
-
expect(last.dep).toBe("hi"); // retained even though now hidden
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe("multi-page wizard (task 7.3)", () => {
|
|
221
|
-
const schema: FormSchemaJSON = {
|
|
222
|
-
pages: [
|
|
223
|
-
{ title: "One", sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "a", required: true }] }] }] }] },
|
|
224
|
-
{ title: "Two", sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "b" }] }] }] }] },
|
|
225
|
-
],
|
|
226
|
-
} as FormSchemaJSON;
|
|
227
|
-
|
|
228
|
-
it("shows a stepper and blocks advance while the page is invalid", async () => {
|
|
229
|
-
renderForm(schema);
|
|
230
|
-
expect(screen.getByText("One")).toBeInTheDocument();
|
|
231
|
-
expect(screen.getByText("Two")).toBeInTheDocument();
|
|
232
|
-
await userEvent.click(screen.getByRole("button", { name: "Next" }));
|
|
233
|
-
// Still on page one because required "a" is empty.
|
|
234
|
-
await screen.findByRole("alert");
|
|
235
|
-
expect(screen.getByLabelText("a")).toBeInTheDocument();
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("single-page form has no stepper", () => {
|
|
239
|
-
renderForm(form([{ type: "text", key: "x" }]));
|
|
240
|
-
expect(screen.queryByRole("button", { name: "Next" })).toBeNull();
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
describe("integration end to end (task 7.14)", () => {
|
|
245
|
-
it("exercises conditional visibility, a cross-field rule, and a calculated field", async () => {
|
|
246
|
-
const schema: FormSchemaJSON = {
|
|
247
|
-
pages: [
|
|
248
|
-
{
|
|
249
|
-
sections: [
|
|
250
|
-
{
|
|
251
|
-
rows: [
|
|
252
|
-
{ columns: [{ fields: [{ type: "number", key: "hours" }] }] },
|
|
253
|
-
{ columns: [{ fields: [{ type: "number", key: "rate" }] }] },
|
|
254
|
-
{ columns: [{ fields: [{ type: "number", key: "total", isCalculated: true, formulaExpression: "{hours} * {rate}" }] }] },
|
|
255
|
-
{
|
|
256
|
-
columns: [
|
|
257
|
-
{
|
|
258
|
-
fields: [
|
|
259
|
-
{
|
|
260
|
-
type: "text",
|
|
261
|
-
key: "approver",
|
|
262
|
-
required: true,
|
|
263
|
-
conditionalRules: [
|
|
264
|
-
{ targetProperty: "visibility", andGroups: [{ conditions: [{ dependentFieldKey: "total", operator: "greaterThan", equalsValue: 100 }] }] },
|
|
265
|
-
],
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
],
|
|
270
|
-
},
|
|
271
|
-
],
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
},
|
|
275
|
-
],
|
|
276
|
-
} as FormSchemaJSON;
|
|
277
|
-
|
|
278
|
-
const { onSubmit } = renderForm(schema);
|
|
279
|
-
await userEvent.type(screen.getByLabelText("hours"), "10");
|
|
280
|
-
await userEvent.type(screen.getByLabelText("rate"), "20");
|
|
281
|
-
// total = 200 -> approver revealed and required (label carries a " *" marker).
|
|
282
|
-
const approver = await screen.findByLabelText(/approver/);
|
|
283
|
-
expect(approver).toBeInTheDocument();
|
|
284
|
-
await submit();
|
|
285
|
-
// Blocked: approver required but empty.
|
|
286
|
-
await screen.findByRole("alert");
|
|
287
|
-
expect(onSubmit).not.toHaveBeenCalled();
|
|
288
|
-
await userEvent.type(approver, "Jane");
|
|
289
|
-
await submit();
|
|
290
|
-
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
291
|
-
const [answers] = onSubmit.mock.calls[0];
|
|
292
|
-
expect(answers.total).toBe(200);
|
|
293
|
-
expect(answers.approver).toBe("Jane");
|
|
294
|
-
});
|
|
295
|
-
});
|