@blackbelt-technology/pi-dashboard-forms-bpmn 0.7.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 +120 -0
- package/.pi/skills/bpmn-package-explorer/assets/LICENSE.bpmn-io.txt +23 -0
- package/.pi/skills/bpmn-package-explorer/assets/VENDORED.md +90 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-codes.css +108 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-embedded.css +166 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn.css +164 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.eot +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.svg +224 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.ttf +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff2 +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-navigated-viewer.production.min.js +22 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn.css +145 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/diagram-js.css +1249 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/diagram-js.css +1133 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-codes.css +41 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-embedded.css +98 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn.css +97 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.eot +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.svg +90 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.ttf +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff2 +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-decision-table.css +580 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-drd.css +108 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-literal-expression.css +165 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-shared.css +221 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-viewer.production.min.js +16 -0
- package/.pi/skills/bpmn-package-explorer/assets/lib/bpmn-pipeline.mjs +6981 -0
- package/.pi/skills/bpmn-package-explorer/assets/lib/yaml.mjs +7372 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g1-identical-bounds.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g2-zero-size.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g3-child-outside.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g4-negative-coord.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g5-overlap.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/1-linear.bpmn +12 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/2-gateway.bpmn +19 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/3-boundary.bpmn +13 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/4-subprocess.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/5-pools.bpmn +21 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/6-lanes-only.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/7-loop.bpmn +13 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/8-long-chain.bpmn +32 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/nesting/expanded-subprocess-ok.bpmn +25 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/call-activity.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-catch.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-throw.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/manual-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/multi-boundary.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/parallel-gateway.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/receive-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/rule-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/script-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/send-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/references/authoring-envelope.md +52 -0
- package/.pi/skills/bpmn-package-explorer/references/identifiers.md +102 -0
- package/.pi/skills/bpmn-package-explorer/references/layout-envelope.md +105 -0
- package/.pi/skills/bpmn-package-explorer/references/licensing.md +48 -0
- package/.pi/skills/bpmn-package-explorer/references/package-manifest.md +104 -0
- package/.pi/skills/bpmn-package-explorer/scripts/build-fixtures.mjs +299 -0
- package/.pi/skills/bpmn-package-explorer/scripts/demo.mjs +128 -0
- package/.pi/skills/bpmn-package-explorer/scripts/diagnostics.mjs +37 -0
- package/.pi/skills/bpmn-package-explorer/scripts/envelope.mjs +160 -0
- package/.pi/skills/bpmn-package-explorer/scripts/fixtures.mjs +140 -0
- package/.pi/skills/bpmn-package-explorer/scripts/generate-cli.mjs +31 -0
- package/.pi/skills/bpmn-package-explorer/scripts/generate.mjs +103 -0
- package/.pi/skills/bpmn-package-explorer/scripts/guard.mjs +335 -0
- package/.pi/skills/bpmn-package-explorer/scripts/harness.mjs +12 -0
- package/.pi/skills/bpmn-package-explorer/scripts/identifiers.mjs +117 -0
- package/.pi/skills/bpmn-package-explorer/scripts/ingest.mjs +95 -0
- package/.pi/skills/bpmn-package-explorer/scripts/manifest.mjs +374 -0
- package/.pi/skills/bpmn-package-explorer/scripts/pipeline.mjs +49 -0
- package/.pi/skills/bpmn-package-explorer/scripts/render.mjs +130 -0
- package/.pi/skills/bpmn-package-explorer/scripts/runguard.mjs +38 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-e2e.mjs +87 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-guard.mjs +99 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-manifest.mjs +170 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-more.mjs +87 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-workflow.mjs +73 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest.mjs +57 -0
- package/.pi/skills/bpmn-package-explorer/scripts/vendor.mjs +141 -0
- package/.pi/skills/bpmn-package-explorer/scripts/view-cli.mjs +19 -0
- package/.pi/skills/bpmn-package-explorer/templates/shell.html +141 -0
- package/.pi/skills/bpmn-package-explorer/templates/viewer.js +301 -0
- package/.pi/skills/canvas-webapp/SKILL.md +104 -0
- package/.pi/skills/openforms-mui/SKILL.md +187 -0
- package/.pi/skills/openforms-mui/references/a11y.md +68 -0
- package/.pi/skills/openforms-mui/references/field-widget-map.md +64 -0
- package/.pi/skills/openforms-mui/references/hu-locale.md +45 -0
- package/.pi/skills/openforms-mui/references/logic.md +94 -0
- package/.pi/skills/openforms-mui/references/schema.md +94 -0
- package/.pi/skills/openforms-mui/references/theme-bridge.md +65 -0
- package/.pi/skills/openforms-mui/tools/canvas-serve.mjs +51 -0
- package/.pi/skills/openforms-mui/tools/demo-schema.json +80 -0
- package/.pi/skills/openforms-mui/tools/mockups/tokens.css +27 -0
- package/.pi/skills/openforms-mui/tools/mockups/ui-contract.tokens.json +16 -0
- package/.pi/skills/openforms-mui/tools/package-lock.json +5919 -0
- package/.pi/skills/openforms-mui/tools/package.json +61 -0
- package/.pi/skills/openforms-mui/tools/preview/RenderPanel.tsx +105 -0
- package/.pi/skills/openforms-mui/tools/preview/canvas-app.tsx +66 -0
- package/.pi/skills/openforms-mui/tools/preview/canvas-index.html +16 -0
- package/.pi/skills/openforms-mui/tools/preview/cli.ts +99 -0
- package/.pi/skills/openforms-mui/tools/preview/index.html +17 -0
- package/.pi/skills/openforms-mui/tools/preview/main.tsx +228 -0
- package/.pi/skills/openforms-mui/tools/preview/vite-plugin.ts +41 -0
- package/.pi/skills/openforms-mui/tools/scripts/assert-peer-deps.mjs +39 -0
- package/.pi/skills/openforms-mui/tools/src/OpenFormsMui.tsx +391 -0
- package/.pi/skills/openforms-mui/tools/src/css.d.ts +2 -0
- package/.pi/skills/openforms-mui/tools/src/fields/ErrorSummary.tsx +72 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FieldRenderer.tsx +328 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FieldShell.tsx +50 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FileField.tsx +91 -0
- package/.pi/skills/openforms-mui/tools/src/fields/MatrixField.tsx +146 -0
- package/.pi/skills/openforms-mui/tools/src/fields/RepeaterField.tsx +82 -0
- package/.pi/skills/openforms-mui/tools/src/fields/SignatureCanvas.tsx +121 -0
- package/.pi/skills/openforms-mui/tools/src/fields/context.tsx +34 -0
- package/.pi/skills/openforms-mui/tools/src/fields/index.ts +7 -0
- package/.pi/skills/openforms-mui/tools/src/fields/label.ts +42 -0
- package/.pi/skills/openforms-mui/tools/src/fonts.ts +8 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/dictionary.ts +58 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/hu.ts +56 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/index.ts +43 -0
- package/.pi/skills/openforms-mui/tools/src/index.ts +27 -0
- package/.pi/skills/openforms-mui/tools/src/logic/cnf.ts +206 -0
- package/.pi/skills/openforms-mui/tools/src/logic/formula.ts +285 -0
- package/.pi/skills/openforms-mui/tools/src/logic/index.ts +4 -0
- package/.pi/skills/openforms-mui/tools/src/logic/operators.ts +43 -0
- package/.pi/skills/openforms-mui/tools/src/logic/state.ts +183 -0
- package/.pi/skills/openforms-mui/tools/src/payload.ts +83 -0
- package/.pi/skills/openforms-mui/tools/src/provenance.ts +21 -0
- package/.pi/skills/openforms-mui/tools/src/schema/diagnose.ts +256 -0
- package/.pi/skills/openforms-mui/tools/src/schema/index.ts +4 -0
- package/.pi/skills/openforms-mui/tools/src/schema/normalize.ts +163 -0
- package/.pi/skills/openforms-mui/tools/src/schema/types.ts +299 -0
- package/.pi/skills/openforms-mui/tools/src/schema/walk.ts +68 -0
- package/.pi/skills/openforms-mui/tools/src/theme/from-tokens.ts +102 -0
- package/.pi/skills/openforms-mui/tools/src/theme/index.ts +1 -0
- package/.pi/skills/openforms-mui/tools/src/validation/constrain.ts +83 -0
- package/.pi/skills/openforms-mui/tools/src/validation/diagnostics.ts +62 -0
- package/.pi/skills/openforms-mui/tools/src/validation/empty.ts +53 -0
- package/.pi/skills/openforms-mui/tools/src/validation/index.ts +5 -0
- package/.pi/skills/openforms-mui/tools/src/validation/resolver.ts +14 -0
- package/.pi/skills/openforms-mui/tools/src/validation/zod-from-schema.ts +169 -0
- package/.pi/skills/openforms-mui/tools/tests/a11y.test.tsx +82 -0
- package/.pi/skills/openforms-mui/tools/tests/cli.test.ts +74 -0
- package/.pi/skills/openforms-mui/tools/tests/component.test.tsx +295 -0
- package/.pi/skills/openforms-mui/tools/tests/diagnose.test.ts +163 -0
- package/.pi/skills/openforms-mui/tools/tests/fixtures/all-field-types.json +45 -0
- package/.pi/skills/openforms-mui/tools/tests/logic.test.ts +175 -0
- package/.pi/skills/openforms-mui/tools/tests/normalize.test.ts +105 -0
- package/.pi/skills/openforms-mui/tools/tests/reference-semantics.test.ts +131 -0
- package/.pi/skills/openforms-mui/tools/tests/responsive.test.tsx +158 -0
- package/.pi/skills/openforms-mui/tools/tests/setup.ts +16 -0
- package/.pi/skills/openforms-mui/tools/tests/singleton.test.tsx +31 -0
- package/.pi/skills/openforms-mui/tools/tests/theme.test.ts +65 -0
- package/.pi/skills/openforms-mui/tools/tests/toolchain.test.ts +33 -0
- package/.pi/skills/openforms-mui/tools/tests/validation.test.ts +222 -0
- package/.pi/skills/openforms-mui/tools/tsconfig.json +21 -0
- package/.pi/skills/openforms-mui/tools/vite.canvas.config.ts +21 -0
- package/.pi/skills/openforms-mui/tools/vitest.config.ts +17 -0
- package/NOTICE +46 -0
- package/README.md +62 -0
- package/package.json +46 -0
- package/scripts/ensure-openforms-deps.mjs +38 -0
|
@@ -0,0 +1,295 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|