@jsonforms/core 3.1.0-alpha.0 → 3.1.0-alpha.2

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.
Files changed (205) hide show
  1. package/README.md +3 -3
  2. package/lib/Helpers.d.ts +1 -1
  3. package/lib/actions/actions.d.ts +27 -26
  4. package/lib/generators/Generate.d.ts +1 -1
  5. package/lib/generators/schema.d.ts +1 -1
  6. package/lib/i18n/arrayTranslations.d.ts +24 -0
  7. package/lib/i18n/i18nTypes.d.ts +3 -2
  8. package/lib/i18n/i18nUtil.d.ts +5 -2
  9. package/lib/i18n/index.d.ts +1 -0
  10. package/lib/jsonforms-core.cjs.js +428 -259
  11. package/lib/jsonforms-core.cjs.js.map +1 -1
  12. package/lib/jsonforms-core.esm.js +313 -200
  13. package/lib/jsonforms-core.esm.js.map +1 -1
  14. package/lib/models/jsonSchema.d.ts +2 -2
  15. package/lib/models/uischema.d.ts +1 -1
  16. package/lib/reducers/cells.d.ts +2 -2
  17. package/lib/reducers/config.d.ts +1 -1
  18. package/lib/reducers/core.d.ts +3 -2
  19. package/lib/reducers/default-data.d.ts +1 -1
  20. package/lib/reducers/i18n.d.ts +1 -1
  21. package/lib/reducers/reducers.d.ts +4 -4
  22. package/lib/reducers/renderers.d.ts +2 -2
  23. package/lib/reducers/selectors.d.ts +6 -6
  24. package/lib/reducers/uischemas.d.ts +2 -2
  25. package/lib/store.d.ts +3 -3
  26. package/lib/testers/testers.d.ts +1 -1
  27. package/lib/util/cell.d.ts +3 -4
  28. package/lib/util/combinators.d.ts +1 -1
  29. package/lib/util/label.d.ts +1 -1
  30. package/lib/util/path.d.ts +6 -3
  31. package/lib/util/renderer.d.ts +11 -7
  32. package/lib/util/resolvers.d.ts +1 -1
  33. package/lib/util/runtime.d.ts +2 -2
  34. package/lib/util/util.d.ts +2 -2
  35. package/lib/util/validator.d.ts +1 -1
  36. package/package.json +16 -5
  37. package/src/Helpers.ts +2 -2
  38. package/src/actions/actions.ts +59 -61
  39. package/src/configDefault.ts +1 -1
  40. package/src/generators/Generate.ts +4 -2
  41. package/src/generators/schema.ts +30 -26
  42. package/src/generators/uischema.ts +7 -6
  43. package/src/i18n/arrayTranslations.ts +54 -0
  44. package/src/i18n/i18nTypes.ts +12 -7
  45. package/src/i18n/i18nUtil.ts +66 -16
  46. package/src/i18n/index.ts +1 -0
  47. package/src/models/draft4.ts +33 -33
  48. package/src/models/jsonSchema.ts +2 -2
  49. package/src/models/uischema.ts +18 -7
  50. package/src/reducers/cells.ts +10 -9
  51. package/src/reducers/config.ts +1 -1
  52. package/src/reducers/core.ts +115 -75
  53. package/src/reducers/default-data.ts +8 -8
  54. package/src/reducers/i18n.ts +22 -10
  55. package/src/reducers/reducers.ts +24 -34
  56. package/src/reducers/renderers.ts +9 -9
  57. package/src/reducers/selectors.ts +10 -11
  58. package/src/reducers/uischemas.ts +27 -26
  59. package/src/store.ts +4 -4
  60. package/src/testers/testers.ts +200 -147
  61. package/src/util/cell.ts +27 -29
  62. package/src/util/combinators.ts +6 -4
  63. package/src/util/label.ts +2 -2
  64. package/src/util/path.ts +15 -8
  65. package/src/util/renderer.ts +123 -72
  66. package/src/util/resolvers.ts +16 -14
  67. package/src/util/runtime.ts +4 -4
  68. package/src/util/schema.ts +1 -1
  69. package/src/util/type.ts +5 -3
  70. package/src/util/uischema.ts +9 -9
  71. package/src/util/util.ts +54 -54
  72. package/src/util/validator.ts +2 -2
  73. package/.nycrc +0 -6
  74. package/docs/assets/css/main.css +0 -1
  75. package/docs/assets/images/icons.png +0 -0
  76. package/docs/assets/images/icons@2x.png +0 -0
  77. package/docs/assets/images/widgets.png +0 -0
  78. package/docs/assets/images/widgets@2x.png +0 -0
  79. package/docs/assets/js/main.js +0 -51
  80. package/docs/assets/js/search.json +0 -1
  81. package/docs/classes/gen.html +0 -406
  82. package/docs/enums/ruleeffect.html +0 -214
  83. package/docs/globals.html +0 -10568
  84. package/docs/index.html +0 -1297
  85. package/docs/interfaces/action.html +0 -166
  86. package/docs/interfaces/addcellrendereraction.html +0 -181
  87. package/docs/interfaces/addrendereraction.html +0 -181
  88. package/docs/interfaces/adduischemaaction.html +0 -181
  89. package/docs/interfaces/andcondition.html +0 -181
  90. package/docs/interfaces/anyaction.html +0 -189
  91. package/docs/interfaces/arraycontrolprops.html +0 -653
  92. package/docs/interfaces/arraylayoutprops.html +0 -648
  93. package/docs/interfaces/categorization.html +0 -281
  94. package/docs/interfaces/category.html +0 -279
  95. package/docs/interfaces/cellprops.html +0 -452
  96. package/docs/interfaces/combinatorrendererprops.html +0 -503
  97. package/docs/interfaces/combinatorsubschemarenderinfo.html +0 -181
  98. package/docs/interfaces/composablecondition.html +0 -193
  99. package/docs/interfaces/condition.html +0 -176
  100. package/docs/interfaces/controlelement.html +0 -280
  101. package/docs/interfaces/controlprops.html +0 -497
  102. package/docs/interfaces/controlstate.html +0 -184
  103. package/docs/interfaces/controlwithdetailprops.html +0 -501
  104. package/docs/interfaces/dispatchcellprops.html +0 -388
  105. package/docs/interfaces/dispatchcellstateprops.html +0 -408
  106. package/docs/interfaces/dispatchpropsofarraycontrol.html +0 -322
  107. package/docs/interfaces/dispatchpropsofcontrol.html +0 -204
  108. package/docs/interfaces/dispatchpropsofmultienumcontrol.html +0 -215
  109. package/docs/interfaces/enumcellprops.html +0 -467
  110. package/docs/interfaces/enumoption.html +0 -167
  111. package/docs/interfaces/formatted.html +0 -226
  112. package/docs/interfaces/grouplayout.html +0 -284
  113. package/docs/interfaces/horizontallayout.html +0 -234
  114. package/docs/interfaces/initaction.html +0 -209
  115. package/docs/interfaces/initactionoptions.html +0 -181
  116. package/docs/interfaces/internationalizable.html +0 -170
  117. package/docs/interfaces/jsonformscellrendererregistryentry.html +0 -167
  118. package/docs/interfaces/jsonformscore.html +0 -251
  119. package/docs/interfaces/jsonformsdefaultdataregistryentry.html +0 -167
  120. package/docs/interfaces/jsonformsextendedstate.html +0 -175
  121. package/docs/interfaces/jsonformsi18nstate.html +0 -181
  122. package/docs/interfaces/jsonformsprops.html +0 -321
  123. package/docs/interfaces/jsonformsrendererregistryentry.html +0 -167
  124. package/docs/interfaces/jsonformsstate.html +0 -170
  125. package/docs/interfaces/jsonformsstore.html +0 -376
  126. package/docs/interfaces/jsonformssubstates.html +0 -276
  127. package/docs/interfaces/jsonformsuischemaregistryentry.html +0 -167
  128. package/docs/interfaces/jsonschema4.html +0 -758
  129. package/docs/interfaces/jsonschema7.html +0 -884
  130. package/docs/interfaces/labelable.html +0 -184
  131. package/docs/interfaces/labeldescription.html +0 -184
  132. package/docs/interfaces/labeled.html +0 -182
  133. package/docs/interfaces/labelelement.html +0 -251
  134. package/docs/interfaces/labelprops.html +0 -339
  135. package/docs/interfaces/layout.html +0 -253
  136. package/docs/interfaces/layoutprops.html +0 -359
  137. package/docs/interfaces/leafcondition.html +0 -209
  138. package/docs/interfaces/orcondition.html +0 -181
  139. package/docs/interfaces/ownpropsofcell.html +0 -321
  140. package/docs/interfaces/ownpropsofcontrol.html +0 -305
  141. package/docs/interfaces/ownpropsofenum.html +0 -161
  142. package/docs/interfaces/ownpropsofenumcell.html +0 -335
  143. package/docs/interfaces/ownpropsofjsonformsrenderer.html +0 -296
  144. package/docs/interfaces/ownpropsoflabel.html +0 -286
  145. package/docs/interfaces/ownpropsoflayout.html +0 -305
  146. package/docs/interfaces/ownpropsofmasterlistitem.html +0 -289
  147. package/docs/interfaces/ownpropsofrenderer.html +0 -292
  148. package/docs/interfaces/referenceschemamap.html +0 -138
  149. package/docs/interfaces/registerdefaultdataaction.html +0 -181
  150. package/docs/interfaces/removecellrendereraction.html +0 -181
  151. package/docs/interfaces/removerendereraction.html +0 -181
  152. package/docs/interfaces/removeuischemaaction.html +0 -167
  153. package/docs/interfaces/rendererprops.html +0 -331
  154. package/docs/interfaces/rule.html +0 -185
  155. package/docs/interfaces/schemabasedcondition.html +0 -202
  156. package/docs/interfaces/scopable.html +0 -171
  157. package/docs/interfaces/scoped.html +0 -183
  158. package/docs/interfaces/setajvaction.html +0 -167
  159. package/docs/interfaces/setconfigaction.html +0 -167
  160. package/docs/interfaces/setlocaleaction.html +0 -167
  161. package/docs/interfaces/setschemaaction.html +0 -167
  162. package/docs/interfaces/settranslatoraction.html +0 -181
  163. package/docs/interfaces/setuischemaaction.html +0 -167
  164. package/docs/interfaces/setvalidationmodeaction.html +0 -167
  165. package/docs/interfaces/statepropsofarraycontrol.html +0 -474
  166. package/docs/interfaces/statepropsofarraylayout.html +0 -461
  167. package/docs/interfaces/statepropsofcell.html +0 -408
  168. package/docs/interfaces/statepropsofcombinator.html +0 -449
  169. package/docs/interfaces/statepropsofcontrol.html +0 -451
  170. package/docs/interfaces/statepropsofcontrolwithdetail.html +0 -463
  171. package/docs/interfaces/statepropsofenumcell.html +0 -422
  172. package/docs/interfaces/statepropsofjsonformsrenderer.html +0 -324
  173. package/docs/interfaces/statepropsoflabel.html +0 -343
  174. package/docs/interfaces/statepropsoflayout.html +0 -369
  175. package/docs/interfaces/statepropsofmasteritem.html +0 -309
  176. package/docs/interfaces/statepropsofrenderer.html +0 -331
  177. package/docs/interfaces/statepropsofscopedrenderer.html +0 -391
  178. package/docs/interfaces/store.html +0 -386
  179. package/docs/interfaces/testercontext.html +0 -184
  180. package/docs/interfaces/uischemaelement.html +0 -225
  181. package/docs/interfaces/unregisterdefaultdataaction.html +0 -167
  182. package/docs/interfaces/updateaction.html +0 -202
  183. package/docs/interfaces/updatecoreaction.html +0 -209
  184. package/docs/interfaces/updateerrorsaction.html +0 -167
  185. package/docs/interfaces/updatei18naction.html +0 -195
  186. package/docs/interfaces/verticallayout.html +0 -234
  187. package/docs/interfaces/withclassname.html +0 -153
  188. package/rollup.config.js +0 -44
  189. package/stats.html +0 -3279
  190. package/test/actions/actions.test.ts +0 -93
  191. package/test/generators/schema.test.ts +0 -224
  192. package/test/generators/uischema.test.ts +0 -576
  193. package/test/i18n/i18nUtil.test.ts +0 -88
  194. package/test/reducers/core.test.ts +0 -1682
  195. package/test/reducers/uischemas.test.ts +0 -173
  196. package/test/testers.test.ts +0 -948
  197. package/test/util/array.test.ts +0 -28
  198. package/test/util/cell.test.ts +0 -354
  199. package/test/util/derivetype.test.ts +0 -101
  200. package/test/util/label.test.ts +0 -364
  201. package/test/util/path.test.ts +0 -259
  202. package/test/util/renderer.test.ts +0 -1830
  203. package/test/util/resolvers.test.ts +0 -157
  204. package/test/util/runtime.test.ts +0 -779
  205. package/tsconfig.json +0 -13
@@ -1,1682 +0,0 @@
1
- /*
2
- The MIT License
3
-
4
- Copyright (c) 2017-2019 EclipseSource Munich
5
- https://github.com/eclipsesource/jsonforms
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- THE SOFTWARE.
24
- */
25
- import test from 'ava';
26
- import Ajv from 'ajv';
27
- import { coreReducer } from '../../src/reducers';
28
- import { init, setSchema, setValidationMode, update, updateCore, updateErrors } from '../../src/actions';
29
- import { JsonSchema } from '../../src/models/jsonSchema';
30
- import {
31
- errorAt,
32
- JsonFormsCore,
33
- validate,
34
- subErrorsAt
35
- } from '../../src/reducers/core';
36
-
37
- import { cloneDeep } from 'lodash';
38
- import { createAjv } from '../../src/util/validator';
39
-
40
- test('core reducer should support v7', t => {
41
- const schema: JsonSchema = {
42
- type: 'object',
43
- properties: {
44
- foo: {
45
- type: 'string',
46
- const: 'bar'
47
- }
48
- }
49
- };
50
- const after = coreReducer(
51
- undefined,
52
- init(
53
- {
54
- foo: 'baz'
55
- },
56
- schema
57
- )
58
- );
59
- t.is(after.errors.length, 1);
60
- });
61
-
62
- test('core reducer - no previous state - init without options should create new ajv', t => {
63
- const schema: JsonSchema = {
64
- type: 'object',
65
- properties: {
66
- foo: {
67
- type: 'string',
68
- const: 'bar'
69
- }
70
- }
71
- };
72
- const after = coreReducer(undefined, init({}, schema, undefined, undefined));
73
- t.true(after.ajv !== undefined);
74
- });
75
-
76
- test('core reducer - no previous state - init with ajv as options object should use it', t => {
77
- const schema: JsonSchema = {
78
- type: 'object',
79
- properties: {
80
- foo: {
81
- type: 'string',
82
- const: 'bar'
83
- }
84
- }
85
- };
86
- const myAjv = new Ajv();
87
- const after = coreReducer(undefined, init({}, schema, undefined, myAjv));
88
- t.deepEqual(after.ajv, myAjv);
89
- });
90
-
91
- test('core reducer - no previous state - init with empty options object', t => {
92
- const schema: JsonSchema = {
93
- type: 'object',
94
- properties: {
95
- foo: {
96
- type: 'string',
97
- const: 'bar'
98
- }
99
- }
100
- };
101
- const after = coreReducer(undefined, init({}, schema, undefined, {}));
102
- t.true(after.ajv !== undefined);
103
- });
104
-
105
- test('core reducer - no previous state - init with options object with ajv', t => {
106
- const schema: JsonSchema = {
107
- type: 'object',
108
- properties: {
109
- foo: {
110
- type: 'string',
111
- const: 'bar'
112
- }
113
- }
114
- };
115
- const myAjv = new Ajv();
116
- const after = coreReducer(
117
- undefined,
118
- init({}, schema, undefined, {
119
- ajv: myAjv
120
- })
121
- );
122
- t.deepEqual(after.ajv, myAjv);
123
- });
124
-
125
- test('core reducer - previous state - init without options should keep previous objects', t => {
126
- const schema: JsonSchema = {
127
- type: 'object',
128
- properties: {
129
- foo: {
130
- type: 'string',
131
- const: 'bar'
132
- }
133
- }
134
- };
135
- const myAjv = new Ajv();
136
- const additionalErrors = [{
137
- instancePath: '',
138
- dataPath: '',
139
- schemaPath: '#/required',
140
- keyword: 'required',
141
- params: {
142
- missingProperty: 'foo'
143
- },
144
- }];
145
- const after = coreReducer(
146
- {
147
- data: {},
148
- schema: {},
149
- uischema: {
150
- type: 'Label'
151
- },
152
- ajv: myAjv,
153
- additionalErrors
154
- },
155
- init({}, schema)
156
- );
157
- t.deepEqual(after.ajv, myAjv);
158
- t.deepEqual(after.additionalErrors, additionalErrors);
159
- });
160
-
161
- test('core reducer - previous state - init with ajv options object should overwrite ajv', t => {
162
- const schema: JsonSchema = {
163
- type: 'object',
164
- properties: {
165
- foo: {
166
- type: 'string',
167
- const: 'bar'
168
- }
169
- }
170
- };
171
- const previousAjv = new Ajv();
172
- const newAjv = new Ajv();
173
- const after = coreReducer(
174
- {
175
- data: {},
176
- schema: {},
177
- uischema: {
178
- type: 'Label'
179
- },
180
- ajv: previousAjv,
181
- },
182
- init({}, schema, undefined, newAjv)
183
- );
184
- t.deepEqual(after.ajv, newAjv);
185
- });
186
-
187
- test('core reducer - previous state - init with additionalErrors option object should overwrite additionalErrors', t => {
188
- const schema: JsonSchema = {
189
- type: 'object',
190
- properties: {
191
- foo: {
192
- type: 'string',
193
- const: 'bar'
194
- }
195
- }
196
- };
197
-
198
- const prevAdditionalErrors = [{
199
- instancePath: '',
200
- dataPath: '',
201
- schemaPath: '#/required',
202
- keyword: 'required',
203
- params: {
204
- missingProperty: 'foo'
205
- },
206
- }];
207
- const currentAdditionalErrors = [{
208
- instancePath: '',
209
- dataPath: '',
210
- schemaPath: '#/required',
211
- keyword: 'required',
212
- params: {
213
- missingProperty: 'bar'
214
- },
215
- }];
216
- const after = coreReducer(
217
- {
218
- data: {},
219
- schema: {},
220
- uischema: {
221
- type: 'Label'
222
- },
223
- additionalErrors: prevAdditionalErrors
224
- },
225
- init({}, schema, undefined, { additionalErrors: currentAdditionalErrors })
226
- );
227
- t.deepEqual(after.additionalErrors, currentAdditionalErrors);
228
- });
229
-
230
- test('core reducer - previous state - init with empty options should not overwrite', t => {
231
- const schema: JsonSchema = {
232
- type: 'object',
233
- properties: {
234
- foo: {
235
- type: 'string',
236
- const: 'bar'
237
- }
238
- }
239
- };
240
- const myAjv = new Ajv();
241
- const additionalErrors = [{
242
- instancePath: '',
243
- dataPath: '',
244
- schemaPath: '#/required',
245
- keyword: 'required',
246
- params: {
247
- missingProperty: 'foo'
248
- },
249
- }];
250
- const after = coreReducer(
251
- {
252
- data: {},
253
- schema: {},
254
- uischema: {
255
- type: 'Label'
256
- },
257
- ajv: myAjv,
258
- additionalErrors
259
- },
260
- init({}, schema, undefined, {})
261
- );
262
- t.deepEqual(after.ajv, myAjv);
263
- t.deepEqual(after.additionalErrors, additionalErrors);
264
- });
265
-
266
- test('core reducer - previous state - init with undefined data should not change data', t => {
267
- const schema = {
268
- type: 'object',
269
- properties: {
270
- animal: {
271
- type: 'string'
272
- },
273
- color: {
274
- type: 'string'
275
- }
276
- }
277
- };
278
-
279
- const after = coreReducer(
280
- {
281
- data: undefined,
282
- schema: {},
283
- uischema: {
284
- type: 'Label'
285
- }
286
- },
287
- init(undefined, schema, undefined, {})
288
- );
289
- t.deepEqual(after.data, undefined);
290
- });
291
-
292
- test('core reducer - previous state - init schema with id', t => {
293
- const schema: JsonSchema = {
294
- $id: 'https://www.jsonforms.io/example.json',
295
- type: 'object',
296
- properties: {
297
- animal: {
298
- type: 'string'
299
- }
300
- }
301
- };
302
- const updatedSchema = cloneDeep(schema);
303
- updatedSchema.properties.animal.minLength = 5;
304
-
305
- const before: JsonFormsCore = coreReducer(
306
- undefined,
307
- init(undefined, schema, undefined, undefined)
308
- );
309
-
310
- const after: JsonFormsCore = coreReducer(
311
- before,
312
- init(undefined, updatedSchema, before.uischema, undefined)
313
- );
314
- t.is(after.schema.properties.animal.minLength, 5);
315
- });
316
-
317
- test('core reducer - update - undefined data should update for given path', t => {
318
- const schema = {
319
- type: 'object',
320
- properties: {
321
- foo: {
322
- type: 'string'
323
- }
324
- }
325
- };
326
-
327
- const before: JsonFormsCore = {
328
- data: undefined,
329
- schema: schema,
330
- uischema: {
331
- type: 'Label'
332
- },
333
- errors: [],
334
- validator: new Ajv().compile(schema)
335
- };
336
-
337
- const after = coreReducer(
338
- before,
339
- update('foo', _ => {
340
- return 'bar';
341
- })
342
- );
343
-
344
- t.not(before, after);
345
- t.not(before.data, after.data);
346
- t.deepEqual(after, { ...before, data: { foo: 'bar'} });
347
- });
348
-
349
- test('core reducer - update - path is undefined state should remain same', t => {
350
- const before: JsonFormsCore = {
351
- data: {
352
- foo: 'bar',
353
- baz: {
354
- bar: 'bar'
355
- }
356
- },
357
- schema: {
358
- type: 'object',
359
- properties: {
360
- foo: {
361
- type: 'string',
362
- const: 'bar'
363
- }
364
- }
365
- },
366
- uischema: {
367
- type: 'Label'
368
- }
369
- };
370
-
371
- const after = coreReducer(
372
- before,
373
- update(undefined, _ => {
374
- return { foo: 'anything' };
375
- })
376
- );
377
-
378
- t.is(before, after);
379
- t.is(before.data, after.data);
380
- t.is(before.data.baz, after.data.baz);
381
- t.deepEqual(before, after);
382
- });
383
-
384
- test('core reducer - update - path is null state should remain same', t => {
385
- const before: JsonFormsCore = {
386
- data: {
387
- foo: 'bar',
388
- baz: {
389
- bar:'bar'
390
- }
391
- },
392
- schema: {
393
- type: 'object',
394
- properties: {
395
- foo: {
396
- type: 'string',
397
- const: 'bar'
398
- }
399
- }
400
- },
401
- uischema: {
402
- type: 'Label'
403
- }
404
- };
405
-
406
- const after = coreReducer(
407
- before,
408
- update(null, _ => {
409
- return { foo: 'anything' };
410
- })
411
- );
412
-
413
- t.is(before, after);
414
- t.is(before.data, after.data);
415
- t.is(before.data.baz, after.data.baz);
416
- t.deepEqual(before, after);
417
- });
418
-
419
- test('core reducer - update - empty path should update root state', t => {
420
- const schema = {
421
- type: 'object',
422
- properties: {
423
- foo: {
424
- type: 'string'
425
- }
426
- }
427
- };
428
-
429
- const before: JsonFormsCore = {
430
- data: {
431
- foo: 'bar',
432
- baz: {
433
- bar:'bar'
434
- }
435
- },
436
- errors: [],
437
- schema,
438
- uischema: {
439
- type: 'Label'
440
- },
441
- validator: new Ajv().compile(schema)
442
- };
443
-
444
- const after = coreReducer(
445
- before,
446
- update('', _ => {
447
- return { foo: 'xyz' };
448
- })
449
- );
450
-
451
- t.not(before, after);
452
- t.not(before.data, after.data);
453
- t.deepEqual(after, { ...before, data: { foo: 'xyz' } });
454
- });
455
-
456
- test('core reducer - update - providing a path should update data only belonging to path', t => {
457
- const schema = {
458
- type: 'object',
459
- properties: {
460
- animal: {
461
- type: 'string'
462
- },
463
- color: {
464
- type: 'string'
465
- }
466
- }
467
- };
468
-
469
- const before: JsonFormsCore = {
470
- data: {
471
- animal: 'Sloth',
472
- color: 'Blue',
473
- baz: {
474
- bar: 'bar'
475
- }
476
- },
477
- errors: [],
478
- schema,
479
- uischema: {
480
- type: 'Label'
481
- },
482
- validator: new Ajv().compile(schema)
483
- };
484
-
485
- const after = coreReducer(
486
- before,
487
- update('color', _ => {
488
- return 'Green';
489
- })
490
- );
491
-
492
- t.not(before, after);
493
- t.not(before.data, after.data);
494
- t.is(before.data.baz, after.data.baz);
495
- t.deepEqual(after, { ...before, data: { ...before.data, color: 'Green' } });
496
- });
497
-
498
- test('core reducer - update - should update errors', t => {
499
- const schema = {
500
- type: 'object',
501
- properties: {
502
- animal: {
503
- type: 'string'
504
- },
505
- color: {
506
- type: 'string',
507
- enum: ['Blue', 'Green']
508
- }
509
- }
510
- };
511
-
512
- const before: JsonFormsCore = {
513
- data: {
514
- animal: 'Sloth',
515
- color: 'Blue',
516
- },
517
- errors: [],
518
- schema,
519
- uischema: {
520
- type: 'Label'
521
- },
522
- validator: new Ajv().compile(schema)
523
- };
524
-
525
- const after = coreReducer(
526
- before,
527
- update('color', _ => {
528
- return 'Yellow';
529
- })
530
- );
531
-
532
- t.deepEqual(after, {
533
- ...before,
534
- data: { ...before.data, color: 'Yellow' },
535
- errors: [
536
- {
537
- instancePath: '/color',
538
- keyword: 'enum',
539
- message: 'must be equal to one of the allowed values',
540
- params: {
541
- allowedValues: ['Blue', 'Green']
542
- },
543
- schemaPath: '#/properties/color/enum'
544
- }
545
- ]
546
- });
547
- });
548
-
549
- test('core reducer - updateErrors - should update errors with empty list', t => {
550
- const before: JsonFormsCore = {
551
- data: {},
552
- schema: {},
553
- uischema: undefined
554
- };
555
-
556
- const after = coreReducer(before, updateErrors([]));
557
- t.deepEqual(after, { ...before, errors: [] });
558
- });
559
-
560
- test('core reducer - updateErrors - should update errors with error', t => {
561
- const before: JsonFormsCore = {
562
- data: {},
563
- schema: {},
564
- uischema: undefined,
565
- errors: []
566
- };
567
-
568
- const error = {
569
- instancePath: '/color',
570
- keyword: 'enum',
571
- message: 'should be equal to one of the allowed values',
572
- params: {
573
- allowedValues: ['Blue', 'Green']
574
- },
575
- schemaPath: '#/properties/color/enum'
576
- };
577
-
578
- const after = coreReducer(before, updateErrors([error]));
579
- t.deepEqual(after, { ...before, errors: [error] });
580
- });
581
-
582
- test('core reducer - updateErrors - should update errors with undefined', t => {
583
- const before: JsonFormsCore = {
584
- data: {},
585
- schema: {},
586
- uischema: undefined,
587
- errors: []
588
- };
589
-
590
- const after = coreReducer(before, updateErrors(undefined));
591
- t.deepEqual(after, { ...before, errors: undefined });
592
- });
593
-
594
- test('errorAt filters enum', t => {
595
- const ajv = createAjv();
596
- const schema: JsonSchema = {
597
- type: 'object',
598
- properties: {
599
- bar: {
600
- type: 'string',
601
- enum: ['f', 'b']
602
- },
603
- foo: {
604
- type: 'string',
605
- enum: ['f', 'b']
606
- }
607
- }
608
- };
609
- const data = { foo: '', bar: '' };
610
- const v = ajv.compile(schema);
611
- const errors = validate(v, data);
612
-
613
- const state: JsonFormsCore = {
614
- data,
615
- schema,
616
- uischema: undefined,
617
- errors
618
- };
619
- const filtered = errorAt('foo', schema.properties.foo)(state);
620
- t.is(filtered.length, 1);
621
- t.deepEqual(filtered[0], state.errors[1]);
622
- });
623
-
624
- test('errorAt filters required', t => {
625
- const ajv = createAjv();
626
- const schema: JsonSchema = {
627
- type: 'object',
628
- properties: {
629
- bar: {
630
- type: 'string',
631
- enum: ['f', 'b']
632
- },
633
- foo: {
634
- type: 'string',
635
- enum: ['f', 'b']
636
- }
637
- },
638
- required: ['bar', 'foo']
639
- };
640
- const data = {};
641
- const v = ajv.compile(schema);
642
- const errors = validate(v, data);
643
-
644
- const state: JsonFormsCore = {
645
- data,
646
- schema,
647
- uischema: undefined,
648
- errors
649
- };
650
- const filtered = errorAt('foo', schema.properties.foo)(state);
651
- t.is(filtered.length, 1);
652
- t.deepEqual(filtered[0], state.errors[1]);
653
- });
654
-
655
- test('errorAt filters required in oneOf object', t => {
656
- const ajv = createAjv();
657
- const schema: JsonSchema = {
658
- type: 'object',
659
- properties: {
660
- fooOrBar: {
661
- oneOf: [
662
- {
663
- title: 'Foo',
664
- type: 'object',
665
- properties: {
666
- foo: {
667
- type: 'string'
668
- }
669
- },
670
- required: ['foo'],
671
- additionalProperties: false
672
- },
673
- {
674
- title: 'Bar',
675
- type: 'object',
676
- properties: {
677
- bar: {
678
- type: 'number'
679
- }
680
- },
681
- required: ['bar'],
682
- additionalProperties: false
683
- }
684
- ]
685
- }
686
- },
687
- additionalProperties: false
688
- };
689
- const data = { fooOrBar: { } };
690
- const v = ajv.compile(schema);
691
- const errors = validate(v, data);
692
-
693
- const state: JsonFormsCore = {
694
- data,
695
- schema,
696
- uischema: undefined,
697
- errors
698
- };
699
- const filtered = errorAt(
700
- 'fooOrBar.foo',
701
- schema.properties.fooOrBar.oneOf[0].properties.foo
702
- )(state);
703
- t.is(filtered.length, 1);
704
- t.deepEqual(filtered[0].keyword, 'required');
705
- });
706
-
707
- test('errorAt filters required in anyOf object', t => {
708
- const ajv = createAjv();
709
- const schema: JsonSchema = {
710
- type: 'object',
711
- properties: {
712
- fooOrBar: {
713
- anyOf: [
714
- {
715
- title: 'Foo',
716
- type: 'object',
717
- properties: {
718
- foo: {
719
- type: 'string'
720
- }
721
- },
722
- required: ['foo'],
723
- additionalProperties: false
724
- },
725
- {
726
- title: 'Bar',
727
- type: 'object',
728
- properties: {
729
- bar: {
730
- type: 'number'
731
- }
732
- },
733
- required: ['bar'],
734
- additionalProperties: false
735
- }
736
- ]
737
- }
738
- },
739
- additionalProperties: false
740
- };
741
- const data = { fooOrBar: { } };
742
- const v = ajv.compile(schema);
743
- const errors = validate(v, data);
744
-
745
- const state: JsonFormsCore = {
746
- data,
747
- schema,
748
- uischema: undefined,
749
- errors
750
- };
751
- const filtered = errorAt(
752
- 'fooOrBar.foo',
753
- schema.properties.fooOrBar.anyOf[0].properties.foo
754
- )(state);
755
- t.is(filtered.length, 1);
756
- t.deepEqual(filtered[0].keyword, 'required');
757
- });
758
-
759
- test('errorAt filters array minItems', t => {
760
- const ajv = createAjv();
761
- const schema: JsonSchema = {
762
- type: 'object',
763
- properties: {
764
- numbers: {
765
- title: 'Numbers',
766
- type: 'array',
767
- items: {
768
- title: 'Type',
769
- type: 'string',
770
- enum: ['One', 'Two', 'Three']
771
- },
772
- minItems: 1
773
- },
774
- colours: {
775
- title: 'Colours',
776
- type: 'array',
777
- items: {
778
- title: 'Type',
779
- type: 'string',
780
- enum: ['Red', 'Green', 'Blue']
781
- },
782
- minItems: 1
783
- }
784
- }
785
- };
786
- const data: { colours: string[]; numbers: string[] } = {
787
- colours: [],
788
- numbers: []
789
- };
790
- const v = ajv.compile(schema);
791
- const errors = validate(v, data);
792
-
793
- const state: JsonFormsCore = {
794
- data,
795
- schema,
796
- uischema: undefined,
797
- errors
798
- };
799
- const filtered = errorAt('colours', schema.properties.colours)(state);
800
- t.is(filtered.length, 1);
801
- t.deepEqual(filtered[0], state.errors[1]);
802
- });
803
-
804
- test('errorAt filters array inner value', t => {
805
- const ajv = createAjv();
806
- const schema: JsonSchema = {
807
- type: 'object',
808
- properties: {
809
- numbers: {
810
- title: 'Numbers',
811
- type: 'array',
812
- items: {
813
- title: 'Type',
814
- type: 'string',
815
- enum: ['One', 'Two', 'Three']
816
- },
817
- minItems: 1
818
- },
819
- colours: {
820
- title: 'Colours',
821
- type: 'array',
822
- items: {
823
- title: 'Type',
824
- type: 'string',
825
- enum: ['Red', 'Green', 'Blue']
826
- },
827
- minItems: 1
828
- }
829
- }
830
- };
831
- const data: { colours: string[]; numbers: string[] } = {
832
- colours: ['Foo'],
833
- numbers: ['Bar']
834
- };
835
- const v = ajv.compile(schema);
836
- const errors = validate(v, data);
837
-
838
- const state: JsonFormsCore = {
839
- data,
840
- schema,
841
- uischema: undefined,
842
- errors
843
- };
844
- const filtered = errorAt('colours.0', schema.properties.colours)(state);
845
- t.is(filtered.length, 1);
846
- t.deepEqual(filtered[0], state.errors[1]);
847
- });
848
-
849
- test('errorAt filters oneOf simple', t => {
850
- const ajv = createAjv();
851
- const schema: JsonSchema = {
852
- type: 'object',
853
- properties: {
854
- coloursOrNumbers: {
855
- oneOf: [
856
- {
857
- title: 'Numbers',
858
- type: 'string',
859
- enum: ['One', 'Two', 'Three']
860
- },
861
- {
862
- title: 'Colours',
863
- type: 'string',
864
- enum: ['Red', 'Green', 'Blue']
865
- }
866
- ]
867
- }
868
- }
869
- };
870
- const data: { coloursOrNumbers: string } = { coloursOrNumbers: 'Foo' };
871
- const v = ajv.compile(schema);
872
- const errors = validate(v, data);
873
-
874
- const state: JsonFormsCore = {
875
- data,
876
- schema,
877
- uischema: undefined,
878
- errors
879
- };
880
- const filtered = errorAt(
881
- 'coloursOrNumbers',
882
- schema.properties.coloursOrNumbers.oneOf[1]
883
- )(state);
884
- t.is(filtered.length, 1);
885
- t.deepEqual(filtered[0], state.errors[1]);
886
- });
887
-
888
- test('errorAt filters anyOf simple', t => {
889
- const ajv = createAjv();
890
- const schema: JsonSchema = {
891
- type: 'object',
892
- properties: {
893
- coloursOrNumbers: {
894
- anyOf: [
895
- {
896
- title: 'Numbers',
897
- type: 'string',
898
- enum: ['One', 'Two', 'Three']
899
- },
900
- {
901
- title: 'Colours',
902
- type: 'string',
903
- enum: ['Red', 'Green', 'Blue']
904
- }
905
- ]
906
- }
907
- }
908
- };
909
- const data: { coloursOrNumbers: string } = { coloursOrNumbers: 'Foo' };
910
- const v = ajv.compile(schema);
911
- const errors = validate(v, data);
912
-
913
- const state: JsonFormsCore = {
914
- data,
915
- schema,
916
- uischema: undefined,
917
- errors
918
- };
919
- const filtered = errorAt(
920
- 'coloursOrNumbers',
921
- schema.properties.coloursOrNumbers.anyOf[1]
922
- )(state);
923
- t.is(filtered.length, 1);
924
- t.deepEqual(filtered[0], state.errors[1]);
925
- });
926
-
927
- test('errorAt filters oneOf objects', t => {
928
- const ajv = createAjv();
929
- const schema: JsonSchema = {
930
- type: 'object',
931
- properties: {
932
- coloursOrNumbers: {
933
- oneOf: [
934
- {
935
- title: 'Numbers',
936
- type: 'object',
937
- properties: {
938
- number: {
939
- title: 'Type',
940
- type: 'string',
941
- enum: ['One', 'Two', 'Three']
942
- }
943
- },
944
- additionalProperties: false
945
- },
946
- {
947
- title: 'Colours',
948
- type: 'object',
949
- properties: {
950
- colour: {
951
- title: 'Type',
952
- type: 'string',
953
- enum: ['Red', 'Green', 'Blue']
954
- }
955
- },
956
- additionalProperties: false
957
- }
958
- ]
959
- }
960
- },
961
- additionalProperties: false
962
- };
963
- const data = { coloursOrNumbers: { colour: 'Foo' } };
964
- const v = ajv.compile(schema);
965
- const errors = validate(v, data);
966
-
967
- const state: JsonFormsCore = {
968
- data,
969
- schema,
970
- uischema: undefined,
971
- errors
972
- };
973
- const filtered = errorAt(
974
- 'coloursOrNumbers.colour',
975
- schema.properties.coloursOrNumbers.oneOf[1].properties.colour
976
- )(state);
977
- t.is(filtered.length, 1);
978
- t.is(filtered[0].keyword, 'enum');
979
- t.deepEqual(filtered[0], state.errors[1]);
980
- });
981
-
982
- test('errorAt filters oneOf objects same properties', t => {
983
- const ajv = createAjv();
984
- const schema: JsonSchema = {
985
- type: 'object',
986
- properties: {
987
- coloursOrNumbers: {
988
- oneOf: [
989
- {
990
- title: 'Numbers',
991
- type: 'object',
992
- properties: {
993
- colourOrNumber: {
994
- title: 'Type',
995
- type: 'string',
996
- enum: ['One', 'Two', 'Three']
997
- }
998
- }
999
- },
1000
- {
1001
- title: 'Colours',
1002
- type: 'object',
1003
- properties: {
1004
- colourOrNumber: {
1005
- title: 'Type',
1006
- type: 'string',
1007
- enum: ['Red', 'Green', 'Blue']
1008
- }
1009
- }
1010
- }
1011
- ]
1012
- }
1013
- }
1014
- };
1015
- const data = { coloursOrNumbers: { colourOrNumber: 'Foo' } };
1016
- const v = ajv.compile(schema);
1017
- const errors = validate(v, data);
1018
-
1019
- const state: JsonFormsCore = {
1020
- data,
1021
- schema,
1022
- uischema: undefined,
1023
- errors
1024
- };
1025
- const filtered = errorAt(
1026
- 'coloursOrNumbers.colourOrNumber',
1027
- schema.properties.coloursOrNumbers.oneOf[1].properties.colourOrNumber
1028
- )(state);
1029
- t.is(filtered.length, 1);
1030
- t.deepEqual(filtered[0], state.errors[1]);
1031
- });
1032
-
1033
- test('errorAt filters oneOf array', t => {
1034
- const ajv = createAjv();
1035
- const schema: JsonSchema = {
1036
- type: 'object',
1037
- properties: {
1038
- coloursOrNumbers: {
1039
- oneOf: [
1040
- {
1041
- title: 'Numbers',
1042
- type: 'array',
1043
- items: {
1044
- title: 'Type',
1045
- type: 'string',
1046
- enum: ['One', 'Two', 'Three']
1047
- },
1048
- minItems: 1
1049
- },
1050
- {
1051
- title: 'Colours',
1052
- type: 'array',
1053
- items: {
1054
- title: 'Type',
1055
- type: 'string',
1056
- enum: ['Red', 'Green', 'Blue']
1057
- },
1058
- minItems: 1
1059
- }
1060
- ]
1061
- }
1062
- }
1063
- };
1064
- const data: { coloursOrNumbers: string[] } = { coloursOrNumbers: [] };
1065
- const v = ajv.compile(schema);
1066
- const errors = validate(v, data);
1067
-
1068
- const state: JsonFormsCore = {
1069
- data,
1070
- schema,
1071
- uischema: undefined,
1072
- errors
1073
- };
1074
- const filtered = errorAt(
1075
- 'coloursOrNumbers',
1076
- schema.properties.coloursOrNumbers.oneOf[1]
1077
- )(state);
1078
- t.is(filtered.length, 1);
1079
- t.deepEqual(filtered[0], state.errors[1]);
1080
- });
1081
-
1082
- test('errorAt filters oneOf array inner', t => {
1083
- const ajv = createAjv();
1084
- const schema: JsonSchema = {
1085
- type: 'object',
1086
- properties: {
1087
- coloursOrNumbers: {
1088
- oneOf: [
1089
- {
1090
- title: 'Numbers',
1091
- type: 'array',
1092
- items: {
1093
- title: 'Type',
1094
- type: 'string',
1095
- enum: ['One', 'Two', 'Three']
1096
- },
1097
- minItems: 1
1098
- },
1099
- {
1100
- title: 'Colours',
1101
- type: 'array',
1102
- items: {
1103
- title: 'Type',
1104
- type: 'string',
1105
- enum: ['Red', 'Green', 'Blue']
1106
- },
1107
- minItems: 1
1108
- }
1109
- ]
1110
- }
1111
- }
1112
- };
1113
- const data: { coloursOrNumbers: string[] } = { coloursOrNumbers: ['Foo'] };
1114
- const v = ajv.compile(schema);
1115
- const errors = validate(v, data);
1116
-
1117
- const state: JsonFormsCore = {
1118
- data,
1119
- schema,
1120
- uischema: undefined,
1121
- errors
1122
- };
1123
- const filtered = errorAt(
1124
- 'coloursOrNumbers',
1125
- schema.properties.coloursOrNumbers.oneOf[1]
1126
- )(state);
1127
- t.is(filtered.length, 0);
1128
- });
1129
-
1130
- test('subErrorsAt filters array inner', t => {
1131
- const ajv = createAjv();
1132
- const schema: JsonSchema = {
1133
- type: 'object',
1134
- properties: {
1135
- numbers: {
1136
- title: 'Numbers',
1137
- type: 'array',
1138
- items: {
1139
- title: 'Type',
1140
- type: 'string',
1141
- enum: ['One', 'Two', 'Three']
1142
- },
1143
- minItems: 1
1144
- },
1145
- colours: {
1146
- title: 'Colours',
1147
- type: 'array',
1148
- items: {
1149
- title: 'Type',
1150
- type: 'string',
1151
- enum: ['Red', 'Green', 'Blue']
1152
- },
1153
- minItems: 1
1154
- }
1155
- }
1156
- };
1157
- const data: { colours: string[]; numbers: string[] } = {
1158
- colours: ['Foo'],
1159
- numbers: ['Bar']
1160
- };
1161
- const v = ajv.compile(schema);
1162
- const errors = validate(v, data);
1163
-
1164
- const state: JsonFormsCore = {
1165
- data,
1166
- schema,
1167
- uischema: undefined,
1168
- errors
1169
- };
1170
- const filtered = subErrorsAt(
1171
- 'colours',
1172
- schema.properties.colours.items as JsonSchema
1173
- )(state);
1174
- t.is(filtered.length, 1);
1175
- t.deepEqual(filtered[0], state.errors[1]);
1176
- });
1177
-
1178
- test('subErrorsAt filters oneOf array inner', t => {
1179
- const ajv = createAjv();
1180
- const schema: JsonSchema = {
1181
- type: 'object',
1182
- properties: {
1183
- coloursOrNumbers: {
1184
- oneOf: [
1185
- {
1186
- title: 'Numbers',
1187
- type: 'array',
1188
- items: {
1189
- title: 'Type',
1190
- type: 'string',
1191
- enum: ['One', 'Two', 'Three']
1192
- },
1193
- minItems: 1
1194
- },
1195
- {
1196
- title: 'Colours',
1197
- type: 'array',
1198
- items: {
1199
- title: 'Type',
1200
- type: 'string',
1201
- enum: ['Red', 'Green', 'Blue']
1202
- },
1203
- minItems: 1
1204
- }
1205
- ]
1206
- }
1207
- }
1208
- };
1209
- const data: { coloursOrNumbers: string[] } = { coloursOrNumbers: ['Foo'] };
1210
- const v = ajv.compile(schema);
1211
- const errors = validate(v, data);
1212
-
1213
- const state: JsonFormsCore = {
1214
- data,
1215
- schema,
1216
- uischema: undefined,
1217
- errors
1218
- };
1219
- const filtered = subErrorsAt(
1220
- 'coloursOrNumbers',
1221
- schema.properties.coloursOrNumbers.oneOf[1].items as JsonSchema
1222
- )(state);
1223
- t.is(filtered.length, 1);
1224
- t.deepEqual(filtered[0], state.errors[1]);
1225
- });
1226
-
1227
- test('errorAt respects hide validation mode', t => {
1228
- const schema = {
1229
- type: 'object',
1230
- properties: {
1231
- animal: {
1232
- type: 'string'
1233
- }
1234
- }
1235
- };
1236
-
1237
- const data = {
1238
- animal: 100
1239
- };
1240
-
1241
- const core: JsonFormsCore = coreReducer(
1242
- undefined,
1243
- init(data, schema, undefined, { validationMode: 'ValidateAndHide' })
1244
- );
1245
- t.is(core.errors.length, 1);
1246
- t.is(errorAt('animal', schema)(core).length, 0);
1247
- })
1248
-
1249
- test('errorAt contains additionalErrors', t => {
1250
- const schema = {
1251
- type: 'object',
1252
- properties: {
1253
- animal: {
1254
- type: 'string'
1255
- }
1256
- }
1257
- };
1258
-
1259
- const data = {
1260
- animal: 100
1261
- };
1262
-
1263
- const additionalErrors = [{
1264
- instancePath: '',
1265
- dataPath: '',
1266
- schemaPath: '#/required',
1267
- keyword: 'required',
1268
- params: {
1269
- missingProperty: 'animal'
1270
- },
1271
- }];
1272
- const core: JsonFormsCore = coreReducer(
1273
- undefined,
1274
- init(data, schema, undefined, { additionalErrors })
1275
- );
1276
- t.is(core.errors.length, 1);
1277
- t.is(core.additionalErrors.length, 1);
1278
- const errorsAt = errorAt('animal', schema)(core);
1279
- t.is(errorsAt.length, 2);
1280
- t.true(errorsAt.indexOf(additionalErrors[0]) > -1);
1281
- });
1282
-
1283
- test('errorAt contains additionalErrors for validation mode NoValidation ', t => {
1284
- const schema = {
1285
- type: 'object',
1286
- properties: {
1287
- animal: {
1288
- type: 'string'
1289
- }
1290
- }
1291
- };
1292
-
1293
- const data = {
1294
- animal: 100
1295
- };
1296
-
1297
- const additionalErrors = [{
1298
- instancePath: '',
1299
- dataPath: '',
1300
- schemaPath: '#/required',
1301
- keyword: 'required',
1302
- params: {
1303
- missingProperty: 'animal'
1304
- },
1305
- }];
1306
- const core: JsonFormsCore = coreReducer(
1307
- undefined,
1308
- init(data, schema, undefined, { additionalErrors, validationMode: 'NoValidation' })
1309
- );
1310
- t.is(core.errors.length, 0);
1311
- t.is(core.additionalErrors.length, 1);
1312
- const errorsAt = errorAt('animal', schema)(core);
1313
- t.is(errorsAt.length, 1);
1314
- t.is(errorsAt.indexOf(additionalErrors[0]), 0);
1315
- });
1316
-
1317
- test('errorAt contains additionalErrors for validation mode ValidateAndHide ', t => {
1318
- const schema = {
1319
- type: 'object',
1320
- properties: {
1321
- animal: {
1322
- type: 'string'
1323
- }
1324
- }
1325
- };
1326
-
1327
- const data = {
1328
- animal: 100
1329
- };
1330
-
1331
- const additionalErrors = [{
1332
- instancePath: '',
1333
- dataPath: '',
1334
- schemaPath: '#/required',
1335
- keyword: 'required',
1336
- params: {
1337
- missingProperty: 'animal'
1338
- },
1339
- }];
1340
- const core: JsonFormsCore = coreReducer(
1341
- undefined,
1342
- init(data, schema, undefined, { additionalErrors, validationMode: 'ValidateAndHide' })
1343
- );
1344
- t.is(core.errors.length, 1);
1345
- t.is(core.additionalErrors.length, 1);
1346
- const errorsAt = errorAt('animal', schema)(core);
1347
- t.is(errorsAt.length, 1);
1348
- t.is(errorsAt.indexOf(additionalErrors[0]), 0);
1349
- });
1350
-
1351
- test('core reducer - setValidationMode - No validation should not produce errors', t => {
1352
- const schema = {
1353
- type: 'object',
1354
- properties: {
1355
- animal: {
1356
- type: 'string'
1357
- }
1358
- }
1359
- };
1360
-
1361
- const data = {
1362
- animal: 100
1363
- };
1364
-
1365
- const core: JsonFormsCore = coreReducer(
1366
- undefined,
1367
- init(data, schema, undefined, { validationMode: 'NoValidation' })
1368
- );
1369
- t.is(core.errors.length, 0);
1370
- t.is(core.validationMode, 'NoValidation');
1371
- });
1372
-
1373
- test('core reducer - setValidationMode - No validation should remove errors', t => {
1374
- const schema = {
1375
- type: 'object',
1376
- properties: {
1377
- animal: {
1378
- type: 'string'
1379
- }
1380
- }
1381
- };
1382
-
1383
- const data = {
1384
- animal: 100
1385
- };
1386
-
1387
- const before: JsonFormsCore = coreReducer(undefined, init(data, schema));
1388
- t.is(before.errors.length, 1);
1389
-
1390
- const after = coreReducer(before, setValidationMode('NoValidation'));
1391
- t.is(after.errors.length, 0);
1392
- t.is(after.validationMode, 'NoValidation');
1393
- });
1394
-
1395
- test('core reducer - init - ValidateAndShow should be default validationMode', t => {
1396
- const data = {
1397
- animal: 100
1398
- };
1399
-
1400
- const core: JsonFormsCore = coreReducer(undefined, init(data));
1401
- t.is(core.validationMode, 'ValidateAndShow');
1402
- });
1403
-
1404
- test('core reducer - init - Validation should produce errors', t => {
1405
- const schema = {
1406
- type: 'object',
1407
- properties: {
1408
- animal: {
1409
- type: 'string'
1410
- }
1411
- }
1412
- };
1413
-
1414
- const data = {
1415
- animal: 100
1416
- };
1417
-
1418
- const coreShow: JsonFormsCore = coreReducer(
1419
- undefined,
1420
- init(data, schema, undefined, { validationMode: 'ValidateAndShow' })
1421
- );
1422
- t.is(coreShow.errors.length, 1);
1423
- t.is(coreShow.validationMode, 'ValidateAndShow');
1424
-
1425
- const coreHide: JsonFormsCore = coreReducer(
1426
- undefined,
1427
- init(data, schema, undefined, { validationMode: 'ValidateAndHide' })
1428
- );
1429
- t.is(coreHide.errors.length, 1);
1430
- t.is(coreHide.validationMode, 'ValidateAndHide');
1431
- });
1432
-
1433
- test('core reducer - setValidationMode - Validation should produce errors', t => {
1434
- const schema = {
1435
- type: 'object',
1436
- properties: {
1437
- animal: {
1438
- type: 'string'
1439
- }
1440
- }
1441
- };
1442
-
1443
- const data = {
1444
- animal: 100
1445
- };
1446
-
1447
- const before: JsonFormsCore = coreReducer(
1448
- undefined,
1449
- init(data, schema, undefined, { validationMode: 'NoValidation' })
1450
- );
1451
- t.is(before.errors.length, 0);
1452
-
1453
- const coreShow: JsonFormsCore = coreReducer(
1454
- before,
1455
- setValidationMode('ValidateAndShow')
1456
- );
1457
- t.is(coreShow.errors.length, 1);
1458
-
1459
- const coreHide: JsonFormsCore = coreReducer(
1460
- before,
1461
- setValidationMode('ValidateAndHide')
1462
- );
1463
- t.is(coreHide.errors.length, 1);
1464
- });
1465
-
1466
- test('core reducer - setValidationMode - Hide validation should preserve errors', t => {
1467
- const schema = {
1468
- type: 'object',
1469
- properties: {
1470
- animal: {
1471
- type: 'string'
1472
- }
1473
- }
1474
- };
1475
-
1476
- const data = {
1477
- animal: 100
1478
- };
1479
-
1480
- const before: JsonFormsCore = coreReducer(
1481
- undefined,
1482
- init(data, schema)
1483
- );
1484
- t.is(before.errors.length, 1);
1485
-
1486
- const after: JsonFormsCore = coreReducer(
1487
- before,
1488
- setValidationMode('ValidateAndHide')
1489
- );
1490
- t.is(after.errors.length, 1);
1491
- });
1492
-
1493
- test('core reducer - update - NoValidation should not produce errors', t => {
1494
- const schema = {
1495
- type: 'object',
1496
- properties: {
1497
- animal: {
1498
- type: 'string'
1499
- }
1500
- }
1501
- };
1502
-
1503
- const data = {
1504
- animal: 'dog'
1505
- };
1506
-
1507
- const before: JsonFormsCore = coreReducer(
1508
- undefined,
1509
- init(data, schema, undefined, { validationMode: 'NoValidation' })
1510
- );
1511
- t.is(before.errors.length, 0);
1512
-
1513
- const after: JsonFormsCore = coreReducer(
1514
- before,
1515
- update('animal', () => 100)
1516
- );
1517
- t.is(after.errors.length, 0);
1518
- });
1519
-
1520
- test('core reducer - update - ValidateAndHide should produce errors', t => {
1521
- const schema = {
1522
- type: 'object',
1523
- properties: {
1524
- animal: {
1525
- type: 'string'
1526
- }
1527
- }
1528
- };
1529
-
1530
- const data = {
1531
- animal: 'dog'
1532
- };
1533
-
1534
- const before: JsonFormsCore = coreReducer(
1535
- undefined,
1536
- init(data, schema, undefined, { validationMode: 'ValidateAndHide' })
1537
- );
1538
- t.is(before.errors.length, 0);
1539
-
1540
- const after: JsonFormsCore = coreReducer(
1541
- before,
1542
- update('animal', () => 100)
1543
- );
1544
- t.is(after.errors.length, 1);
1545
- });
1546
-
1547
- test('core reducer - update core - state should be unchanged when nothing changes', t => {
1548
- const schema = {
1549
- type: 'object',
1550
- properties: {
1551
- animal: {
1552
- type: 'string'
1553
- }
1554
- }
1555
- };
1556
-
1557
- const data = {
1558
- animal: 'dog'
1559
- };
1560
- const before: JsonFormsCore = coreReducer(
1561
- undefined,
1562
- init(data, schema)
1563
- );
1564
-
1565
- const after: JsonFormsCore = coreReducer(
1566
- before,
1567
- updateCore(before.data, before.schema, before.uischema, before.ajv)
1568
- );
1569
- t.true(before === after);
1570
- });
1571
-
1572
- test('core reducer - update core - unchanged state properties should be unchanged when state changes', t => {
1573
- const schema = {
1574
- type: 'object',
1575
- properties: {
1576
- animal: {
1577
- type: 'string'
1578
- }
1579
- }
1580
- };
1581
-
1582
- const data = {
1583
- animal: 'dog'
1584
- };
1585
- const before: JsonFormsCore = coreReducer(
1586
- undefined,
1587
- init(data, schema)
1588
- );
1589
-
1590
- const afterDataUpdate: JsonFormsCore = coreReducer(
1591
- before,
1592
- updateCore({
1593
- animal: 'cat'
1594
- }, before.schema, before.uischema, { ajv: before.ajv, additionalErrors: before.additionalErrors })
1595
- );
1596
- t.true(before.schema === afterDataUpdate.schema);
1597
- t.true(before.ajv === afterDataUpdate.ajv);
1598
- t.true(before.errors === afterDataUpdate.errors);
1599
- t.true(before.uischema === afterDataUpdate.uischema);
1600
- t.true(before.validationMode === afterDataUpdate.validationMode);
1601
- t.true(before.validator === afterDataUpdate.validator);
1602
- t.true(before.additionalErrors === afterDataUpdate.additionalErrors);
1603
-
1604
- const updatedSchema = {
1605
- type: 'object',
1606
- properties: {
1607
- animal: {
1608
- type: 'string'
1609
- },
1610
- id: {
1611
- type: 'number'
1612
- }
1613
- }
1614
- };
1615
- // check that data stays unchanged as well
1616
- const afterSchemaUpdate : JsonFormsCore = coreReducer(
1617
- before,
1618
- updateCore(before.data, updatedSchema, before.uischema, before.ajv)
1619
- );
1620
- t.true(before.data === afterSchemaUpdate.data);
1621
- });
1622
-
1623
- test('core reducer - update core - additionalErrors should update', t => {
1624
- const schema = {
1625
- type: 'object',
1626
- properties: {
1627
- animal: {
1628
- type: 'string'
1629
- }
1630
- }
1631
- };
1632
-
1633
- const data = {
1634
- animal: 'dog'
1635
- };
1636
- const before: JsonFormsCore = coreReducer(
1637
- undefined,
1638
- init(data, schema, undefined, { additionalErrors: [] })
1639
- );
1640
-
1641
- const additionalErrors = [{
1642
- instancePath: '',
1643
- dataPath: '',
1644
- schemaPath: '#/required',
1645
- keyword: 'required',
1646
- params: {
1647
- missingProperty: 'animal'
1648
- },
1649
- }];
1650
- const after: JsonFormsCore = coreReducer(
1651
- before,
1652
- updateCore(before.data, before.schema, before.uischema, { additionalErrors })
1653
- );
1654
- t.true(after.additionalErrors === additionalErrors);
1655
- });
1656
-
1657
- test('core reducer - setSchema - schema with id', t => {
1658
- const schema: JsonSchema = {
1659
- $id: 'https://www.jsonforms.io/example.json',
1660
- type: 'object',
1661
- properties: {
1662
- animal: {
1663
- type: 'string'
1664
- }
1665
- }
1666
- };
1667
- const updatedSchema = cloneDeep(schema);
1668
- updatedSchema.properties.animal.minLength = 5;
1669
-
1670
- const before: JsonFormsCore = coreReducer(
1671
- undefined,
1672
- init(undefined, schema, undefined, undefined)
1673
- );
1674
-
1675
- const after: JsonFormsCore = coreReducer(
1676
- before,
1677
- setSchema(updatedSchema)
1678
- );
1679
- t.is(after.schema.properties.animal.minLength, 5);
1680
- });
1681
-
1682
-