@zohodesk/library-platform 1.2.2-exp.1 → 1.2.2-exp.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.
- package/es/cc/table-connected/SdkContract.js +3 -28
- package/es/cc/table-list/Properties.js +8 -9
- package/es/cc/table-list/row/Properties.js +6 -19
- package/es/library/custom-component/frameworks/json-schema-validator/Validator.js +1 -177
- package/es/library/custom-component/frameworks/ui/DependencyFactory.js +1 -17
- package/es/library/json-schema-validator/Validator.js +338 -0
- package/es/library/json-schema-validator/__tests__/Validator.test.js +753 -0
- package/es/library/json-schema-validator/index.js +1 -0
- package/es/platform/client-actions/cc/action-event-mediator/Properties.js +4 -18
- package/es/platform/sdk/application/interfaces/gateways/AbstractResource.js +1 -1
- package/package.json +3 -6
- package/es/library/custom-component/frameworks/json-schema-validator/__generated__/registry.d.js +0 -1
- package/es/library/custom-component/frameworks/json-schema-validator/__generated__/registry.js +0 -92
- package/es/library/custom-component/frameworks/json-schema-validator/__generated__/validators.js +0 -1
- package/es/library/custom-component/frameworks/json-schema-validator/__tests__/Validator.test.js +0 -478
package/es/library/custom-component/frameworks/json-schema-validator/__tests__/Validator.test.js
DELETED
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
import Validator from "../Validator"; // Schemas extracted from src/cc/table-connected/Properties.ts
|
|
2
|
-
|
|
3
|
-
const preferencesSchema = {
|
|
4
|
-
type: 'object',
|
|
5
|
-
properties: {
|
|
6
|
-
rowActions: {
|
|
7
|
-
type: 'object',
|
|
8
|
-
additionalProperties: {
|
|
9
|
-
width: {
|
|
10
|
-
type: 'string'
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
fields: {
|
|
15
|
-
type: 'object',
|
|
16
|
-
additionalProperties: {
|
|
17
|
-
type: 'object',
|
|
18
|
-
properties: {
|
|
19
|
-
initialWidth: {
|
|
20
|
-
type: 'number'
|
|
21
|
-
},
|
|
22
|
-
currencyLocale: {
|
|
23
|
-
type: 'string'
|
|
24
|
-
},
|
|
25
|
-
currencySymbol: {
|
|
26
|
-
type: 'string'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
autoColumnSizing: {
|
|
32
|
-
type: 'boolean'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const moduleNameSchema = {
|
|
37
|
-
type: 'string'
|
|
38
|
-
};
|
|
39
|
-
const textOverflowConfigSchema = {
|
|
40
|
-
type: 'object',
|
|
41
|
-
properties: {
|
|
42
|
-
isEnabled: {
|
|
43
|
-
type: 'boolean'
|
|
44
|
-
},
|
|
45
|
-
mode: {
|
|
46
|
-
type: 'string',
|
|
47
|
-
enum: ['clip', 'wrap']
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const nameFieldsConfigSchema = {
|
|
52
|
-
type: 'object'
|
|
53
|
-
};
|
|
54
|
-
const componentMappingSchema = {
|
|
55
|
-
type: 'object',
|
|
56
|
-
properties: {
|
|
57
|
-
fields: {
|
|
58
|
-
type: 'object'
|
|
59
|
-
},
|
|
60
|
-
rowActionsComponentName: {
|
|
61
|
-
type: 'string'
|
|
62
|
-
},
|
|
63
|
-
emptyState: {
|
|
64
|
-
type: 'string'
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const selectionConfigSchema = {
|
|
69
|
-
type: 'object',
|
|
70
|
-
properties: {
|
|
71
|
-
isEnabled: {
|
|
72
|
-
type: 'boolean'
|
|
73
|
-
},
|
|
74
|
-
maxSelectionCount: {
|
|
75
|
-
type: 'number'
|
|
76
|
-
},
|
|
77
|
-
limitExceedAlertMessage: {
|
|
78
|
-
type: 'string'
|
|
79
|
-
},
|
|
80
|
-
isSelectAllEnabled: {
|
|
81
|
-
type: 'boolean'
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
describe('Validator', () => {
|
|
86
|
-
describe('validate() — direct schema (no schema.schema)', () => {
|
|
87
|
-
it('should return valid for a correct object value', () => {
|
|
88
|
-
const result = Validator.validate(preferencesSchema, {
|
|
89
|
-
fields: {},
|
|
90
|
-
autoColumnSizing: false
|
|
91
|
-
});
|
|
92
|
-
expect(result.isValid).toBe(true);
|
|
93
|
-
expect(result.errors).toEqual([]);
|
|
94
|
-
expect(result.warnings).toEqual([]);
|
|
95
|
-
});
|
|
96
|
-
it('should return invalid when a property has wrong type', () => {
|
|
97
|
-
const result = Validator.validate(preferencesSchema, {
|
|
98
|
-
fields: 'not-an-object',
|
|
99
|
-
autoColumnSizing: false
|
|
100
|
-
});
|
|
101
|
-
expect(result.isValid).toBe(false);
|
|
102
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
103
|
-
});
|
|
104
|
-
it('should return valid for a correct string value', () => {
|
|
105
|
-
const result = Validator.validate(moduleNameSchema, 'deals');
|
|
106
|
-
expect(result.isValid).toBe(true);
|
|
107
|
-
expect(result.errors).toEqual([]);
|
|
108
|
-
});
|
|
109
|
-
it('should return invalid when string expected but number given', () => {
|
|
110
|
-
const result = Validator.validate(moduleNameSchema, 123);
|
|
111
|
-
expect(result.isValid).toBe(false);
|
|
112
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
113
|
-
});
|
|
114
|
-
it('should return valid for a value matching an enum', () => {
|
|
115
|
-
const result = Validator.validate(textOverflowConfigSchema, {
|
|
116
|
-
isEnabled: true,
|
|
117
|
-
mode: 'clip'
|
|
118
|
-
});
|
|
119
|
-
expect(result.isValid).toBe(true);
|
|
120
|
-
expect(result.errors).toEqual([]);
|
|
121
|
-
});
|
|
122
|
-
it('should return invalid for a value not in enum', () => {
|
|
123
|
-
const result = Validator.validate(textOverflowConfigSchema, {
|
|
124
|
-
isEnabled: true,
|
|
125
|
-
mode: 'scroll'
|
|
126
|
-
});
|
|
127
|
-
expect(result.isValid).toBe(false);
|
|
128
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
129
|
-
expect(result.errors.some(e => e.keyword === 'enum')).toBe(true);
|
|
130
|
-
});
|
|
131
|
-
it('should return valid for nested object with additionalProperties', () => {
|
|
132
|
-
const result = Validator.validate(preferencesSchema, {
|
|
133
|
-
fields: {
|
|
134
|
-
name: {
|
|
135
|
-
initialWidth: 200,
|
|
136
|
-
currencyLocale: 'en-US'
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
autoColumnSizing: true
|
|
140
|
-
});
|
|
141
|
-
expect(result.isValid).toBe(true);
|
|
142
|
-
});
|
|
143
|
-
it('should return invalid for nested additionalProperties with wrong type', () => {
|
|
144
|
-
const result = Validator.validate(preferencesSchema, {
|
|
145
|
-
fields: {
|
|
146
|
-
name: {
|
|
147
|
-
initialWidth: 'wide'
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
expect(result.isValid).toBe(false);
|
|
152
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
153
|
-
});
|
|
154
|
-
it('should return valid for a loose object schema with any object', () => {
|
|
155
|
-
const result = Validator.validate(nameFieldsConfigSchema, {
|
|
156
|
-
isEnabled: true,
|
|
157
|
-
isPreventDefault: false,
|
|
158
|
-
constructUrl: null,
|
|
159
|
-
extraProp: 'anything'
|
|
160
|
-
});
|
|
161
|
-
expect(result.isValid).toBe(true);
|
|
162
|
-
});
|
|
163
|
-
it('should return valid for selectionConfig with correct values', () => {
|
|
164
|
-
const result = Validator.validate(selectionConfigSchema, {
|
|
165
|
-
isEnabled: true,
|
|
166
|
-
maxSelectionCount: 50,
|
|
167
|
-
limitExceedAlertMessage: 'Maximum records selected',
|
|
168
|
-
isSelectAllEnabled: false
|
|
169
|
-
});
|
|
170
|
-
expect(result.isValid).toBe(true);
|
|
171
|
-
expect(result.errors).toEqual([]);
|
|
172
|
-
});
|
|
173
|
-
it('should return invalid for selectionConfig with wrong types', () => {
|
|
174
|
-
const result = Validator.validate(selectionConfigSchema, {
|
|
175
|
-
isEnabled: 'yes',
|
|
176
|
-
maxSelectionCount: 'fifty'
|
|
177
|
-
});
|
|
178
|
-
expect(result.isValid).toBe(false);
|
|
179
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
180
|
-
});
|
|
181
|
-
it('should return valid for componentMapping with partial properties', () => {
|
|
182
|
-
const result = Validator.validate(componentMappingSchema, {
|
|
183
|
-
fields: {},
|
|
184
|
-
emptyState: 'NoDataComponent'
|
|
185
|
-
});
|
|
186
|
-
expect(result.isValid).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
it('should return valid for an empty object when no properties are required', () => {
|
|
189
|
-
const result = Validator.validate(preferencesSchema, {});
|
|
190
|
-
expect(result.isValid).toBe(true);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
describe('checkFunctionsRecursively() — function type handling', () => {
|
|
194
|
-
it('should return valid when value is a function for function type schema', () => {
|
|
195
|
-
const schema = {
|
|
196
|
-
type: 'function'
|
|
197
|
-
};
|
|
198
|
-
const result = Validator.validate(schema, () => {});
|
|
199
|
-
expect(result.isValid).toBe(true);
|
|
200
|
-
expect(result.errors).toEqual([]);
|
|
201
|
-
});
|
|
202
|
-
it('should return error when value is not a function for function type schema', () => {
|
|
203
|
-
const schema = {
|
|
204
|
-
type: 'function'
|
|
205
|
-
};
|
|
206
|
-
const result = Validator.validate(schema, 'not a function');
|
|
207
|
-
expect(result.isValid).toBe(false);
|
|
208
|
-
expect(result.errors).toEqual(expect.arrayContaining([expect.objectContaining({
|
|
209
|
-
keyword: 'type',
|
|
210
|
-
params: {
|
|
211
|
-
type: 'function'
|
|
212
|
-
},
|
|
213
|
-
message: 'should be function'
|
|
214
|
-
})]));
|
|
215
|
-
});
|
|
216
|
-
it('should validate nested function property in object schema', () => {
|
|
217
|
-
const schema = {
|
|
218
|
-
type: 'object',
|
|
219
|
-
properties: {
|
|
220
|
-
onClick: {
|
|
221
|
-
type: 'function'
|
|
222
|
-
},
|
|
223
|
-
label: {
|
|
224
|
-
type: 'string'
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
const result = Validator.validate(schema, {
|
|
229
|
-
onClick: () => {},
|
|
230
|
-
label: 'Click me'
|
|
231
|
-
});
|
|
232
|
-
expect(result.isValid).toBe(true);
|
|
233
|
-
expect(result.errors).toEqual([]);
|
|
234
|
-
});
|
|
235
|
-
it('should return error with correct dataPath for nested function property', () => {
|
|
236
|
-
const schema = {
|
|
237
|
-
type: 'object',
|
|
238
|
-
properties: {
|
|
239
|
-
onClick: {
|
|
240
|
-
type: 'function'
|
|
241
|
-
},
|
|
242
|
-
label: {
|
|
243
|
-
type: 'string'
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
const result = Validator.validate(schema, {
|
|
248
|
-
onClick: 'not a function',
|
|
249
|
-
label: 'Click me'
|
|
250
|
-
});
|
|
251
|
-
expect(result.isValid).toBe(false);
|
|
252
|
-
expect(result.errors).toEqual(expect.arrayContaining([expect.objectContaining({
|
|
253
|
-
keyword: 'type',
|
|
254
|
-
dataPath: '.onClick',
|
|
255
|
-
schemaPath: '#/properties/onClick/type',
|
|
256
|
-
message: 'should be function'
|
|
257
|
-
})]));
|
|
258
|
-
});
|
|
259
|
-
it('should validate function items in array schema', () => {
|
|
260
|
-
const schema = {
|
|
261
|
-
type: 'array',
|
|
262
|
-
items: {
|
|
263
|
-
type: 'function'
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
const fn1 = () => {};
|
|
268
|
-
|
|
269
|
-
const fn2 = () => {};
|
|
270
|
-
|
|
271
|
-
const result = Validator.validate(schema, [fn1, fn2]);
|
|
272
|
-
expect(result.isValid).toBe(true);
|
|
273
|
-
expect(result.errors).toEqual([]);
|
|
274
|
-
});
|
|
275
|
-
it('should return error for non-function item in array of functions', () => {
|
|
276
|
-
const schema = {
|
|
277
|
-
type: 'array',
|
|
278
|
-
items: {
|
|
279
|
-
type: 'function'
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
const result = Validator.validate(schema, [() => {}, 'not a function']);
|
|
283
|
-
expect(result.isValid).toBe(false);
|
|
284
|
-
expect(result.errors).toEqual(expect.arrayContaining([expect.objectContaining({
|
|
285
|
-
keyword: 'type',
|
|
286
|
-
dataPath: '.[1]',
|
|
287
|
-
message: 'should be function'
|
|
288
|
-
})]));
|
|
289
|
-
});
|
|
290
|
-
it('should validate deeply nested function in object > object', () => {
|
|
291
|
-
const schema = {
|
|
292
|
-
type: 'object',
|
|
293
|
-
properties: {
|
|
294
|
-
handlers: {
|
|
295
|
-
type: 'object',
|
|
296
|
-
properties: {
|
|
297
|
-
onMount: {
|
|
298
|
-
type: 'function'
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
const result = Validator.validate(schema, {
|
|
305
|
-
handlers: {
|
|
306
|
-
onMount: 42
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
expect(result.isValid).toBe(false);
|
|
310
|
-
expect(result.errors).toEqual(expect.arrayContaining([expect.objectContaining({
|
|
311
|
-
dataPath: '.handlers.onMount',
|
|
312
|
-
schemaPath: '#/properties/handlers/properties/onMount/type'
|
|
313
|
-
})]));
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
describe('validatePropertySchema() — property schema path (schema.schema exists)', () => {
|
|
317
|
-
it('should return valid with key for required property provided with correct value', () => {
|
|
318
|
-
const propertySchema = {
|
|
319
|
-
required: true,
|
|
320
|
-
isValueProvided: true,
|
|
321
|
-
name: 'moduleName',
|
|
322
|
-
schema: moduleNameSchema
|
|
323
|
-
};
|
|
324
|
-
const result = Validator.validate(propertySchema, 'deals');
|
|
325
|
-
expect(result.isValid).toBe(true);
|
|
326
|
-
expect(result.key).toBe('moduleName');
|
|
327
|
-
expect(result.errors).toEqual([]);
|
|
328
|
-
expect(result.warnings).toEqual([]);
|
|
329
|
-
});
|
|
330
|
-
it('should return invalid for required property provided with wrong type', () => {
|
|
331
|
-
const propertySchema = {
|
|
332
|
-
required: true,
|
|
333
|
-
isValueProvided: true,
|
|
334
|
-
name: 'moduleName',
|
|
335
|
-
schema: moduleNameSchema
|
|
336
|
-
};
|
|
337
|
-
const result = Validator.validate(propertySchema, 123);
|
|
338
|
-
expect(result.isValid).toBe(false);
|
|
339
|
-
expect(result.key).toBe('moduleName');
|
|
340
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
341
|
-
});
|
|
342
|
-
it('should return valid with warning when required property missing but has default', () => {
|
|
343
|
-
const propertySchema = {
|
|
344
|
-
required: true,
|
|
345
|
-
isValueProvided: false,
|
|
346
|
-
defaultValue: {
|
|
347
|
-
isEnabled: true
|
|
348
|
-
},
|
|
349
|
-
name: 'keyboardControlsConfig',
|
|
350
|
-
schema: {
|
|
351
|
-
type: 'object',
|
|
352
|
-
properties: {
|
|
353
|
-
isEnabled: {
|
|
354
|
-
type: 'boolean'
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
const result = Validator.validate(propertySchema, undefined);
|
|
360
|
-
expect(result.isValid).toBe(true);
|
|
361
|
-
expect(result.errors).toEqual([]);
|
|
362
|
-
expect(result.warnings.length).toBeGreaterThan(0);
|
|
363
|
-
expect(result.warnings[0].message).toContain('Default value will be used');
|
|
364
|
-
});
|
|
365
|
-
it('should return invalid when required property missing and no default', () => {
|
|
366
|
-
const propertySchema = {
|
|
367
|
-
required: true,
|
|
368
|
-
isValueProvided: false,
|
|
369
|
-
name: 'moduleName',
|
|
370
|
-
schema: moduleNameSchema
|
|
371
|
-
};
|
|
372
|
-
const result = Validator.validate(propertySchema, undefined);
|
|
373
|
-
expect(result.isValid).toBe(false);
|
|
374
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
375
|
-
expect(result.errors[0].message).toContain('required but missing');
|
|
376
|
-
});
|
|
377
|
-
it('should return invalid when required property missing and default is undefined', () => {
|
|
378
|
-
const propertySchema = {
|
|
379
|
-
required: true,
|
|
380
|
-
isValueProvided: false,
|
|
381
|
-
defaultValue: undefined,
|
|
382
|
-
name: 'testProp',
|
|
383
|
-
schema: moduleNameSchema
|
|
384
|
-
};
|
|
385
|
-
const result = Validator.validate(propertySchema, undefined);
|
|
386
|
-
expect(result.isValid).toBe(false);
|
|
387
|
-
expect(result.errors[0].message).toContain('default value is undefined');
|
|
388
|
-
});
|
|
389
|
-
it('should return valid with no warnings for optional property not provided', () => {
|
|
390
|
-
const propertySchema = {
|
|
391
|
-
required: false,
|
|
392
|
-
isValueProvided: false,
|
|
393
|
-
name: 'preferences',
|
|
394
|
-
defaultValue: {
|
|
395
|
-
fields: {},
|
|
396
|
-
autoColumnSizing: false
|
|
397
|
-
},
|
|
398
|
-
schema: preferencesSchema
|
|
399
|
-
};
|
|
400
|
-
const result = Validator.validate(propertySchema, undefined);
|
|
401
|
-
expect(result.isValid).toBe(true);
|
|
402
|
-
expect(result.errors).toEqual([]);
|
|
403
|
-
expect(result.warnings).toEqual([]);
|
|
404
|
-
});
|
|
405
|
-
it('should return invalid for optional property provided with invalid value', () => {
|
|
406
|
-
const propertySchema = {
|
|
407
|
-
required: false,
|
|
408
|
-
isValueProvided: true,
|
|
409
|
-
name: 'textOverflowConfig',
|
|
410
|
-
schema: textOverflowConfigSchema
|
|
411
|
-
};
|
|
412
|
-
const result = Validator.validate(propertySchema, {
|
|
413
|
-
isEnabled: true,
|
|
414
|
-
mode: 'invalid'
|
|
415
|
-
});
|
|
416
|
-
expect(result.isValid).toBe(false);
|
|
417
|
-
expect(result.key).toBe('textOverflowConfig');
|
|
418
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
419
|
-
});
|
|
420
|
-
it('should return valid for optional property provided with valid value', () => {
|
|
421
|
-
const propertySchema = {
|
|
422
|
-
required: false,
|
|
423
|
-
isValueProvided: true,
|
|
424
|
-
name: 'textOverflowConfig',
|
|
425
|
-
schema: textOverflowConfigSchema
|
|
426
|
-
};
|
|
427
|
-
const result = Validator.validate(propertySchema, {
|
|
428
|
-
isEnabled: true,
|
|
429
|
-
mode: 'wrap'
|
|
430
|
-
});
|
|
431
|
-
expect(result.isValid).toBe(true);
|
|
432
|
-
expect(result.key).toBe('textOverflowConfig');
|
|
433
|
-
});
|
|
434
|
-
it('should validate componentMapping property schema with valid data', () => {
|
|
435
|
-
const propertySchema = {
|
|
436
|
-
required: false,
|
|
437
|
-
isValueProvided: true,
|
|
438
|
-
name: 'componentMapping',
|
|
439
|
-
defaultValue: {
|
|
440
|
-
fields: {},
|
|
441
|
-
emptyState: ''
|
|
442
|
-
},
|
|
443
|
-
schema: componentMappingSchema
|
|
444
|
-
};
|
|
445
|
-
const result = Validator.validate(propertySchema, {
|
|
446
|
-
fields: {
|
|
447
|
-
name: 'TextField'
|
|
448
|
-
},
|
|
449
|
-
rowActionsComponentName: 'RowActions',
|
|
450
|
-
emptyState: 'EmptyState'
|
|
451
|
-
});
|
|
452
|
-
expect(result.isValid).toBe(true);
|
|
453
|
-
expect(result.key).toBe('componentMapping');
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
describe('AJV useDefaults behavior', () => {
|
|
457
|
-
it('should fill in default values defined in schema', () => {
|
|
458
|
-
const schema = {
|
|
459
|
-
type: 'object',
|
|
460
|
-
properties: {
|
|
461
|
-
isEnabled: {
|
|
462
|
-
type: 'boolean',
|
|
463
|
-
default: true
|
|
464
|
-
},
|
|
465
|
-
mode: {
|
|
466
|
-
type: 'string',
|
|
467
|
-
default: 'clip'
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
const value = {};
|
|
472
|
-
const result = Validator.validate(schema, value);
|
|
473
|
-
expect(result.isValid).toBe(true);
|
|
474
|
-
expect(value.isEnabled).toBe(true);
|
|
475
|
-
expect(value.mode).toBe('clip');
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
});
|