@chobantonov/jsonforms-extended-spec 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +126 -2
- package/conformance/authoring.json +2680 -0
- package/conformance/behavior.json +1602 -0
- package/conformance/config-consumption.json +1542 -0
- package/conformance/expected-invalid.json +20 -0
- package/docs/audit.md +150 -0
- package/docs/conditional-fields.md +122 -0
- package/docs/draft-07-visual-support.md +43 -0
- package/docs/external-resources-proposal.md +536 -0
- package/docs/implementation-guide.md +233 -0
- package/docs/implementation-pitfalls.md +968 -0
- package/docs/implementation-web-typescript.md +41 -0
- package/docs/renderer-and-demo.md +1347 -0
- package/docs/renderer-selection.md +99 -0
- package/docs/spec.md +8470 -0
- package/docs/todo.md +166 -0
- package/examples/README.md +127 -0
- package/examples/additional-errors/README.md +176 -0
- package/examples/additional-errors/config.json +3 -0
- package/examples/additional-errors/data.json +11 -0
- package/examples/additional-errors/schema.json +56 -0
- package/examples/additional-errors/translations.json +64 -0
- package/examples/additional-errors/uischema.json +158 -0
- package/examples/additional-items-pagination/README.md +8 -0
- package/examples/additional-items-pagination/config.json +10 -0
- package/examples/additional-items-pagination/data.json +22 -0
- package/examples/additional-items-pagination/schema.json +30 -0
- package/examples/additional-items-pagination/translations.json +16 -0
- package/examples/additional-items-pagination/uischema.json +39 -0
- package/examples/additional-properties/README.md +203 -0
- package/examples/additional-properties/config.json +5 -0
- package/examples/additional-properties/data.json +31 -0
- package/examples/additional-properties/schema.json +78 -0
- package/examples/additional-properties/translations.json +80 -0
- package/examples/additional-properties/uischema.json +104 -0
- package/examples/ag-grid/README.md +62 -0
- package/examples/ag-grid/config.json +14 -0
- package/examples/ag-grid/data.json +124 -0
- package/examples/ag-grid/schema.json +48 -0
- package/examples/ag-grid/translations.json +58 -0
- package/examples/ag-grid/uischema.json +671 -0
- package/examples/array-choices/README.md +150 -0
- package/examples/array-choices/config.json +4 -0
- package/examples/array-choices/data.json +10 -0
- package/examples/array-choices/schema.json +68 -0
- package/examples/array-choices/translations.json +64 -0
- package/examples/array-choices/uischema.json +97 -0
- package/examples/array-controls/README.md +237 -0
- package/examples/array-controls/config.json +4 -0
- package/examples/array-controls/data.json +147 -0
- package/examples/array-controls/schema.json +374 -0
- package/examples/array-controls/translations.json +186 -0
- package/examples/array-controls/uischema.json +685 -0
- package/examples/array-detail-modes/README.md +11 -0
- package/examples/array-detail-modes/data.json +38 -0
- package/examples/array-detail-modes/schema.json +89 -0
- package/examples/array-detail-modes/translations.json +36 -0
- package/examples/array-detail-modes/uischema.json +73 -0
- package/examples/array-detail-modes/uischemas.d.mts +2 -0
- package/examples/array-detail-modes/uischemas.json +15 -0
- package/examples/boolean-controls/README.md +109 -0
- package/examples/boolean-controls/config.json +3 -0
- package/examples/boolean-controls/data.json +27 -0
- package/examples/boolean-controls/schema.json +98 -0
- package/examples/boolean-controls/translations.json +94 -0
- package/examples/boolean-controls/uischema.json +126 -0
- package/examples/button-actions/README.md +259 -0
- package/examples/button-actions/config.json +7 -0
- package/examples/button-actions/data.json +5 -0
- package/examples/button-actions/host.mjs +14 -0
- package/examples/button-actions/schema.json +20 -0
- package/examples/button-actions/translations.json +60 -0
- package/examples/button-actions/uischema.json +179 -0
- package/examples/catalog.json +634 -0
- package/examples/categorization/README.md +132 -0
- package/examples/categorization/config.json +7 -0
- package/examples/categorization/data.json +8 -0
- package/examples/categorization/schema.json +29 -0
- package/examples/categorization/translations.json +72 -0
- package/examples/categorization/uischema.json +288 -0
- package/examples/choice-controls/README.md +136 -0
- package/examples/choice-controls/config.json +10 -0
- package/examples/choice-controls/data.json +61 -0
- package/examples/choice-controls/schema.json +406 -0
- package/examples/choice-controls/translations.json +154 -0
- package/examples/choice-controls/uischema.json +575 -0
- package/examples/choice-controls/uischemas.d.mts +2 -0
- package/examples/choice-controls/uischemas.json +16 -0
- package/examples/code-editor/README.md +74 -0
- package/examples/code-editor/data.json +8 -0
- package/examples/code-editor/schema.json +28 -0
- package/examples/code-editor/translations.json +20 -0
- package/examples/code-editor/uischema.json +77 -0
- package/examples/collection-pagination/README.md +5 -0
- package/examples/collection-pagination/config.json +1 -0
- package/examples/collection-pagination/data.json +64 -0
- package/examples/collection-pagination/schema.json +23 -0
- package/examples/collection-pagination/translations.json +14 -0
- package/examples/collection-pagination/uischema.json +14 -0
- package/examples/color-control/README.md +154 -0
- package/examples/color-control/config.json +7 -0
- package/examples/color-control/data.json +11 -0
- package/examples/color-control/schema.json +61 -0
- package/examples/color-control/translations.json +76 -0
- package/examples/color-control/uischema.json +106 -0
- package/examples/combinators/README.md +223 -0
- package/examples/combinators/config.json +9 -0
- package/examples/combinators/data.json +23 -0
- package/examples/combinators/schema.json +232 -0
- package/examples/combinators/translations.json +178 -0
- package/examples/combinators/uischema.json +158 -0
- package/examples/conditional-fields/README.md +27 -0
- package/examples/conditional-fields/config.json +5 -0
- package/examples/conditional-fields/data.json +7 -0
- package/examples/conditional-fields/schema.json +59 -0
- package/examples/conditional-fields/translations.json +32 -0
- package/examples/conditional-fields/uischema.json +131 -0
- package/examples/container-validation-indicator/README.md +187 -0
- package/examples/container-validation-indicator/config.json +9 -0
- package/examples/container-validation-indicator/data.json +68 -0
- package/examples/container-validation-indicator/schema.json +222 -0
- package/examples/container-validation-indicator/translations.json +120 -0
- package/examples/container-validation-indicator/uischema.json +98 -0
- package/examples/cron-control/README.md +155 -0
- package/examples/cron-control/data.json +15 -0
- package/examples/cron-control/schema.json +72 -0
- package/examples/cron-control/translations.json +80 -0
- package/examples/cron-control/uischema.json +91 -0
- package/examples/destructive-confirmation/README.md +210 -0
- package/examples/destructive-confirmation/config.json +17 -0
- package/examples/destructive-confirmation/data.json +86 -0
- package/examples/destructive-confirmation/schema.json +204 -0
- package/examples/destructive-confirmation/translations.json +112 -0
- package/examples/destructive-confirmation/uischema.json +105 -0
- package/examples/draft-07-metaschema/README.md +11 -0
- package/examples/draft-07-metaschema/config.json +3 -0
- package/examples/draft-07-metaschema/data.json +25 -0
- package/examples/draft-07-metaschema/schema.json +172 -0
- package/examples/draft-07-metaschema/translations.json +10 -0
- package/examples/draft-07-metaschema/uischema.json +14 -0
- package/examples/dynamic-playground/README.md +95 -0
- package/examples/dynamic-playground/config.json +8 -0
- package/examples/dynamic-playground/configuration.json +152 -0
- package/examples/dynamic-playground/data.json +15 -0
- package/examples/dynamic-playground/dynamic-uischema.json +379 -0
- package/examples/dynamic-playground/host.mjs +37 -0
- package/examples/dynamic-playground/schema.json +48 -0
- package/examples/dynamic-playground/translations.json +76 -0
- package/examples/dynamic-playground/uischema.json +36 -0
- package/examples/editor-details/README.md +10 -0
- package/examples/editor-details/data.json +18 -0
- package/examples/editor-details/schema.json +49 -0
- package/examples/editor-details/translations.json +28 -0
- package/examples/editor-details/uischema.json +53 -0
- package/examples/editor-details/uischemas.d.mts +2 -0
- package/examples/editor-details/uischemas.json +14 -0
- package/examples/file-control/README.md +108 -0
- package/examples/file-control/data.json +28 -0
- package/examples/file-control/schema.json +89 -0
- package/examples/file-control/translations.json +46 -0
- package/examples/file-control/uischema.json +152 -0
- package/examples/group-layout/README.md +149 -0
- package/examples/group-layout/config.json +10 -0
- package/examples/group-layout/data.json +9 -0
- package/examples/group-layout/schema.json +51 -0
- package/examples/group-layout/translations.json +62 -0
- package/examples/group-layout/uischema.json +249 -0
- package/examples/index.d.ts +17 -0
- package/examples/index.js +69 -0
- package/examples/input-adornments/README.md +68 -0
- package/examples/input-adornments/data.json +41 -0
- package/examples/input-adornments/schema.json +207 -0
- package/examples/input-adornments/translations.json +106 -0
- package/examples/input-adornments/uischema.json +695 -0
- package/examples/job-application/README.md +23 -0
- package/examples/job-application/config.json +10 -0
- package/examples/job-application/data.json +68 -0
- package/examples/job-application/schema.json +196 -0
- package/examples/job-application/translations.json +388 -0
- package/examples/job-application/uischema.json +218 -0
- package/examples/job-application/uischemas.json +153 -0
- package/examples/json-editor/README.md +28 -0
- package/examples/json-editor/schema.json +1 -0
- package/examples/json-editor/translations.json +10 -0
- package/examples/json-editor/uischema.json +16 -0
- package/examples/json-inference/README.md +33 -0
- package/examples/json-inference/translations.json +10 -0
- package/examples/json-inference/uischema.json +16 -0
- package/examples/kitchen-sink/README.md +86 -0
- package/examples/kitchen-sink/config.json +14 -0
- package/examples/kitchen-sink/data.json +263 -0
- package/examples/kitchen-sink/invalid-data.json +263 -0
- package/examples/kitchen-sink/schema.json +515 -0
- package/examples/kitchen-sink/translations.json +270 -0
- package/examples/kitchen-sink/uischema.json +722 -0
- package/examples/label-interpolation/README.md +241 -0
- package/examples/label-interpolation/config.json +14 -0
- package/examples/label-interpolation/data.json +13 -0
- package/examples/label-interpolation/schema.json +64 -0
- package/examples/label-interpolation/translations.json +94 -0
- package/examples/label-interpolation/uischema.json +379 -0
- package/examples/layout-sizing/README.md +162 -0
- package/examples/layout-sizing/config.json +10 -0
- package/examples/layout-sizing/data.json +14 -0
- package/examples/layout-sizing/schema.json +58 -0
- package/examples/layout-sizing/translations.json +42 -0
- package/examples/layout-sizing/uischema.json +558 -0
- package/examples/markup-label/README.md +109 -0
- package/examples/markup-label/config.json +16 -0
- package/examples/markup-label/data.json +5 -0
- package/examples/markup-label/schema.json +24 -0
- package/examples/markup-label/translations.json +40 -0
- package/examples/markup-label/uischema.json +149 -0
- package/examples/mixed-control/README.md +164 -0
- package/examples/mixed-control/config.json +11 -0
- package/examples/mixed-control/data.json +70 -0
- package/examples/mixed-control/schema.json +221 -0
- package/examples/mixed-control/translations.json +158 -0
- package/examples/mixed-control/uischema.json +211 -0
- package/examples/null-control/README.md +111 -0
- package/examples/null-control/config.json +4 -0
- package/examples/null-control/data.json +6 -0
- package/examples/null-control/schema.json +36 -0
- package/examples/null-control/translations.json +42 -0
- package/examples/null-control/uischema.json +56 -0
- package/examples/numeric-controls/README.md +94 -0
- package/examples/numeric-controls/config.json +4 -0
- package/examples/numeric-controls/data.json +8 -0
- package/examples/numeric-controls/schema.json +52 -0
- package/examples/numeric-controls/translations.json +56 -0
- package/examples/numeric-controls/uischema.json +77 -0
- package/examples/object-control/README.md +220 -0
- package/examples/object-control/config.json +4 -0
- package/examples/object-control/data.json +62 -0
- package/examples/object-control/schema.json +252 -0
- package/examples/object-control/translations.json +160 -0
- package/examples/object-control/uischema.json +275 -0
- package/examples/object-control/uischemas.d.mts +2 -0
- package/examples/object-control/uischemas.json +59 -0
- package/examples/password-control/README.md +119 -0
- package/examples/password-control/config.json +3 -0
- package/examples/password-control/data.json +18 -0
- package/examples/password-control/schema.json +65 -0
- package/examples/password-control/translations.json +64 -0
- package/examples/password-control/uischema.json +94 -0
- package/examples/pre-touch-errors/README.md +176 -0
- package/examples/pre-touch-errors/config.json +4 -0
- package/examples/pre-touch-errors/data.json +5 -0
- package/examples/pre-touch-errors/schema.json +56 -0
- package/examples/pre-touch-errors/translations.json +68 -0
- package/examples/pre-touch-errors/uischema.json +85 -0
- package/examples/presentation/README.md +148 -0
- package/examples/presentation/config.json +9 -0
- package/examples/presentation/data.json +6 -0
- package/examples/presentation/schema.json +21 -0
- package/examples/presentation/translations.json +64 -0
- package/examples/presentation/uischema.json +210 -0
- package/examples/property-pagination/README.md +5 -0
- package/examples/property-pagination/config.json +1 -0
- package/examples/property-pagination/data.json +17 -0
- package/examples/property-pagination/schema.json +14 -0
- package/examples/property-pagination/translations.json +10 -0
- package/examples/property-pagination/uischema.json +24 -0
- package/examples/recursive-tree/README.md +49 -0
- package/examples/recursive-tree/config.json +1 -0
- package/examples/recursive-tree/data.json +40 -0
- package/examples/recursive-tree/schema.json +89 -0
- package/examples/recursive-tree/translations.json +42 -0
- package/examples/recursive-tree/uischema.json +84 -0
- package/examples/recursive-tree/uischemas.d.mts +2 -0
- package/examples/recursive-tree/uischemas.json +51 -0
- package/examples/split-layout/README.md +123 -0
- package/examples/split-layout/config.json +3 -0
- package/examples/split-layout/data.json +13 -0
- package/examples/split-layout/schema.json +50 -0
- package/examples/split-layout/translations.json +50 -0
- package/examples/split-layout/uischema.json +204 -0
- package/examples/string-controls/README.md +159 -0
- package/examples/string-controls/config.json +5 -0
- package/examples/string-controls/data.json +13 -0
- package/examples/string-controls/schema.json +70 -0
- package/examples/string-controls/translations.json +76 -0
- package/examples/string-controls/uischema.json +148 -0
- package/examples/table-row-details/README.md +69 -0
- package/examples/table-row-details/config.json +7 -0
- package/examples/table-row-details/data.json +280 -0
- package/examples/table-row-details/schema.json +61 -0
- package/examples/table-row-details/translations.json +56 -0
- package/examples/table-row-details/uischema.json +1303 -0
- package/examples/template-layout/README.md +250 -0
- package/examples/template-layout/config.json +9 -0
- package/examples/template-layout/data.json +20 -0
- package/examples/template-layout/host.mjs +13 -0
- package/examples/template-layout/schema.json +48 -0
- package/examples/template-layout/translations.json +70 -0
- package/examples/template-layout/uischema.json +177 -0
- package/examples/template-slots/README.md +19 -0
- package/examples/template-slots/data.json +4 -0
- package/examples/template-slots/schema.json +11 -0
- package/examples/template-slots/translations.json +26 -0
- package/examples/template-slots/uischema.json +47 -0
- package/examples/template-slots/uischemas.d.mts +2 -0
- package/examples/template-slots/uischemas.json +56 -0
- package/examples/temporal-controls/README.md +325 -0
- package/examples/temporal-controls/data.json +44 -0
- package/examples/temporal-controls/schema.json +208 -0
- package/examples/temporal-controls/translations.json +156 -0
- package/examples/temporal-controls/uischema.json +297 -0
- package/examples/tree-max-depth/README.md +5 -0
- package/examples/tree-max-depth/config.json +3 -0
- package/examples/tree-max-depth/data.json +31 -0
- package/examples/tree-max-depth/schema.json +258 -0
- package/examples/tree-max-depth/translations.json +42 -0
- package/examples/tree-max-depth/uischema.json +16 -0
- package/examples/tree-max-depth/uischemas.d.mts +2 -0
- package/examples/tree-max-depth/uischemas.json +50 -0
- package/examples/tuple-control/README.md +335 -0
- package/examples/tuple-control/config.json +4 -0
- package/examples/tuple-control/data.json +61 -0
- package/examples/tuple-control/schema.json +218 -0
- package/examples/tuple-control/translations.json +142 -0
- package/examples/tuple-control/uischema.json +128 -0
- package/examples/tuple-control/uischemas.d.mts +2 -0
- package/examples/tuple-control/uischemas.json +125 -0
- package/examples/validator-profile/README.md +197 -0
- package/examples/validator-profile/config.json +9 -0
- package/examples/validator-profile/data.json +16 -0
- package/examples/validator-profile/schema.json +139 -0
- package/examples/validator-profile/translations.json +34 -0
- package/examples/validator-profile/uischema.json +59 -0
- package/package.json +83 -3
- package/provenance.json +140 -0
- package/schemas/README.md +82 -0
- package/schemas/example.schema.json +37 -0
- package/schemas/jsonforms-config.schema.json +427 -0
- package/schemas/jsonforms-dynamic-uischema.schema.json +220 -0
- package/schemas/jsonforms-extended-config.schema.json +332 -0
- package/schemas/jsonforms-extended-uischema.schema.json +1932 -0
- package/schemas/jsonforms-rule.schema.json +104 -0
- package/schemas/jsonforms-uischema.schema.json +1434 -0
- package/typescript/README.md +546 -0
- package/typescript/lib/authoring/cssLength.d.ts +33 -0
- package/typescript/lib/authoring/cssLength.js +25 -0
- package/typescript/lib/authoring/dynamic.d.ts +73 -0
- package/typescript/lib/authoring/dynamic.js +8 -0
- package/typescript/lib/authoring/forSchema.d.ts +385 -0
- package/typescript/lib/authoring/forSchema.js +84 -0
- package/typescript/lib/authoring/schemaTypes.d.ts +111 -0
- package/typescript/lib/authoring/schemaTypes.js +15 -0
- package/typescript/lib/index.d.ts +4 -0
- package/typescript/lib/index.js +20 -0
- package/typescript/package.json +1 -0
- package/typescript/src/authoring/cssLength.ts +79 -0
- package/typescript/src/authoring/dynamic.ts +96 -0
- package/typescript/src/authoring/forSchema.ts +428 -0
- package/typescript/src/authoring/schemaTypes.ts +143 -0
- package/typescript/src/index.ts +4 -0
- package/typescript/test/schemaContract.test.ts +638 -0
- package/typescript/test/tsconfig.json +10 -0
- package/typescript/test/typedAuthoring.test.ts +151 -0
- package/typescript/test/typedAuthoringCoverage.test.ts +178 -0
- package/typescript/test/typedAuthoringCssLength.test.ts +81 -0
- package/typescript/test/typedAuthoringNames.test.ts +90 -0
- package/typescript/test/typedDynamic.test.ts +88 -0
- package/typescript/tsconfig.json +15 -0
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import Ajv from 'ajv';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The authoring schemas in the spec package, checked against reality.
|
|
8
|
+
*
|
|
9
|
+
* A hand-written schema of a hand-written surface rots the moment an option is
|
|
10
|
+
* added, and a rotted one is worse than none: it rejects valid documents and
|
|
11
|
+
* so teaches authors to ignore it. These tests are the thing that keeps it
|
|
12
|
+
* honest - every fixture in the repository has to validate.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const schemaDir = join(__dirname, '../../schemas');
|
|
16
|
+
const specDir = join(__dirname, '../../examples');
|
|
17
|
+
|
|
18
|
+
const load = (name: string) =>
|
|
19
|
+
JSON.parse(readFileSync(join(schemaDir, name), 'utf8'));
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
`strict: false` because these schemas carry `examples` and prose next to
|
|
23
|
+
keywords Ajv's strict mode would rather not see together. They describe a
|
|
24
|
+
surface for authors, not a validator contract.
|
|
25
|
+
*/
|
|
26
|
+
/*
|
|
27
|
+
The extended config schema `$ref`s the base one by filename rather than
|
|
28
|
+
restating it, so the base has to be registered under exactly that key before
|
|
29
|
+
anything referencing it will compile.
|
|
30
|
+
*/
|
|
31
|
+
const BASE_CONFIG = 'jsonforms-config.schema.json';
|
|
32
|
+
const EXTENDED_CONFIG = 'jsonforms-extended-config.schema.json';
|
|
33
|
+
const BASE_UISCHEMA = 'jsonforms-uischema.schema.json';
|
|
34
|
+
const EXTENDED_UISCHEMA = 'jsonforms-extended-uischema.schema.json';
|
|
35
|
+
|
|
36
|
+
const ajvWithConfigSchemas = () => {
|
|
37
|
+
const ajv = new Ajv({ strict: false, allErrors: true });
|
|
38
|
+
for (const name of readdirSync(schemaDir).filter(name => name.endsWith('.json'))) {
|
|
39
|
+
ajv.addSchema(load(name), name);
|
|
40
|
+
}
|
|
41
|
+
return ajv;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const compile = (name: string) => ajvWithConfigSchemas().getSchema(name)!;
|
|
45
|
+
|
|
46
|
+
const uiSchemasIn = (dir: string) =>
|
|
47
|
+
readdirSync(specDir)
|
|
48
|
+
.map((example) => join(specDir, example, dir))
|
|
49
|
+
.filter(existsSync);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Examples that author something invalid on purpose, to show what a renderer
|
|
53
|
+
* does with it.
|
|
54
|
+
*
|
|
55
|
+
* Listed with the error the schema **must** raise, so being on this list
|
|
56
|
+
* asserts the catch rather than waiving it: an example drops off the sweep
|
|
57
|
+
* only by proving the schema notices it.
|
|
58
|
+
*/
|
|
59
|
+
const DELIBERATELY_INVALID: Record<string, RegExp> = {
|
|
60
|
+
'button-actions': /must NOT be valid/,
|
|
61
|
+
// A Label asking for a markup language this renderer set does not
|
|
62
|
+
// implement, so the example can show the diagnostic beside the text.
|
|
63
|
+
'markup-label': /options\/markup must be equal to one of the allowed values/,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const exampleIdOf = (file: string) => basename(dirname(file));
|
|
67
|
+
|
|
68
|
+
describe('the schemas themselves', () => {
|
|
69
|
+
it.each([BASE_CONFIG, EXTENDED_CONFIG, BASE_UISCHEMA, EXTENDED_UISCHEMA])(
|
|
70
|
+
'%s compiles',
|
|
71
|
+
(name) => {
|
|
72
|
+
expect(() => compile(name)).not.toThrow();
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('every UI schema in the repository', () => {
|
|
78
|
+
/*
|
|
79
|
+
The whole point. If an example stops validating, either the example is
|
|
80
|
+
wrong or the schema has fallen behind the code - and the second is much
|
|
81
|
+
more likely.
|
|
82
|
+
*/
|
|
83
|
+
it('validates against the full schema', () => {
|
|
84
|
+
const ajv = ajvWithConfigSchemas();
|
|
85
|
+
const validate = ajv.getSchema(EXTENDED_UISCHEMA)!;
|
|
86
|
+
const failures: string[] = [];
|
|
87
|
+
for (const file of uiSchemasIn('uischema.json')) {
|
|
88
|
+
const expected = DELIBERATELY_INVALID[exampleIdOf(file)];
|
|
89
|
+
const ok = validate(JSON.parse(readFileSync(file, 'utf8')));
|
|
90
|
+
const errors = ajv.errorsText(validate.errors);
|
|
91
|
+
if (expected) {
|
|
92
|
+
if (ok) {
|
|
93
|
+
failures.push(
|
|
94
|
+
`${file}: expected the schema to reject this, and it did not`
|
|
95
|
+
);
|
|
96
|
+
} else if (!expected.test(errors)) {
|
|
97
|
+
failures.push(`${file}: rejected for the wrong reason: ${errors}`);
|
|
98
|
+
}
|
|
99
|
+
} else if (!ok) {
|
|
100
|
+
failures.push(`${file}: ${errors}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
expect(failures).toEqual([]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('validates at least a dozen of them, so the sweep is not empty', () => {
|
|
107
|
+
expect(uiSchemasIn('uischema.json').length).toBeGreaterThan(12);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('every config in the repository', () => {
|
|
112
|
+
/*
|
|
113
|
+
Validated against the **extended** schema, because the examples exercise
|
|
114
|
+
the extended vocabulary. The base schema is the narrower one and is checked for
|
|
115
|
+
the superset relationship below rather than against these fixtures.
|
|
116
|
+
*/
|
|
117
|
+
it('validates against the extended config schema', () => {
|
|
118
|
+
const ajv = ajvWithConfigSchemas();
|
|
119
|
+
const validate = ajv.getSchema(EXTENDED_CONFIG)!;
|
|
120
|
+
const failures: string[] = [];
|
|
121
|
+
for (const file of uiSchemasIn('config.json')) {
|
|
122
|
+
if (!validate(JSON.parse(readFileSync(file, 'utf8')))) {
|
|
123
|
+
failures.push(`${file}: ${ajv.errorsText(validate.errors)}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
expect(failures).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('the two config schemas', () => {
|
|
131
|
+
/*
|
|
132
|
+
The split mirrors the package layering: the base file is what a host on
|
|
133
|
+
core plus the antd renderer set can author, and the extended file adds what
|
|
134
|
+
the framework-agnostic extended renderers and their antd bindings read.
|
|
135
|
+
|
|
136
|
+
The extended file **references** the base rather than restating it. That is
|
|
137
|
+
the property worth protecting: a duplicated key is a key that will
|
|
138
|
+
eventually disagree with its twin, and nothing would report it.
|
|
139
|
+
*/
|
|
140
|
+
const base = load('jsonforms-config.schema.json');
|
|
141
|
+
const extended = load('jsonforms-extended-config.schema.json');
|
|
142
|
+
|
|
143
|
+
it('restates nothing from the base', () => {
|
|
144
|
+
// No top-level properties of its own at all - they arrive through the ref.
|
|
145
|
+
expect(Object.keys(extended.properties ?? {})).toEqual([]);
|
|
146
|
+
|
|
147
|
+
const baseNamespaced = Object.keys(base.$defs.extended.properties);
|
|
148
|
+
const restated = Object.keys(extended.$defs.extendedOnly.properties).filter(
|
|
149
|
+
(key) => baseNamespaced.includes(key)
|
|
150
|
+
);
|
|
151
|
+
expect(restated).toEqual([]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('references the base file rather than copying it', () => {
|
|
155
|
+
const refs = JSON.stringify(extended).match(/"\$ref":"[^"]+"/g) ?? [];
|
|
156
|
+
expect(refs.some((ref) => ref.includes(BASE_CONFIG))).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('still accepts everything the base accepts', () => {
|
|
160
|
+
const validate = ajvWithConfigSchemas().getSchema(extended.$id)!;
|
|
161
|
+
expect(
|
|
162
|
+
validate({
|
|
163
|
+
restrict: false,
|
|
164
|
+
hideRequiredAsterisk: true,
|
|
165
|
+
dateSaveFormat: 'YYYY-MM-DD',
|
|
166
|
+
jsonformsExtended: {
|
|
167
|
+
layoutDefaults: { gap: 8, gridColumns: 12 },
|
|
168
|
+
confirmation: { default: 'never' },
|
|
169
|
+
showValidationIndicator: true,
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('adds what only the extended renderers read', () => {
|
|
176
|
+
const validate = ajvWithConfigSchemas().getSchema(extended.$id)!;
|
|
177
|
+
expect(
|
|
178
|
+
validate({
|
|
179
|
+
jsonformsExtended: {
|
|
180
|
+
security: {
|
|
181
|
+
allowScriptEvaluation: false,
|
|
182
|
+
urlPolicy: { allowedSchemes: ['https'], allowRelative: true },
|
|
183
|
+
},
|
|
184
|
+
defaultTemplateLang: 'ractive',
|
|
185
|
+
propagateErrors: true,
|
|
186
|
+
colorSaveFormat: 'hex',
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
/*
|
|
193
|
+
And the base does not describe them. A host on the antd set alone would
|
|
194
|
+
otherwise get completion for options nothing in its build consumes.
|
|
195
|
+
*/
|
|
196
|
+
it('keeps extended-only options out of the base', () => {
|
|
197
|
+
const extendedOnly = [
|
|
198
|
+
'security',
|
|
199
|
+
'defaultTemplateLang',
|
|
200
|
+
'propagateErrors',
|
|
201
|
+
'colorTextEntry',
|
|
202
|
+
'colorSaveFormat',
|
|
203
|
+
'agGridOptions',
|
|
204
|
+
'monaco',
|
|
205
|
+
];
|
|
206
|
+
const leaked = extendedOnly.filter(
|
|
207
|
+
(key) => key in base.$defs.extended.properties
|
|
208
|
+
);
|
|
209
|
+
expect(leaked).toEqual([]);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('carries the options the antd set actually reads', () => {
|
|
213
|
+
for (const key of [
|
|
214
|
+
'layoutDefaults',
|
|
215
|
+
'confirmation',
|
|
216
|
+
'showValidationIndicator',
|
|
217
|
+
'showDataIndicator',
|
|
218
|
+
'collapsible',
|
|
219
|
+
]) {
|
|
220
|
+
expect(base.$defs.extended.properties, key).toHaveProperty(key);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('the reference is load-bearing', () => {
|
|
226
|
+
it('cannot compile without the base registered', () => {
|
|
227
|
+
const ajv = new Ajv({ strict: false });
|
|
228
|
+
expect(() => ajv.compile(load(EXTENDED_CONFIG))).toThrow();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('enforces a base constraint through the reference', () => {
|
|
232
|
+
const ajv = ajvWithConfigSchemas();
|
|
233
|
+
const validate = ajv.getSchema(EXTENDED_CONFIG)!;
|
|
234
|
+
// `restrict` is typed boolean in the BASE file only.
|
|
235
|
+
expect(validate({ restrict: 'yes' })).toBe(false);
|
|
236
|
+
expect(validate({ restrict: true })).toBe(true);
|
|
237
|
+
// `gridColumns` minimum lives in the base's layoutDefaults.
|
|
238
|
+
expect(
|
|
239
|
+
validate({ jsonformsExtended: { layoutDefaults: { gridColumns: 0 } } })
|
|
240
|
+
).toBe(false);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('enforces an extended-only constraint too', () => {
|
|
244
|
+
const ajv = ajvWithConfigSchemas();
|
|
245
|
+
const validate = ajv.getSchema(EXTENDED_CONFIG)!;
|
|
246
|
+
expect(
|
|
247
|
+
validate({ jsonformsExtended: { colorSaveFormat: 'not-a-format' } })
|
|
248
|
+
).toBe(false);
|
|
249
|
+
expect(validate({ jsonformsExtended: { colorSaveFormat: 'hex' } })).toBe(
|
|
250
|
+
true
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('the base alone does not know the extended options', () => {
|
|
255
|
+
const validate = compile(BASE_CONFIG);
|
|
256
|
+
// Open by design, so it accepts them - but describes nothing.
|
|
257
|
+
expect(validate({ jsonformsExtended: { colorSaveFormat: 'hex' } })).toBe(
|
|
258
|
+
true
|
|
259
|
+
);
|
|
260
|
+
expect(
|
|
261
|
+
'colorSaveFormat' in load(BASE_CONFIG).$defs.extended.properties
|
|
262
|
+
).toBe(false);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe('the common UI vocabulary', () => {
|
|
267
|
+
const common = () => compile(BASE_UISCHEMA);
|
|
268
|
+
|
|
269
|
+
/* It has to actually refuse something, or it is not a subset. */
|
|
270
|
+
it('refuses an element only the extended set registers', () => {
|
|
271
|
+
const validate = common();
|
|
272
|
+
expect(validate({ type: 'Button', label: 'Go', action: 'go' })).toBe(false);
|
|
273
|
+
expect(
|
|
274
|
+
validate({
|
|
275
|
+
type: 'TemplateLayout',
|
|
276
|
+
template: '<p>x</p>',
|
|
277
|
+
elements: [],
|
|
278
|
+
})
|
|
279
|
+
).toBe(false);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
/*
|
|
283
|
+
`options.format` is a renderer-selection hint, not an enumeration - the
|
|
284
|
+
fixtures alone use radio, date, date-time, time - so the subset cannot
|
|
285
|
+
close it. Excluding the three values only the extended set answers to is
|
|
286
|
+
as much as a schema can honestly enforce.
|
|
287
|
+
*/
|
|
288
|
+
it('accepts format hints independently of renderer availability', () => {
|
|
289
|
+
const validate = common();
|
|
290
|
+
for (const format of ['code', 'duration', 'color']) {
|
|
291
|
+
expect(
|
|
292
|
+
validate({
|
|
293
|
+
type: 'Control',
|
|
294
|
+
scope: '#/properties/a',
|
|
295
|
+
options: { format },
|
|
296
|
+
}),
|
|
297
|
+
format
|
|
298
|
+
).toBe(true);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('leaves the open format hint open', () => {
|
|
303
|
+
const validate = common();
|
|
304
|
+
for (const format of ['password', 'radio', 'date-time', 'table']) {
|
|
305
|
+
expect(
|
|
306
|
+
validate({
|
|
307
|
+
type: 'Control',
|
|
308
|
+
scope: '#/properties/a',
|
|
309
|
+
options: { format },
|
|
310
|
+
}),
|
|
311
|
+
format
|
|
312
|
+
).toBe(true);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
/*
|
|
317
|
+
A detail may be written without a `type` - JSON Forms reads a bare
|
|
318
|
+
`{ elements: [...] }` as a vertical layout, and three fixtures do. The
|
|
319
|
+
alternatives overlap, so the schema uses `anyOf`; `oneOf` called a typed
|
|
320
|
+
detail ambiguous and rejected it.
|
|
321
|
+
*/
|
|
322
|
+
it('accepts a detail with or without a type', () => {
|
|
323
|
+
const validate = common();
|
|
324
|
+
for (const detail of [
|
|
325
|
+
{ elements: [{ type: 'Control', scope: '#/properties/b' }] },
|
|
326
|
+
{
|
|
327
|
+
type: 'VerticalLayout',
|
|
328
|
+
elements: [{ type: 'Control', scope: '#/properties/b' }],
|
|
329
|
+
},
|
|
330
|
+
'GENERATE',
|
|
331
|
+
'generate',
|
|
332
|
+
'DEFAULT',
|
|
333
|
+
'default',
|
|
334
|
+
'REGISTERED',
|
|
335
|
+
'registered',
|
|
336
|
+
'GENERATED',
|
|
337
|
+
'custom',
|
|
338
|
+
]) {
|
|
339
|
+
expect(
|
|
340
|
+
validate({
|
|
341
|
+
type: 'Control',
|
|
342
|
+
scope: '#/properties/a',
|
|
343
|
+
options: { detail },
|
|
344
|
+
}),
|
|
345
|
+
JSON.stringify(detail)
|
|
346
|
+
).toBe(true);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
/* And it must still accept what the base set does render. */
|
|
351
|
+
it('accepts the base elements', () => {
|
|
352
|
+
const validate = common();
|
|
353
|
+
for (const element of [
|
|
354
|
+
{ type: 'Control', scope: '#/properties/a' },
|
|
355
|
+
{ type: 'VerticalLayout', elements: [] },
|
|
356
|
+
{ type: 'Group', label: 'G', elements: [] },
|
|
357
|
+
{ type: 'Categorization', elements: [] },
|
|
358
|
+
{ type: 'Label', text: 'x' },
|
|
359
|
+
{ type: 'ListWithDetail', scope: '#/properties/a' },
|
|
360
|
+
]) {
|
|
361
|
+
expect(validate(element), JSON.stringify(element)).toBe(true);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
describe('`views` matches what the code actually reads', () => {
|
|
367
|
+
/*
|
|
368
|
+
`datePickerMode` reads the date views and `timePickerColumns` the time
|
|
369
|
+
ones, and both ignore anything else - so an unconstrained string array let
|
|
370
|
+
a typo through to a picker that quietly kept its defaults, which is exactly
|
|
371
|
+
the silent failure these schemas exist to catch.
|
|
372
|
+
*/
|
|
373
|
+
const viewsOf = (schema: any): any => {
|
|
374
|
+
let found: any;
|
|
375
|
+
const walk = (node: any) => {
|
|
376
|
+
if (Array.isArray(node)) return node.forEach(walk);
|
|
377
|
+
if (node && typeof node === 'object') {
|
|
378
|
+
if (node.views?.type === 'array') found = node.views;
|
|
379
|
+
Object.values(node).forEach(walk);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
walk(schema);
|
|
383
|
+
return found;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
it.each([BASE_CONFIG, BASE_UISCHEMA, EXTENDED_UISCHEMA])(
|
|
387
|
+
'%s offers every view the code reads',
|
|
388
|
+
(name) => {
|
|
389
|
+
expect(viewsOf(load(name))?.items?.enum).toEqual([
|
|
390
|
+
'year',
|
|
391
|
+
'month',
|
|
392
|
+
'day',
|
|
393
|
+
'hours',
|
|
394
|
+
'minutes',
|
|
395
|
+
'seconds',
|
|
396
|
+
]);
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
it('rejects a misspelling', () => {
|
|
401
|
+
const validate = compile(BASE_CONFIG);
|
|
402
|
+
expect(validate({ views: ['year', 'hours'] })).toBe(true);
|
|
403
|
+
expect(validate({ views: ['days'] })).toBe(false);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
/*
|
|
407
|
+
The UI schema narrows per control kind, which the config file cannot: a
|
|
408
|
+
global default has no control in sight. The narrowing only reaches a
|
|
409
|
+
control whose kind is stated in `options.format` - one selected by its data
|
|
410
|
+
schema's format is invisible to a UI-schema validator, which is a limit
|
|
411
|
+
worth stating rather than papering over.
|
|
412
|
+
*/
|
|
413
|
+
describe('per control kind, in the UI schema', () => {
|
|
414
|
+
const control = (format: string, views: string[]) => ({
|
|
415
|
+
type: 'Control',
|
|
416
|
+
scope: '#/properties/at',
|
|
417
|
+
options: { format, views },
|
|
418
|
+
});
|
|
419
|
+
const validate = () =>
|
|
420
|
+
compile(BASE_UISCHEMA);
|
|
421
|
+
|
|
422
|
+
it('accepts shared view names for a date picker to filter', () => {
|
|
423
|
+
const v = validate();
|
|
424
|
+
expect(v(control('date', ['year', 'month']))).toBe(true);
|
|
425
|
+
expect(v(control('date', ['hours']))).toBe(true);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('accepts shared view names for a time picker to filter', () => {
|
|
429
|
+
const v = validate();
|
|
430
|
+
expect(v(control('time', ['hours', 'minutes']))).toBe(true);
|
|
431
|
+
expect(v(control('time', ['month']))).toBe(true);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it('lets a date-time control ask for both', () => {
|
|
435
|
+
const v = validate();
|
|
436
|
+
expect(v(control('date-time', ['year', 'day', 'hours', 'minutes']))).toBe(
|
|
437
|
+
true
|
|
438
|
+
);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('leaves a control whose kind comes from the data schema alone', () => {
|
|
442
|
+
const v = validate();
|
|
443
|
+
expect(
|
|
444
|
+
v({
|
|
445
|
+
type: 'Control',
|
|
446
|
+
scope: '#/properties/at',
|
|
447
|
+
options: { views: ['hours'] },
|
|
448
|
+
})
|
|
449
|
+
).toBe(true);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
describe('the two UI schemas', () => {
|
|
455
|
+
/*
|
|
456
|
+
The pair mirrors the config pair, with one difference that is forced
|
|
457
|
+
rather than chosen: a UI schema is a single mutually-recursive graph
|
|
458
|
+
rooted at `element`, and the extended file has to **widen** that union.
|
|
459
|
+
`allOf` intersects, so the config file's pure-reference trick cannot
|
|
460
|
+
express it, and draft-07 has no other mechanism. What can be shared is
|
|
461
|
+
shared by reference; the recursive spine is generated from the base, and
|
|
462
|
+
these tests are what stop it drifting.
|
|
463
|
+
*/
|
|
464
|
+
const base = load(BASE_UISCHEMA);
|
|
465
|
+
const extended = load(EXTENDED_UISCHEMA);
|
|
466
|
+
|
|
467
|
+
/*
|
|
468
|
+
`label` is deliberately absent: it is the one definition the extended file
|
|
469
|
+
both references and adds to, so it has its own test below.
|
|
470
|
+
*/
|
|
471
|
+
const SHARED = [
|
|
472
|
+
'confirmationOperations',
|
|
473
|
+
'dimension',
|
|
474
|
+
'layoutContainerOptions',
|
|
475
|
+
'layoutItemOptions',
|
|
476
|
+
];
|
|
477
|
+
|
|
478
|
+
/*
|
|
479
|
+
The third shape, between "shared by reference" and "generated from the
|
|
480
|
+
base": a definition the extended set adds options to. It must still be a
|
|
481
|
+
wrapper over the base rather than a copy, or `text` and `options.format`
|
|
482
|
+
acquire a second home and drift.
|
|
483
|
+
*/
|
|
484
|
+
it('extends the base label by reference rather than restating it', () => {
|
|
485
|
+
const label = extended.$defs.label;
|
|
486
|
+
expect(label.allOf?.[0]?.$ref).toBe(`${BASE_UISCHEMA}#/$defs/label`);
|
|
487
|
+
// Nothing the base already declares is repeated here.
|
|
488
|
+
const added = label.allOf?.[1]?.properties ?? {};
|
|
489
|
+
expect(Object.keys(added)).toEqual(['options']);
|
|
490
|
+
expect(Object.keys(added.options.properties)).toEqual([
|
|
491
|
+
'markup',
|
|
492
|
+
'typography',
|
|
493
|
+
'interpolate',
|
|
494
|
+
'textParams',
|
|
495
|
+
]);
|
|
496
|
+
expect(JSON.stringify(label)).not.toContain('"text"');
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it('references the base for every definition that can be shared', () => {
|
|
500
|
+
const text = JSON.stringify(extended);
|
|
501
|
+
for (const name of SHARED) {
|
|
502
|
+
// Referenced across the file boundary...
|
|
503
|
+
expect(text, name).toContain(`${BASE_UISCHEMA}#/$defs/${name}`);
|
|
504
|
+
// ...and not restated locally.
|
|
505
|
+
expect(Object.keys(extended.$defs), name).not.toContain(name);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
/*
|
|
510
|
+
The spine that cannot be shared must still be identical where it is not
|
|
511
|
+
deliberately widened. `control`, `detail` and the layout shells carry no
|
|
512
|
+
extended vocabulary of their own - only the element union and the option
|
|
513
|
+
bag do - so any difference in them is drift.
|
|
514
|
+
*/
|
|
515
|
+
it('keeps the unwidened spine identical to the base', () => {
|
|
516
|
+
for (const name of ['control', 'detail', 'category']) {
|
|
517
|
+
expect(extended.$defs[name], name).toEqual(base.$defs[name]);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
/*
|
|
522
|
+
The two files restrict `type` differently, and the asymmetry is the whole
|
|
523
|
+
design. The base enumerates what its renderer set registers, so authoring
|
|
524
|
+
an element it cannot draw is an error. The extended file leaves `type`
|
|
525
|
+
open, because unknown elements must be preserved and ignored - a host may
|
|
526
|
+
register more - and relies on its per-type branches instead.
|
|
527
|
+
*/
|
|
528
|
+
it('restricts the element type in the base and leaves it open in the extended', () => {
|
|
529
|
+
const baseTypes: string[] = base.$defs.element.properties.type.enum;
|
|
530
|
+
expect(baseTypes.length).toBeGreaterThan(0);
|
|
531
|
+
expect(extended.$defs.element.properties.type.enum).toBeUndefined();
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it('covers every base element type, and more, in its per-type branches', () => {
|
|
535
|
+
const typesIn = (schema: any): string[] =>
|
|
536
|
+
(schema.$defs.byType.allOf ?? [])
|
|
537
|
+
.map((branch: any) => branch.if?.properties?.type?.const)
|
|
538
|
+
.filter(Boolean);
|
|
539
|
+
const baseCovered = typesIn(base);
|
|
540
|
+
const extCovered = typesIn(extended);
|
|
541
|
+
expect(baseCovered.length).toBeGreaterThan(0);
|
|
542
|
+
expect(baseCovered.every((t) => extCovered.includes(t))).toBe(true);
|
|
543
|
+
expect(extCovered.length).toBeGreaterThan(baseCovered.length);
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it('accepts an extended element nested inside a base layout', () => {
|
|
547
|
+
const validate = ajvWithConfigSchemas().getSchema(extended.$id)!;
|
|
548
|
+
const doc = {
|
|
549
|
+
type: 'VerticalLayout',
|
|
550
|
+
elements: [
|
|
551
|
+
{ type: 'Control', scope: '#/properties/a' },
|
|
552
|
+
{ type: 'Button', label: 'Go', action: 'submit' },
|
|
553
|
+
],
|
|
554
|
+
};
|
|
555
|
+
expect(validate(doc), JSON.stringify(validate.errors)).toBe(true);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it('and the base refuses that same document', () => {
|
|
559
|
+
const validate = compile(BASE_UISCHEMA);
|
|
560
|
+
const doc = {
|
|
561
|
+
type: 'VerticalLayout',
|
|
562
|
+
elements: [{ type: 'Button', label: 'Go', action: 'submit' }],
|
|
563
|
+
};
|
|
564
|
+
expect(validate(doc)).toBe(false);
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
it('names no renderer library and keeps vendor mentions to upstream attribution', () => {
|
|
568
|
+
for (const name of [
|
|
569
|
+
BASE_CONFIG,
|
|
570
|
+
EXTENDED_CONFIG,
|
|
571
|
+
BASE_UISCHEMA,
|
|
572
|
+
EXTENDED_UISCHEMA,
|
|
573
|
+
]) {
|
|
574
|
+
const schema = load(name);
|
|
575
|
+
const text = JSON.stringify(schema).toLowerCase();
|
|
576
|
+
expect(text, name).not.toContain('jsonforms-react-renderers');
|
|
577
|
+
if (name === EXTENDED_UISCHEMA) {
|
|
578
|
+
const attribution = schema.$defs.inputAdornmentValue.description;
|
|
579
|
+
expect(attribution).toContain('JSON Forms React Material');
|
|
580
|
+
expect(text.replace(attribution.toLowerCase(), ''), name).not.toContain('material');
|
|
581
|
+
} else {
|
|
582
|
+
expect(text, name).not.toContain('material');
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it.each([BASE_UISCHEMA, EXTENDED_UISCHEMA])('validates editor detail modes in %s', (schemaName) => {
|
|
589
|
+
const validate = compile(schemaName);
|
|
590
|
+
for (const detail of ['GENERATE', 'REGISTERED', {type: 'Control', scope: '#'}]) {
|
|
591
|
+
expect(validate({type:'Control',scope:'#',options:{
|
|
592
|
+
'object-detail':detail,
|
|
593
|
+
recursiveTree:{childrenProperty:'children',labelProperty:'name',detail},
|
|
594
|
+
cells:{value:{detail}},
|
|
595
|
+
rowDetail:{presentation:'dialog',detail}
|
|
596
|
+
}})).toBe(true);
|
|
597
|
+
}
|
|
598
|
+
expect(validate({type:'Control',scope:'#',options:{'object-detail':true}})).toBe(false);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it('validates named template models and slot fallback content', async () => {
|
|
602
|
+
const validate = compile(EXTENDED_UISCHEMA);
|
|
603
|
+
const { examples } = await import('../../examples/index.js');
|
|
604
|
+
const uischemas = examples.find((example) => example.id === 'template-slots')?.uischemas ?? [];
|
|
605
|
+
for (const entry of uischemas) {
|
|
606
|
+
expect(validate(entry.uischema), JSON.stringify(validate.errors)).toBe(true);
|
|
607
|
+
}
|
|
608
|
+
expect(validate({ type: 'Template', name: 'card' })).toBe(true);
|
|
609
|
+
expect(validate({ type: 'Template' })).toBe(false);
|
|
610
|
+
expect(validate({ type: 'Slot', name: 'body', elements: [{ type: 'Control' }] })).toBe(false);
|
|
611
|
+
expect(validate({ type: 'Slot', name: 'body', elements: [{ type: 'Control', scope: '#' }] })).toBe(true);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it.each([BASE_UISCHEMA, EXTENDED_UISCHEMA])('validates conditional field options in %s', name => {
|
|
615
|
+
const validate=compile(name);
|
|
616
|
+
expect(validate({type:'Control',scope:'#',options:{conditionalFields:true}})).toBe(true);
|
|
617
|
+
expect(validate({type:'Control',scope:'#',options:{conditionalFields:false}})).toBe(true);
|
|
618
|
+
expect(validate({type:'Control',scope:'#',options:{conditionalFields:'auto'}})).toBe(false);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it.each([true, false, undefined])('accepts Button fullWidth %s', (fullWidth) => {
|
|
622
|
+
expect(compile(EXTENDED_UISCHEMA)({ type: 'Button', options: { fullWidth } })).toBe(true);
|
|
623
|
+
});
|
|
624
|
+
it.each(['true', 1, null])('rejects nonboolean Button fullWidth %s', (fullWidth) => {
|
|
625
|
+
expect(compile(EXTENDED_UISCHEMA)({ type: 'Button', options: { fullWidth } })).toBe(false);
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
it.each([BASE_UISCHEMA, EXTENDED_UISCHEMA])('validates conditional layout entry options in %s', name => {
|
|
630
|
+
const validate = compile(name);
|
|
631
|
+
for (const type of ['VerticalLayout', 'HorizontalLayout', 'Group', 'Categorization']) {
|
|
632
|
+
const elements = type === 'Categorization' ? [{type:'Category',label:'Fields',elements:[]}] : [];
|
|
633
|
+
for (const conditionalFields of [true, false]) {
|
|
634
|
+
expect(validate({type, elements, options:{conditionalFields}})).toBe(true);
|
|
635
|
+
}
|
|
636
|
+
expect(validate({type, elements, options:{conditionalFields:'auto'}})).toBe(false);
|
|
637
|
+
}
|
|
638
|
+
});
|