@formspec/build 0.1.0-alpha.2 → 0.1.0-alpha.21
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/README.md +120 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts +9 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts.map +1 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts +2 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts.map +1 -0
- package/dist/__tests__/class-schema.test.d.ts +2 -0
- package/dist/__tests__/class-schema.test.d.ts.map +1 -0
- package/dist/__tests__/constraint-validator.test.d.ts +2 -0
- package/dist/__tests__/constraint-validator.test.d.ts.map +1 -0
- package/dist/__tests__/date-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/date-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/extension-api.test.d.ts +2 -0
- package/dist/__tests__/extension-api.test.d.ts.map +1 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts +2 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts.map +1 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts +37 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts.map +1 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts +86 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts.map +1 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts +132 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts +31 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts +12 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts +107 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts +20 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts +7 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts +31 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts.map +1 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts +15 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts +14 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts.map +1 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts +65 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts.map +1 -0
- package/dist/__tests__/generate-schemas.test.d.ts +2 -0
- package/dist/__tests__/generate-schemas.test.d.ts.map +1 -0
- package/dist/__tests__/guards.test.d.ts +2 -0
- package/dist/__tests__/guards.test.d.ts.map +1 -0
- package/dist/__tests__/ir-analyzer.test.d.ts +11 -0
- package/dist/__tests__/ir-analyzer.test.d.ts.map +1 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts +12 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts.map +1 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts +11 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts +2 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/mixed-authoring.test.d.ts +2 -0
- package/dist/__tests__/mixed-authoring.test.d.ts.map +1 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts +17 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts +13 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts +28 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts +12 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/parity.test.d.ts +18 -0
- package/dist/__tests__/parity/parity.test.d.ts.map +1 -0
- package/dist/__tests__/parity/utils.d.ts +152 -0
- package/dist/__tests__/parity/utils.d.ts.map +1 -0
- package/dist/__tests__/path-target-parser.test.d.ts +9 -0
- package/dist/__tests__/path-target-parser.test.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts +100 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -0
- package/dist/analyzer/jsdoc-constraints.d.ts +53 -0
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
- package/dist/analyzer/program.d.ts +68 -0
- package/dist/analyzer/program.d.ts.map +1 -0
- package/dist/analyzer/tsdoc-parser.d.ts +123 -0
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
- package/dist/browser.cjs +1294 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +73 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1245 -0
- package/dist/browser.js.map +1 -0
- package/dist/build.d.ts +1144 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +18 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
- package/dist/canonicalize/index.d.ts +8 -0
- package/dist/canonicalize/index.d.ts.map +1 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts +34 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
- package/dist/cli.cjs +3859 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +3823 -103
- package/dist/cli.js.map +1 -1
- package/dist/extensions/index.d.ts +8 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/registry.d.ts +83 -0
- package/dist/extensions/registry.d.ts.map +1 -0
- package/dist/generators/class-schema.d.ts +111 -0
- package/dist/generators/class-schema.d.ts.map +1 -0
- package/dist/generators/method-schema.d.ts +65 -0
- package/dist/generators/method-schema.d.ts.map +1 -0
- package/dist/generators/mixed-authoring.d.ts +51 -0
- package/dist/generators/mixed-authoring.d.ts.map +1 -0
- package/dist/index.cjs +3624 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +45 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3584 -106
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +3368 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.d.ts +30 -0
- package/dist/internals.d.ts.map +1 -0
- package/dist/internals.js +3342 -0
- package/dist/internals.js.map +1 -0
- package/dist/json-schema/generator.d.ts +20 -5
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/json-schema/ir-generator.d.ts +114 -0
- package/dist/json-schema/ir-generator.d.ts.map +1 -0
- package/dist/json-schema/schema.d.ts +23 -0
- package/dist/json-schema/schema.d.ts.map +1 -0
- package/dist/json-schema/types.d.ts +45 -2
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +7 -0
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/ir-generator.d.ts +53 -0
- package/dist/ui-schema/ir-generator.d.ts.map +1 -0
- package/dist/ui-schema/schema.d.ts +434 -0
- package/dist/ui-schema/schema.d.ts.map +1 -0
- package/dist/ui-schema/types.d.ts +10 -73
- package/dist/ui-schema/types.d.ts.map +1 -1
- package/dist/validate/constraint-validator.d.ts +23 -0
- package/dist/validate/constraint-validator.d.ts.map +1 -0
- package/dist/validate/index.d.ts +9 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/package.json +27 -7
- package/dist/__tests__/cli.test.js +0 -178
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/__tests__/edge-cases.test.js +0 -217
- package/dist/__tests__/edge-cases.test.js.map +0 -1
- package/dist/__tests__/generator.test.js +0 -225
- package/dist/__tests__/generator.test.js.map +0 -1
- package/dist/__tests__/integration.test.js +0 -163
- package/dist/__tests__/integration.test.js.map +0 -1
- package/dist/__tests__/write-schemas.test.js +0 -196
- package/dist/__tests__/write-schemas.test.js.map +0 -1
- package/dist/json-schema/generator.js +0 -161
- package/dist/json-schema/generator.js.map +0 -1
- package/dist/json-schema/types.js +0 -7
- package/dist/json-schema/types.js.map +0 -1
- package/dist/ui-schema/generator.js +0 -150
- package/dist/ui-schema/generator.js.map +0 -1
- package/dist/ui-schema/types.js +0 -8
- package/dist/ui-schema/types.js.map +0 -1
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import * as os from "node:os";
|
|
5
|
-
import { execSync } from "node:child_process";
|
|
6
|
-
describe("CLI", () => {
|
|
7
|
-
let tempDir;
|
|
8
|
-
const cliPath = path.join(__dirname, "..", "..", "dist", "cli.js");
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "formspec-cli-test-"));
|
|
11
|
-
});
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
if (fs.existsSync(tempDir)) {
|
|
14
|
-
fs.rmSync(tempDir, { recursive: true });
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
function runCli(args) {
|
|
18
|
-
try {
|
|
19
|
-
const stdout = execSync(`node ${cliPath} ${args.join(" ")}`, {
|
|
20
|
-
encoding: "utf-8",
|
|
21
|
-
cwd: tempDir,
|
|
22
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
23
|
-
});
|
|
24
|
-
return { stdout, exitCode: 0 };
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
const execError = error;
|
|
28
|
-
return {
|
|
29
|
-
stdout: execError.stdout || execError.stderr || "",
|
|
30
|
-
exitCode: execError.status || 1,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function createFormFile(filename, content) {
|
|
35
|
-
const filepath = path.join(tempDir, filename);
|
|
36
|
-
fs.writeFileSync(filepath, content);
|
|
37
|
-
return filepath;
|
|
38
|
-
}
|
|
39
|
-
describe("help", () => {
|
|
40
|
-
it("should show help with --help flag", () => {
|
|
41
|
-
const result = runCli(["--help"]);
|
|
42
|
-
expect(result.stdout).toContain("FormSpec Build CLI");
|
|
43
|
-
expect(result.stdout).toContain("Usage:");
|
|
44
|
-
expect(result.stdout).toContain("--out-dir");
|
|
45
|
-
expect(result.stdout).toContain("--name");
|
|
46
|
-
});
|
|
47
|
-
it("should show help with -h flag", () => {
|
|
48
|
-
const result = runCli(["-h"]);
|
|
49
|
-
expect(result.stdout).toContain("FormSpec Build CLI");
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe("argument parsing", () => {
|
|
53
|
-
it("should fail when no input file provided", () => {
|
|
54
|
-
const result = runCli([]);
|
|
55
|
-
expect(result.exitCode).not.toBe(0);
|
|
56
|
-
// Shows help which includes Usage information
|
|
57
|
-
expect(result.stdout).toContain("Usage:");
|
|
58
|
-
});
|
|
59
|
-
it("should fail for unknown option", () => {
|
|
60
|
-
const formFile = createFormFile("form.js", `
|
|
61
|
-
export default { elements: [] };
|
|
62
|
-
`);
|
|
63
|
-
const result = runCli([formFile, "--unknown-option"]);
|
|
64
|
-
expect(result.exitCode).not.toBe(0);
|
|
65
|
-
expect(result.stdout).toContain("Unknown option");
|
|
66
|
-
});
|
|
67
|
-
it("should fail when --out-dir has no value", () => {
|
|
68
|
-
const formFile = createFormFile("form.js", `
|
|
69
|
-
export default { elements: [] };
|
|
70
|
-
`);
|
|
71
|
-
const result = runCli([formFile, "--out-dir"]);
|
|
72
|
-
expect(result.exitCode).not.toBe(0);
|
|
73
|
-
expect(result.stdout).toContain("--out-dir requires a value");
|
|
74
|
-
});
|
|
75
|
-
it("should fail when --name has no value", () => {
|
|
76
|
-
const formFile = createFormFile("form.js", `
|
|
77
|
-
export default { elements: [] };
|
|
78
|
-
`);
|
|
79
|
-
const result = runCli([formFile, "--name"]);
|
|
80
|
-
expect(result.exitCode).not.toBe(0);
|
|
81
|
-
expect(result.stdout).toContain("--name requires a value");
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
describe("file handling", () => {
|
|
85
|
-
it("should fail when input file doesn't exist", () => {
|
|
86
|
-
const result = runCli(["nonexistent.js"]);
|
|
87
|
-
expect(result.exitCode).not.toBe(0);
|
|
88
|
-
expect(result.stdout).toContain("Error");
|
|
89
|
-
});
|
|
90
|
-
it("should fail when file has no form export", () => {
|
|
91
|
-
const formFile = createFormFile("no-export.js", `
|
|
92
|
-
const notExported = { foo: "bar" };
|
|
93
|
-
`);
|
|
94
|
-
const result = runCli([formFile]);
|
|
95
|
-
expect(result.exitCode).not.toBe(0);
|
|
96
|
-
expect(result.stdout).toContain("Error");
|
|
97
|
-
});
|
|
98
|
-
it("should fail when export is not a FormSpec", () => {
|
|
99
|
-
const formFile = createFormFile("not-formspec.js", `
|
|
100
|
-
export default { notAForm: true };
|
|
101
|
-
`);
|
|
102
|
-
const result = runCli([formFile]);
|
|
103
|
-
expect(result.exitCode).not.toBe(0);
|
|
104
|
-
expect(result.stdout).toContain("FormSpec");
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe("successful generation", () => {
|
|
108
|
-
it("should generate schemas from default export", () => {
|
|
109
|
-
const formFile = createFormFile("form-default.js", `
|
|
110
|
-
export default {
|
|
111
|
-
elements: [
|
|
112
|
-
{ _type: "field", _field: "text", name: "name" }
|
|
113
|
-
]
|
|
114
|
-
};
|
|
115
|
-
`);
|
|
116
|
-
const outDir = path.join(tempDir, "output");
|
|
117
|
-
const result = runCli([formFile, "-o", outDir, "-n", "test"]);
|
|
118
|
-
expect(result.exitCode).toBe(0);
|
|
119
|
-
expect(result.stdout).toContain("Generated");
|
|
120
|
-
expect(fs.existsSync(path.join(outDir, "test-schema.json"))).toBe(true);
|
|
121
|
-
expect(fs.existsSync(path.join(outDir, "test-uischema.json"))).toBe(true);
|
|
122
|
-
});
|
|
123
|
-
it("should generate schemas from named 'form' export", () => {
|
|
124
|
-
const formFile = createFormFile("form-named.js", `
|
|
125
|
-
export const form = {
|
|
126
|
-
elements: [
|
|
127
|
-
{ _type: "field", _field: "text", name: "title" }
|
|
128
|
-
]
|
|
129
|
-
};
|
|
130
|
-
`);
|
|
131
|
-
const outDir = path.join(tempDir, "output");
|
|
132
|
-
const result = runCli([formFile, "-o", outDir, "-n", "test"]);
|
|
133
|
-
expect(result.exitCode).toBe(0);
|
|
134
|
-
expect(fs.existsSync(path.join(outDir, "test-schema.json"))).toBe(true);
|
|
135
|
-
});
|
|
136
|
-
it("should derive name from input filename when not specified", () => {
|
|
137
|
-
const formFile = createFormFile("my-form.js", `
|
|
138
|
-
export default {
|
|
139
|
-
elements: [
|
|
140
|
-
{ _type: "field", _field: "text", name: "name" }
|
|
141
|
-
]
|
|
142
|
-
};
|
|
143
|
-
`);
|
|
144
|
-
const outDir = path.join(tempDir, "output");
|
|
145
|
-
const result = runCli([formFile, "-o", outDir]);
|
|
146
|
-
expect(result.exitCode).toBe(0);
|
|
147
|
-
expect(fs.existsSync(path.join(outDir, "my-form-schema.json"))).toBe(true);
|
|
148
|
-
expect(fs.existsSync(path.join(outDir, "my-form-uischema.json"))).toBe(true);
|
|
149
|
-
});
|
|
150
|
-
it("should use default output directory when not specified", () => {
|
|
151
|
-
const formFile = createFormFile("form.js", `
|
|
152
|
-
export default {
|
|
153
|
-
elements: [
|
|
154
|
-
{ _type: "field", _field: "text", name: "name" }
|
|
155
|
-
]
|
|
156
|
-
};
|
|
157
|
-
`);
|
|
158
|
-
const result = runCli([formFile, "-n", "test"]);
|
|
159
|
-
expect(result.exitCode).toBe(0);
|
|
160
|
-
// Default output is ./generated relative to cwd
|
|
161
|
-
expect(fs.existsSync(path.join(tempDir, "generated", "test-schema.json"))).toBe(true);
|
|
162
|
-
});
|
|
163
|
-
it("should accept short flags -o and -n", () => {
|
|
164
|
-
const formFile = createFormFile("form.js", `
|
|
165
|
-
export default {
|
|
166
|
-
elements: [
|
|
167
|
-
{ _type: "field", _field: "text", name: "name" }
|
|
168
|
-
]
|
|
169
|
-
};
|
|
170
|
-
`);
|
|
171
|
-
const outDir = path.join(tempDir, "out");
|
|
172
|
-
const result = runCli([formFile, "-o", outDir, "-n", "short"]);
|
|
173
|
-
expect(result.exitCode).toBe(0);
|
|
174
|
-
expect(fs.existsSync(path.join(outDir, "short-schema.json"))).toBe(true);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
//# sourceMappingURL=cli.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.test.js","sourceRoot":"","sources":["../../src/__tests__/cli.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;IACnB,IAAI,OAAe,CAAC;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEnE,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,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AC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Edge case and error handling tests.
|
|
3
|
-
*
|
|
4
|
-
* These tests verify correct behavior in unusual or boundary situations.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect } from "vitest";
|
|
7
|
-
import { buildFormSchemas, generateJsonSchema, generateUiSchema } from "../index.js";
|
|
8
|
-
import { formspec, field, group, when, is } from "@formspec/dsl";
|
|
9
|
-
describe("Edge cases: Empty and minimal forms", () => {
|
|
10
|
-
it("should handle form with no fields", () => {
|
|
11
|
-
const emptyForm = formspec();
|
|
12
|
-
const { jsonSchema, uiSchema } = buildFormSchemas(emptyForm);
|
|
13
|
-
expect(jsonSchema.type).toBe("object");
|
|
14
|
-
expect(jsonSchema.properties).toEqual({});
|
|
15
|
-
expect(jsonSchema.required).toBeUndefined();
|
|
16
|
-
expect(uiSchema.type).toBe("VerticalLayout");
|
|
17
|
-
expect(uiSchema.elements).toEqual([]);
|
|
18
|
-
});
|
|
19
|
-
it("should handle empty group", () => {
|
|
20
|
-
const form = formspec(group("Empty Group"));
|
|
21
|
-
const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
22
|
-
expect(jsonSchema.properties).toEqual({});
|
|
23
|
-
expect(uiSchema.elements).toHaveLength(1);
|
|
24
|
-
expect(uiSchema.elements[0]).toMatchObject({
|
|
25
|
-
type: "Group",
|
|
26
|
-
label: "Empty Group",
|
|
27
|
-
elements: [],
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
it("should handle empty conditional", () => {
|
|
31
|
-
const form = formspec(field.enum("type", ["a", "b"]), when(is("type", "a")));
|
|
32
|
-
const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
33
|
-
// Only the enum field should exist
|
|
34
|
-
expect(Object.keys(jsonSchema.properties ?? {})).toEqual(["type"]);
|
|
35
|
-
expect(uiSchema.elements).toHaveLength(1);
|
|
36
|
-
});
|
|
37
|
-
it("should handle empty array field", () => {
|
|
38
|
-
const form = formspec(field.array("items"));
|
|
39
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
40
|
-
expect(jsonSchema.properties?.["items"]).toMatchObject({
|
|
41
|
-
type: "array",
|
|
42
|
-
items: {
|
|
43
|
-
type: "object",
|
|
44
|
-
properties: {},
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it("should handle empty object field", () => {
|
|
49
|
-
const form = formspec(field.object("data"));
|
|
50
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
51
|
-
expect(jsonSchema.properties?.["data"]).toMatchObject({
|
|
52
|
-
type: "object",
|
|
53
|
-
properties: {},
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
describe("Edge cases: Field names", () => {
|
|
58
|
-
it("should handle field names with special characters", () => {
|
|
59
|
-
const form = formspec(field.text("field_with_underscore"), field.text("field-with-dash"), field.text("field123"));
|
|
60
|
-
const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
61
|
-
expect(jsonSchema.properties?.["field_with_underscore"]).toBeDefined();
|
|
62
|
-
expect(jsonSchema.properties?.["field-with-dash"]).toBeDefined();
|
|
63
|
-
expect(jsonSchema.properties?.["field123"]).toBeDefined();
|
|
64
|
-
// All scopes should be properly formed
|
|
65
|
-
expect(uiSchema.elements[0]).toMatchObject({
|
|
66
|
-
scope: "#/properties/field_with_underscore",
|
|
67
|
-
});
|
|
68
|
-
expect(uiSchema.elements[1]).toMatchObject({
|
|
69
|
-
scope: "#/properties/field-with-dash",
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
it("should handle single character field names", () => {
|
|
73
|
-
const form = formspec(field.text("a"), field.number("b"), field.boolean("c"));
|
|
74
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
75
|
-
expect(Object.keys(jsonSchema.properties ?? {})).toEqual(["a", "b", "c"]);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
describe("Edge cases: Number constraints", () => {
|
|
79
|
-
it("should handle zero as min/max", () => {
|
|
80
|
-
const form = formspec(field.number("zeroMin", { min: 0 }), field.number("zeroMax", { max: 0 }), field.number("zeroRange", { min: 0, max: 0 }));
|
|
81
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
82
|
-
expect(jsonSchema.properties?.["zeroMin"]).toMatchObject({
|
|
83
|
-
type: "number",
|
|
84
|
-
minimum: 0,
|
|
85
|
-
});
|
|
86
|
-
expect(jsonSchema.properties?.["zeroMax"]).toMatchObject({
|
|
87
|
-
type: "number",
|
|
88
|
-
maximum: 0,
|
|
89
|
-
});
|
|
90
|
-
expect(jsonSchema.properties?.["zeroRange"]).toMatchObject({
|
|
91
|
-
type: "number",
|
|
92
|
-
minimum: 0,
|
|
93
|
-
maximum: 0,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it("should handle negative min/max", () => {
|
|
97
|
-
const form = formspec(field.number("temperature", { min: -273, max: 1000000 }));
|
|
98
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
99
|
-
expect(jsonSchema.properties?.["temperature"]).toMatchObject({
|
|
100
|
-
type: "number",
|
|
101
|
-
minimum: -273,
|
|
102
|
-
maximum: 1000000,
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe("Edge cases: Enum options", () => {
|
|
107
|
-
it("should handle single option enum", () => {
|
|
108
|
-
const form = formspec(field.enum("singleOption", ["only"]));
|
|
109
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
110
|
-
expect(jsonSchema.properties?.["singleOption"]).toMatchObject({
|
|
111
|
-
type: "string",
|
|
112
|
-
enum: ["only"],
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it("should handle single object option enum", () => {
|
|
116
|
-
const form = formspec(field.enum("singleObj", [{ id: "only", label: "Only Option" }]));
|
|
117
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
118
|
-
expect(jsonSchema.properties?.["singleObj"]).toMatchObject({
|
|
119
|
-
type: "string",
|
|
120
|
-
oneOf: [{ const: "only", title: "Only Option" }],
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
it("should handle enum with empty string option", () => {
|
|
124
|
-
const form = formspec(field.enum("withEmpty", ["", "value"]));
|
|
125
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
126
|
-
expect(jsonSchema.properties?.["withEmpty"]).toMatchObject({
|
|
127
|
-
type: "string",
|
|
128
|
-
enum: ["", "value"],
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
describe("Edge cases: Conditional values", () => {
|
|
133
|
-
it("should handle boolean conditional value", () => {
|
|
134
|
-
const form = formspec(field.boolean("enabled"), when(is("enabled", true), field.text("config")));
|
|
135
|
-
const { uiSchema } = buildFormSchemas(form);
|
|
136
|
-
const conditionalField = uiSchema.elements.find((el) => el.type === "Control" && "scope" in el && el.scope === "#/properties/config");
|
|
137
|
-
expect(conditionalField?.rule?.condition.schema).toMatchObject({
|
|
138
|
-
const: true,
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
it("should handle null conditional value", () => {
|
|
142
|
-
const form = formspec(field.text("optional"), when(is("optional", null), field.text("fallback")));
|
|
143
|
-
const { uiSchema } = buildFormSchemas(form);
|
|
144
|
-
const conditionalField = uiSchema.elements.find((el) => el.type === "Control" && "scope" in el && el.scope === "#/properties/fallback");
|
|
145
|
-
expect(conditionalField?.rule?.condition.schema).toMatchObject({
|
|
146
|
-
const: null,
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
it("should handle number conditional value", () => {
|
|
150
|
-
const form = formspec(field.number("quantity"), when(is("quantity", 0), field.text("zeroReason", { label: "Why zero?" })));
|
|
151
|
-
const { uiSchema } = buildFormSchemas(form);
|
|
152
|
-
const conditionalField = uiSchema.elements.find((el) => el.type === "Control" && "scope" in el && el.scope === "#/properties/zeroReason");
|
|
153
|
-
expect(conditionalField?.rule?.condition.schema).toMatchObject({
|
|
154
|
-
const: 0,
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe("Edge cases: Array min/max items", () => {
|
|
159
|
-
it("should handle minItems of 0", () => {
|
|
160
|
-
const form = formspec(field.arrayWithConfig("items", { minItems: 0 }, field.text("name")));
|
|
161
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
162
|
-
expect(jsonSchema.properties?.["items"]).toMatchObject({
|
|
163
|
-
type: "array",
|
|
164
|
-
minItems: 0,
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
it("should handle minItems equal to maxItems", () => {
|
|
168
|
-
const form = formspec(field.arrayWithConfig("exactFive", { minItems: 5, maxItems: 5 }, field.text("item")));
|
|
169
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
170
|
-
expect(jsonSchema.properties?.["exactFive"]).toMatchObject({
|
|
171
|
-
type: "array",
|
|
172
|
-
minItems: 5,
|
|
173
|
-
maxItems: 5,
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe("Edge cases: Deeply nested structures", () => {
|
|
178
|
-
it("should handle 3+ levels of nesting", () => {
|
|
179
|
-
const form = formspec(field.object("level1", field.object("level2", field.object("level3", field.text("deepValue")))));
|
|
180
|
-
const { jsonSchema } = buildFormSchemas(form);
|
|
181
|
-
expect(jsonSchema.properties?.["level1"]).toMatchObject({
|
|
182
|
-
type: "object",
|
|
183
|
-
properties: {
|
|
184
|
-
level2: {
|
|
185
|
-
type: "object",
|
|
186
|
-
properties: {
|
|
187
|
-
level3: {
|
|
188
|
-
type: "object",
|
|
189
|
-
properties: {
|
|
190
|
-
deepValue: { type: "string" },
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
it("should handle conditionals inside groups inside conditionals", () => {
|
|
199
|
-
const form = formspec(field.enum("outer", ["a", "b"]), when(is("outer", "a"), group("Inner Group", field.enum("inner", ["x", "y"]), when(is("inner", "x"), field.text("deepest")))));
|
|
200
|
-
const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
201
|
-
// All fields should be in schema
|
|
202
|
-
expect(Object.keys(jsonSchema.properties ?? {})).toContain("outer");
|
|
203
|
-
expect(Object.keys(jsonSchema.properties ?? {})).toContain("inner");
|
|
204
|
-
expect(Object.keys(jsonSchema.properties ?? {})).toContain("deepest");
|
|
205
|
-
// Find the deepest field and verify it has combined rules
|
|
206
|
-
const deepestControl = uiSchema.elements.find((el) => {
|
|
207
|
-
if (el.type === "Group") {
|
|
208
|
-
return el.elements.some((inner) => inner.type === "Control" &&
|
|
209
|
-
"scope" in inner &&
|
|
210
|
-
inner.scope === "#/properties/deepest");
|
|
211
|
-
}
|
|
212
|
-
return false;
|
|
213
|
-
});
|
|
214
|
-
expect(deepestControl).toBeDefined();
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
//# sourceMappingURL=edge-cases.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edge-cases.test.js","sourceRoot":"","sources":["../../src/__tests__/edge-cases.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAEjE,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;IACnD,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,SAAS,G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C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACpE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACpE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAEtE,0DAA0D;QAC1D,MAAM,cAAc,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;YACnD,IAAI,EAAE,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBACxB,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,IAAI,KAAK,SAAS;oBACxB,OAAO,IAAI,KAAK;oBAChB,KAAK,CAAC,KAAK,KAAK,sBAAsB,CACzC,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,cAAc,CAAC,CAAC,WAAW,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { buildFormSchemas, generateJsonSchema, generateUiSchema } from "../index.js";
|
|
3
|
-
import { formspec, field, group, when, is } from "@formspec/dsl";
|
|
4
|
-
describe("generateJsonSchema", () => {
|
|
5
|
-
it("should generate schema for basic fields", () => {
|
|
6
|
-
const form = formspec(field.text("name", { label: "Name" }), field.number("age", { min: 0, max: 150 }), field.boolean("active"));
|
|
7
|
-
const schema = generateJsonSchema(form);
|
|
8
|
-
expect(schema.$schema).toBe("https://json-schema.org/draft-07/schema#");
|
|
9
|
-
expect(schema.type).toBe("object");
|
|
10
|
-
expect(schema.properties).toEqual({
|
|
11
|
-
name: { type: "string", title: "Name" },
|
|
12
|
-
age: { type: "number", minimum: 0, maximum: 150 },
|
|
13
|
-
active: { type: "boolean" },
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
it("should generate schema for enum fields", () => {
|
|
17
|
-
const form = formspec(field.enum("status", ["draft", "sent", "paid"], { label: "Status" }));
|
|
18
|
-
const schema = generateJsonSchema(form);
|
|
19
|
-
expect(schema.properties?.["status"]).toEqual({
|
|
20
|
-
type: "string",
|
|
21
|
-
title: "Status",
|
|
22
|
-
enum: ["draft", "sent", "paid"],
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
it("should generate schema for enum fields with object options", () => {
|
|
26
|
-
const form = formspec(field.enum("priority", [
|
|
27
|
-
{ id: "low", label: "Low Priority" },
|
|
28
|
-
{ id: "medium", label: "Medium Priority" },
|
|
29
|
-
{ id: "high", label: "High Priority" },
|
|
30
|
-
], { label: "Priority" }));
|
|
31
|
-
const schema = generateJsonSchema(form);
|
|
32
|
-
expect(schema.properties?.["priority"]).toEqual({
|
|
33
|
-
type: "string",
|
|
34
|
-
title: "Priority",
|
|
35
|
-
oneOf: [
|
|
36
|
-
{ const: "low", title: "Low Priority" },
|
|
37
|
-
{ const: "medium", title: "Medium Priority" },
|
|
38
|
-
{ const: "high", title: "High Priority" },
|
|
39
|
-
],
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it("should handle required fields", () => {
|
|
43
|
-
const form = formspec(field.text("name", { required: true }), field.text("optional"));
|
|
44
|
-
const schema = generateJsonSchema(form);
|
|
45
|
-
expect(schema.required).toEqual(["name"]);
|
|
46
|
-
});
|
|
47
|
-
it("should extract fields from groups", () => {
|
|
48
|
-
const form = formspec(group("Customer", field.text("name"), field.text("email")));
|
|
49
|
-
const schema = generateJsonSchema(form);
|
|
50
|
-
expect(Object.keys(schema.properties ?? {})).toEqual(["name", "email"]);
|
|
51
|
-
});
|
|
52
|
-
it("should extract fields from conditionals", () => {
|
|
53
|
-
const form = formspec(field.enum("type", ["a", "b"]), when(is("type", "a"), field.text("extra")));
|
|
54
|
-
const schema = generateJsonSchema(form);
|
|
55
|
-
expect(Object.keys(schema.properties ?? {})).toEqual(["type", "extra"]);
|
|
56
|
-
});
|
|
57
|
-
it("should include x-formspec-source for dynamic enum fields", () => {
|
|
58
|
-
const form = formspec(field.dynamicEnum("country", "countries", { label: "Country" }));
|
|
59
|
-
const schema = generateJsonSchema(form);
|
|
60
|
-
expect(schema.properties?.["country"]).toMatchObject({
|
|
61
|
-
type: "string",
|
|
62
|
-
title: "Country",
|
|
63
|
-
"x-formspec-source": "countries",
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
it("should include x-formspec-params for dynamic enum with dependencies", () => {
|
|
67
|
-
const form = formspec(field.dynamicEnum("city", "cities", {
|
|
68
|
-
label: "City",
|
|
69
|
-
params: ["country", "state"],
|
|
70
|
-
}));
|
|
71
|
-
const schema = generateJsonSchema(form);
|
|
72
|
-
expect(schema.properties?.["city"]).toMatchObject({
|
|
73
|
-
type: "string",
|
|
74
|
-
"x-formspec-source": "cities",
|
|
75
|
-
"x-formspec-params": ["country", "state"],
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it("should include x-formspec-schemaSource for dynamic schema fields", () => {
|
|
79
|
-
const form = formspec(field.dynamicSchema("paymentDetails", "stripe-payment-form", {
|
|
80
|
-
label: "Payment Details",
|
|
81
|
-
}));
|
|
82
|
-
const schema = generateJsonSchema(form);
|
|
83
|
-
expect(schema.properties?.["paymentDetails"]).toMatchObject({
|
|
84
|
-
type: "object",
|
|
85
|
-
title: "Payment Details",
|
|
86
|
-
additionalProperties: true,
|
|
87
|
-
"x-formspec-schemaSource": "stripe-payment-form",
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
describe("generateUiSchema", () => {
|
|
92
|
-
it("should generate vertical layout for basic fields", () => {
|
|
93
|
-
const form = formspec(field.text("name", { label: "Name" }));
|
|
94
|
-
const uiSchema = generateUiSchema(form);
|
|
95
|
-
expect(uiSchema.type).toBe("VerticalLayout");
|
|
96
|
-
expect(uiSchema.elements).toHaveLength(1);
|
|
97
|
-
expect(uiSchema.elements[0]).toEqual({
|
|
98
|
-
type: "Control",
|
|
99
|
-
scope: "#/properties/name",
|
|
100
|
-
label: "Name",
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
it("should generate groups", () => {
|
|
104
|
-
const form = formspec(group("Customer Info", field.text("name")));
|
|
105
|
-
const uiSchema = generateUiSchema(form);
|
|
106
|
-
expect(uiSchema.elements[0]).toMatchObject({
|
|
107
|
-
type: "Group",
|
|
108
|
-
label: "Customer Info",
|
|
109
|
-
elements: [
|
|
110
|
-
{ type: "Control", scope: "#/properties/name" },
|
|
111
|
-
],
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
it("should generate rules for conditionals", () => {
|
|
115
|
-
const form = formspec(field.enum("status", ["draft", "sent"]), when(is("status", "draft"), field.text("notes", { label: "Notes" })));
|
|
116
|
-
const uiSchema = generateUiSchema(form);
|
|
117
|
-
// First element is the status control
|
|
118
|
-
expect(uiSchema.elements[0]).toMatchObject({
|
|
119
|
-
type: "Control",
|
|
120
|
-
scope: "#/properties/status",
|
|
121
|
-
});
|
|
122
|
-
// Second element is the notes control with a rule
|
|
123
|
-
expect(uiSchema.elements[1]).toMatchObject({
|
|
124
|
-
type: "Control",
|
|
125
|
-
scope: "#/properties/notes",
|
|
126
|
-
label: "Notes",
|
|
127
|
-
rule: {
|
|
128
|
-
effect: "SHOW",
|
|
129
|
-
condition: {
|
|
130
|
-
scope: "#/properties/status",
|
|
131
|
-
schema: { const: "draft" },
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
describe("generateJsonSchema - array fields", () => {
|
|
138
|
-
it("should generate schema for array fields", () => {
|
|
139
|
-
const form = formspec(field.array("addresses", field.text("street"), field.text("city")));
|
|
140
|
-
const schema = generateJsonSchema(form);
|
|
141
|
-
expect(schema.properties?.["addresses"]).toEqual({
|
|
142
|
-
type: "array",
|
|
143
|
-
items: {
|
|
144
|
-
type: "object",
|
|
145
|
-
properties: {
|
|
146
|
-
street: { type: "string" },
|
|
147
|
-
city: { type: "string" },
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
it("should handle array fields with min/max items", () => {
|
|
153
|
-
const form = formspec(field.arrayWithConfig("items", { label: "Line Items", minItems: 1, maxItems: 10 }, field.text("description"), field.number("quantity")));
|
|
154
|
-
const schema = generateJsonSchema(form);
|
|
155
|
-
expect(schema.properties?.["items"]).toMatchObject({
|
|
156
|
-
type: "array",
|
|
157
|
-
title: "Line Items",
|
|
158
|
-
minItems: 1,
|
|
159
|
-
maxItems: 10,
|
|
160
|
-
items: {
|
|
161
|
-
type: "object",
|
|
162
|
-
properties: {
|
|
163
|
-
description: { type: "string" },
|
|
164
|
-
quantity: { type: "number" },
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
describe("generateJsonSchema - object fields", () => {
|
|
171
|
-
it("should generate schema for object fields", () => {
|
|
172
|
-
const form = formspec(field.object("address", field.text("street"), field.text("city"), field.text("zip")));
|
|
173
|
-
const schema = generateJsonSchema(form);
|
|
174
|
-
expect(schema.properties?.["address"]).toEqual({
|
|
175
|
-
type: "object",
|
|
176
|
-
properties: {
|
|
177
|
-
street: { type: "string" },
|
|
178
|
-
city: { type: "string" },
|
|
179
|
-
zip: { type: "string" },
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
it("should handle required fields within object fields", () => {
|
|
184
|
-
const form = formspec(field.object("address", field.text("street", { required: true }), field.text("city", { required: true }), field.text("zip")));
|
|
185
|
-
const schema = generateJsonSchema(form);
|
|
186
|
-
expect(schema.properties?.["address"]).toMatchObject({
|
|
187
|
-
type: "object",
|
|
188
|
-
properties: {
|
|
189
|
-
street: { type: "string" },
|
|
190
|
-
city: { type: "string" },
|
|
191
|
-
zip: { type: "string" },
|
|
192
|
-
},
|
|
193
|
-
required: ["street", "city"],
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
describe("generateUiSchema - nested conditionals", () => {
|
|
198
|
-
it("should combine rules for nested conditionals", () => {
|
|
199
|
-
const form = formspec(field.enum("country", ["US", "CA"]), field.enum("paymentMethod", ["card", "bank"]), when(is("country", "US"), when(is("paymentMethod", "bank"), field.text("routingNumber", { label: "Routing Number" }))));
|
|
200
|
-
const uiSchema = generateUiSchema(form);
|
|
201
|
-
// Find the routingNumber control
|
|
202
|
-
const routingControl = uiSchema.elements.find((el) => el.type === "Control" && "scope" in el && el.scope === "#/properties/routingNumber");
|
|
203
|
-
expect(routingControl).toBeDefined();
|
|
204
|
-
expect(routingControl?.rule).toBeDefined();
|
|
205
|
-
// The combined rule should use allOf to require both conditions
|
|
206
|
-
expect(routingControl?.rule?.condition.schema.allOf).toHaveLength(2);
|
|
207
|
-
expect(routingControl?.rule?.condition.schema.allOf?.[0]).toMatchObject({
|
|
208
|
-
properties: { country: { const: "US" } },
|
|
209
|
-
});
|
|
210
|
-
expect(routingControl?.rule?.condition.schema.allOf?.[1]).toMatchObject({
|
|
211
|
-
properties: { paymentMethod: { const: "bank" } },
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
describe("buildFormSchemas", () => {
|
|
216
|
-
it("should return both schemas", () => {
|
|
217
|
-
const form = formspec(field.text("name"));
|
|
218
|
-
const result = buildFormSchemas(form);
|
|
219
|
-
expect(result.jsonSchema).toBeDefined();
|
|
220
|
-
expect(result.jsonSchema.$schema).toBe("https://json-schema.org/draft-07/schema#");
|
|
221
|
-
expect(result.uiSchema).toBeDefined();
|
|
222
|
-
expect(result.uiSchema.type).toBe("VerticalLayout");
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
//# sourceMappingURL=generator.test.js.map
|