@jsonforms/material-renderers 3.1.0-alpha.0 → 3.1.0-alpha.1

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 (100) hide show
  1. package/lib/controls/MaterialBooleanControl.d.ts +1 -1
  2. package/lib/controls/MaterialBooleanToggleControl.d.ts +1 -1
  3. package/lib/controls/index.d.ts +2 -2
  4. package/lib/jsonforms-react-material.cjs.js +79 -11
  5. package/lib/jsonforms-react-material.cjs.js.map +1 -1
  6. package/lib/jsonforms-react-material.esm.js +79 -11
  7. package/lib/jsonforms-react-material.esm.js.map +1 -1
  8. package/lib/mui-controls/MuiCheckbox.d.ts +6 -1
  9. package/lib/mui-controls/MuiToggle.d.ts +6 -1
  10. package/package.json +23 -12
  11. package/src/additional/ListWithDetailMasterItem.tsx +1 -1
  12. package/src/controls/MaterialBooleanControl.tsx +84 -23
  13. package/src/controls/MaterialBooleanToggleControl.tsx +84 -23
  14. package/src/mui-controls/MuiCheckbox.tsx +12 -5
  15. package/src/mui-controls/MuiToggle.tsx +12 -5
  16. package/docs/assets/css/main.css +0 -1
  17. package/docs/assets/images/icons.png +0 -0
  18. package/docs/assets/images/icons@2x.png +0 -0
  19. package/docs/assets/images/widgets.png +0 -0
  20. package/docs/assets/images/widgets@2x.png +0 -0
  21. package/docs/assets/js/main.js +0 -51
  22. package/docs/assets/js/search.json +0 -1
  23. package/docs/classes/combinatorproperties.html +0 -957
  24. package/docs/classes/materialanyofstringorenumcontrol.html +0 -822
  25. package/docs/classes/materialtablecontrol.html +0 -999
  26. package/docs/globals.html +0 -4492
  27. package/docs/index.html +0 -753
  28. package/docs/interfaces/ajvprops.html +0 -162
  29. package/docs/interfaces/arraylayouttoolbarprops.html +0 -253
  30. package/docs/interfaces/categorizationstate.html +0 -154
  31. package/docs/interfaces/categorizationstepperstate.html +0 -154
  32. package/docs/interfaces/combinatorpropertiesprops.html +0 -182
  33. package/docs/interfaces/deletedialogprops.html +0 -225
  34. package/docs/interfaces/dispatchpropsofexpandpanel.html +0 -296
  35. package/docs/interfaces/emptytableprops.html +0 -154
  36. package/docs/interfaces/expandpanelprops.html +0 -594
  37. package/docs/interfaces/inputref.html +0 -168
  38. package/docs/interfaces/jsonformstheme.html +0 -352
  39. package/docs/interfaces/materialcategorizationlayoutrendererprops.html +0 -460
  40. package/docs/interfaces/materialcategorizationstepperlayoutrendererprops.html +0 -394
  41. package/docs/interfaces/materiallabelablelayoutrendererprops.html +0 -328
  42. package/docs/interfaces/materiallayoutrendererprops.html +0 -317
  43. package/docs/interfaces/materialtabletoolbarprops.html +0 -302
  44. package/docs/interfaces/muitextinputprops.html +0 -168
  45. package/docs/interfaces/nonemptycellcomponentprops.html +0 -266
  46. package/docs/interfaces/nonemptycellprops.html +0 -277
  47. package/docs/interfaces/nonemptyrowprops.html +0 -366
  48. package/docs/interfaces/ownoneofprops.html +0 -308
  49. package/docs/interfaces/ownpropsofexpandpanel.html +0 -397
  50. package/docs/interfaces/ownpropsofnonemptycell.html +0 -229
  51. package/docs/interfaces/statepropsofexpandpanel.html +0 -445
  52. package/docs/interfaces/tableheadercellprops.html +0 -154
  53. package/docs/interfaces/tablerowsprop.html +0 -330
  54. package/docs/interfaces/validationprops.html +0 -168
  55. package/docs/interfaces/withdeletedialogsupport.html +0 -170
  56. package/docs/interfaces/withinput.html +0 -154
  57. package/docs/interfaces/withoptionlabel.html +0 -230
  58. package/example/index.html +0 -16
  59. package/example/index.ts +0 -31
  60. package/rollup.config.js +0 -51
  61. package/stats.html +0 -3279
  62. package/test/renderers/MatchMediaMock.ts +0 -36
  63. package/test/renderers/MaterialAllOfRenderer.test.tsx +0 -114
  64. package/test/renderers/MaterialAnyOfRenderer.test.tsx +0 -310
  65. package/test/renderers/MaterialAnyOfStringOrEnumControl.test.tsx +0 -126
  66. package/test/renderers/MaterialArrayControl.test.tsx +0 -633
  67. package/test/renderers/MaterialArrayLayout.test.tsx +0 -528
  68. package/test/renderers/MaterialBooleanCell.test.tsx +0 -374
  69. package/test/renderers/MaterialBooleanToggleCell.test.tsx +0 -466
  70. package/test/renderers/MaterialBooleanToggleControl.test.tsx +0 -469
  71. package/test/renderers/MaterialCategorizationLayout.test.tsx +0 -458
  72. package/test/renderers/MaterialCategorizationStepperLayout.test.tsx +0 -647
  73. package/test/renderers/MaterialDateCell.test.tsx +0 -303
  74. package/test/renderers/MaterialDateControl.test.tsx +0 -411
  75. package/test/renderers/MaterialDateTimeControl.test.tsx +0 -417
  76. package/test/renderers/MaterialEnumArrayRenderer.test.tsx +0 -207
  77. package/test/renderers/MaterialEnumCell.test.tsx +0 -88
  78. package/test/renderers/MaterialEnumControl.test.tsx +0 -75
  79. package/test/renderers/MaterialGroupLayout.test.tsx +0 -90
  80. package/test/renderers/MaterialInputControl.test.tsx +0 -370
  81. package/test/renderers/MaterialIntegerCell.test.tsx +0 -333
  82. package/test/renderers/MaterialLabelRenderer.test.tsx +0 -114
  83. package/test/renderers/MaterialLayouts.test.tsx +0 -542
  84. package/test/renderers/MaterialListWithDetailRenderer.test.tsx +0 -279
  85. package/test/renderers/MaterialNativeControl.test.tsx +0 -81
  86. package/test/renderers/MaterialNumberCell.test.tsx +0 -382
  87. package/test/renderers/MaterialObjectControl.test.tsx +0 -186
  88. package/test/renderers/MaterialOneOfEnumCell.test.tsx +0 -94
  89. package/test/renderers/MaterialOneOfRadioGroupControl.test.tsx +0 -108
  90. package/test/renderers/MaterialOneOfRenderer.test.tsx +0 -603
  91. package/test/renderers/MaterialRadioGroupControl.test.tsx +0 -125
  92. package/test/renderers/MaterialSliderControl.test.tsx +0 -438
  93. package/test/renderers/MaterialTextCell.test.tsx +0 -541
  94. package/test/renderers/MaterialTextControl.test.tsx +0 -115
  95. package/test/renderers/MaterialTimeCell.test.tsx +0 -331
  96. package/test/renderers/MaterialTimeControl.test.tsx +0 -411
  97. package/test/renderers/util.ts +0 -50
  98. package/tsconfig.json +0 -13
  99. package/tsconfig.test.json +0 -7
  100. package/webpack/webpack.dev.js +0 -11
@@ -1,108 +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 './MatchMediaMock';
26
- import * as React from 'react';
27
- import {
28
- ControlElement,
29
- NOT_APPLICABLE,
30
- } from '@jsonforms/core';
31
- import MaterialOneOfRadioGroupControl, {
32
- materialOneOfRadioGroupControlTester
33
- } from '../../src/controls/MaterialOneOfRadioGroupControl';
34
- import { materialRenderers } from '../../src';
35
- import Enzyme, { mount, ReactWrapper } from 'enzyme';
36
- import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
37
- import {
38
- JsonFormsStateProvider
39
- } from '@jsonforms/react';
40
- import { initCore } from './util';
41
- Enzyme.configure({ adapter: new Adapter() });
42
-
43
- const oneOfSchema = {
44
- type: 'object',
45
- properties: {
46
- foo: {
47
- type: 'string',
48
- oneOf: [
49
- { const: 'A', title: 'Option A' },
50
- { const: 'B' },
51
- { const: 'C', title: 'Option C' }
52
- ]
53
- }
54
- }
55
- };
56
- const uischema: ControlElement = {
57
- type: 'Control',
58
- scope: '#/properties/foo',
59
- options: {
60
- format: 'radio'
61
- }
62
- };
63
-
64
- describe('Material oneof radio group tester', () => {
65
- it('should return valid rank for oneof enums with radio format', () => {
66
- const rank = materialOneOfRadioGroupControlTester(uischema, oneOfSchema, undefined);
67
- expect(rank).not.toBe(NOT_APPLICABLE);
68
- });
69
-
70
- it('should return NOT_APPLICABLE for enums without radio format', () => {
71
- const uiSchemaNoRadio = {
72
- type: 'Control',
73
- scope: '#/properties/foo'
74
- };
75
- const rank = materialOneOfRadioGroupControlTester(
76
- uiSchemaNoRadio,
77
- oneOfSchema,
78
- undefined
79
- );
80
- expect(rank).toBe(NOT_APPLICABLE);
81
- });
82
- });
83
-
84
- describe('Material oneof radio group control', () => {
85
- let wrapper: ReactWrapper;
86
-
87
- afterEach(() => wrapper.unmount());
88
-
89
- it('should render oneOf schemas ', () => {
90
- const core = initCore(oneOfSchema, uischema, { foo: 'B' });
91
-
92
- wrapper = mount(
93
- <JsonFormsStateProvider
94
- initState={{ renderers: materialRenderers, core }}
95
- >
96
- <MaterialOneOfRadioGroupControl
97
- schema={oneOfSchema}
98
- uischema={uischema}
99
- />
100
- </JsonFormsStateProvider>
101
- );
102
- const inputs = wrapper.find('input[type="radio"]');
103
- expect(inputs.length).toBe(3);
104
- const currentlyChecked = inputs.find('[checked=true]');
105
- expect(currentlyChecked.length).toBe(1);
106
- expect(currentlyChecked.first().props().value).toBe('B');
107
- });
108
- });
@@ -1,603 +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 './MatchMediaMock';
26
- import React from 'react';
27
- import Dialog from '@mui/material/Dialog';
28
-
29
- import Enzyme, { mount, ReactWrapper } from 'enzyme';
30
- import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
31
- import {
32
- ControlElement
33
- } from '@jsonforms/core';
34
- import {
35
- MaterialOneOfRenderer,
36
- materialRenderers
37
- } from '../../src';
38
- import { JsonForms, JsonFormsDispatch, JsonFormsStateProvider } from '@jsonforms/react';
39
- import { Tab } from '@mui/material';
40
- import { initCore, TestEmitter } from './util';
41
-
42
- Enzyme.configure({ adapter: new Adapter() });
43
-
44
- const waitForAsync = () => new Promise(resolve => setImmediate(resolve));
45
-
46
- const clickAddButton = (wrapper: ReactWrapper, times: number) => {
47
- // click add button
48
- const buttons = wrapper.find('button');
49
- const addButton = buttons.at(2);
50
- for (let i = 0; i < times; i++) {
51
- addButton.simulate('click');
52
- }
53
- wrapper.update();
54
- };
55
-
56
- const selectOneOfTab = (
57
- wrapper: ReactWrapper,
58
- at: number,
59
- expectConfim: boolean
60
- ) => {
61
- // select oneOf
62
- const buttons = wrapper.find('button');
63
- buttons.at(at).simulate('click');
64
- wrapper.update();
65
-
66
- if (expectConfim) {
67
- // confirm dialog
68
- const confirmButton = wrapper
69
- .find(Dialog)
70
- .last()
71
- .find('button')
72
- .at(1);
73
- confirmButton.simulate('click');
74
- wrapper.update();
75
- } else {
76
- expect(
77
- wrapper
78
- .find(Dialog)
79
- .last()
80
- .find('button')
81
- .at(1)
82
- .exists()
83
- ).toBe(false);
84
- }
85
- };
86
-
87
- describe('Material oneOf renderer', () => {
88
- let wrapper: ReactWrapper;
89
-
90
- afterEach(() => wrapper.unmount());
91
-
92
- it('should render and select first tab by default', () => {
93
- const schema = {
94
- type: 'object',
95
- properties: {
96
- value: {
97
- oneOf: [
98
- {
99
- title: 'String',
100
- type: 'string'
101
- },
102
- {
103
- title: 'Number',
104
- type: 'number'
105
- }
106
- ]
107
- }
108
- }
109
- };
110
- const uischema: ControlElement = {
111
- type: 'Control',
112
- label: 'Value',
113
- scope: '#/properties/value'
114
- };
115
- const core = initCore(schema, uischema, { data: undefined });
116
- wrapper = mount(
117
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
118
- <MaterialOneOfRenderer schema={schema} uischema={uischema} />
119
- </JsonFormsStateProvider>
120
- );
121
-
122
- const firstTab = wrapper.find(Tab).first();
123
- expect(firstTab.html()).toContain('Mui-selected');
124
- });
125
-
126
- it('should render and select second tab due to datatype', () => {
127
- const schema = {
128
- type: 'object',
129
- properties: {
130
- value: {
131
- oneOf: [
132
- {
133
- title: 'String',
134
- type: 'string'
135
- },
136
- {
137
- title: 'Number',
138
- type: 'number'
139
- }
140
- ]
141
- }
142
- }
143
- };
144
- const uischema: ControlElement = {
145
- type: 'Control',
146
- label: 'Value',
147
- scope: '#/properties/value'
148
- };
149
- const data = {
150
- value: 5
151
- };
152
- wrapper = mount(
153
- <JsonForms
154
- data={data}
155
- schema={schema}
156
- uischema={uischema}
157
- renderers={materialRenderers}
158
- />
159
- );
160
- expect(wrapper.find(MaterialOneOfRenderer).length).toBeTruthy();
161
-
162
- const secondTab = wrapper.find(Tab).at(1);
163
- expect(secondTab.html()).toContain('Mui-selected');
164
- });
165
-
166
- it('should render and select second tab due to schema with additionalProperties', () => {
167
- const schema = {
168
- type: 'object',
169
- properties: {
170
- value: {
171
- oneOf: [
172
- {
173
- title: 'String',
174
- type: 'object',
175
- properties: {
176
- foo: { type: 'string' }
177
- },
178
- additionalProperties: false
179
- },
180
- {
181
- title: 'Number',
182
- type: 'object',
183
- properties: {
184
- bar: { type: 'string' }
185
- },
186
- additionalProperties: false
187
- }
188
- ]
189
- }
190
- }
191
- };
192
- const uischema: ControlElement = {
193
- type: 'Control',
194
- label: 'Value',
195
- scope: '#/properties/value'
196
- };
197
- const data = {
198
- value: { bar: 'bar' }
199
- };
200
- wrapper = mount(
201
- <JsonForms
202
- data={data}
203
- schema={schema}
204
- uischema={uischema}
205
- renderers={materialRenderers}
206
- />
207
- );
208
- expect(wrapper.find(MaterialOneOfRenderer).length).toBeTruthy();
209
-
210
- const secondTab = wrapper.find(Tab).at(1);
211
- expect(secondTab.html()).toContain('Mui-selected');
212
- });
213
-
214
- it('should render and select second tab due to schema with required', () => {
215
- const schema = {
216
- type: 'object',
217
- properties: {
218
- value: {
219
- oneOf: [
220
- {
221
- title: 'String',
222
- type: 'object',
223
- properties: {
224
- foo: { type: 'string' }
225
- },
226
- required: ['foo']
227
- },
228
- {
229
- title: 'Number',
230
- type: 'object',
231
- properties: {
232
- bar: { type: 'string' }
233
- },
234
- required: ['bar']
235
- }
236
- ]
237
- }
238
- }
239
- };
240
- const uischema: ControlElement = {
241
- type: 'Control',
242
- label: 'Value',
243
- scope: '#/properties/value'
244
- };
245
- const data = {
246
- value: { bar: 'bar' }
247
- };
248
- wrapper = mount(
249
- <JsonForms
250
- data={data}
251
- schema={schema}
252
- uischema={uischema}
253
- renderers={materialRenderers}
254
- />
255
- );
256
- expect(wrapper.find(MaterialOneOfRenderer).length).toBeTruthy();
257
-
258
- const secondTab = wrapper.find(Tab).at(1);
259
- expect(secondTab.html()).toContain('Mui-selected');
260
- });
261
-
262
- it('should add an item at correct path', (done) => {
263
- const schema = {
264
- type: 'object',
265
- properties: {
266
- value: {
267
- oneOf: [
268
- {
269
- title: 'String',
270
- type: 'string'
271
- },
272
- {
273
- title: 'Number',
274
- type: 'number'
275
- }
276
- ]
277
- }
278
- }
279
- };
280
- const uischema: ControlElement = {
281
- type: 'Control',
282
- label: 'Value',
283
- scope: '#/properties/value'
284
- };
285
- const onChangeData: any = {
286
- data: undefined
287
- };
288
- wrapper = mount(
289
- <JsonForms
290
- data={undefined}
291
- schema={schema}
292
- uischema={uischema}
293
- renderers={materialRenderers}
294
- onChange={({ data }) => {
295
- onChangeData.data = data;
296
- }}
297
- />
298
- );
299
- expect(wrapper.find(MaterialOneOfRenderer).length).toBeTruthy();
300
-
301
- const input = wrapper.find('input').first();
302
- input.simulate('change', { target: { value: 'test' } });
303
- wrapper.update();
304
- setTimeout(() => {
305
- expect(onChangeData.data).toEqual({
306
- value: 'test'
307
- });
308
- done();
309
- }, 1000);
310
- });
311
-
312
- it('should add an item within an array', async () => {
313
- const schema = {
314
- type: 'object',
315
- properties: {
316
- thingOrThings: {
317
- oneOf: [
318
- {
319
- $ref: '#/definitions/thing'
320
- },
321
- {
322
- $ref: '#/definitions/thingArray'
323
- }
324
- ]
325
- }
326
- },
327
- definitions: {
328
- thing: {
329
- title: 'Thing',
330
- type: 'string'
331
- },
332
- thingArray: {
333
- title: 'Things',
334
- type: 'array',
335
- items: {
336
- $ref: '#/definitions/thing'
337
- }
338
- }
339
- }
340
- };
341
- const uischema: ControlElement = {
342
- type: 'Control',
343
- scope: '#/properties/thingOrThings'
344
- };
345
-
346
- const core = initCore(schema, uischema, { data: {} });
347
-
348
- wrapper = mount(
349
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
350
- <JsonFormsDispatch schema={schema} uischema={uischema} />
351
- </JsonFormsStateProvider>
352
- );
353
-
354
- await waitForAsync();
355
-
356
- wrapper.update();
357
-
358
- selectOneOfTab(wrapper, 1, false);
359
- const nrOfRowsBeforeAdd = wrapper.find('tr');
360
- clickAddButton(wrapper, 2);
361
- const nrOfRowsAfterAdd = wrapper.find('tr');
362
-
363
- // 1 header row + no data row
364
- expect(nrOfRowsBeforeAdd.length).toBe(2);
365
- // 1 header row + 2 data rows (one is replacing the 'No data' one)
366
- expect(nrOfRowsAfterAdd.length).toBe(3);
367
- });
368
-
369
- it('should add an object within an array', async () => {
370
- const schema = {
371
- type: 'object',
372
- properties: {
373
- thingOrThings: {
374
- oneOf: [
375
- {
376
- title: 'Thing',
377
- type: 'object',
378
- properties: {
379
- thing: {
380
- $ref: '#/definitions/thing'
381
- }
382
- }
383
- },
384
- {
385
- $ref: '#/definitions/thingArray'
386
- }
387
- ]
388
- }
389
- },
390
- definitions: {
391
- thing: {
392
- title: 'Thing',
393
- type: 'string'
394
- },
395
- thingArray: {
396
- title: 'Things',
397
- type: 'array',
398
- items: {
399
- $ref: '#/definitions/thing'
400
- }
401
- }
402
- }
403
- };
404
- const uischema: ControlElement = {
405
- type: 'Control',
406
- scope: '#/properties/thingOrThings'
407
- };
408
-
409
- const core = initCore(schema, uischema, {});
410
- const onChangeData: any = {
411
- data: undefined
412
- };
413
-
414
- wrapper = mount(
415
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
416
- <TestEmitter
417
- onChange={({ data }) => {
418
- onChangeData.data = data;
419
- }}
420
- />
421
- <JsonFormsDispatch schema={schema} uischema={uischema} />
422
- </JsonFormsStateProvider>
423
- );
424
-
425
- await waitForAsync();
426
-
427
- wrapper.update();
428
-
429
- selectOneOfTab(wrapper, 1, false);
430
- const nrOfRowsBeforeAdd = wrapper.find('tr');
431
- clickAddButton(wrapper, 2);
432
- const nrOfRowsAfterAdd = wrapper.find('tr');
433
-
434
- // 1 header row + no data row
435
- expect(nrOfRowsBeforeAdd.length).toBe(2);
436
- // 1 header row + 2 data rows (one is replacing the 'No data' one)
437
- expect(nrOfRowsAfterAdd.length).toBe(3);
438
- expect(onChangeData.data).toEqual({
439
- thingOrThings: ['', '']
440
- });
441
- });
442
-
443
- it('should switch to array based oneOf subschema, then switch back, then edit', async (done) => {
444
- const schema = {
445
- type: 'object',
446
- properties: {
447
- thingOrThings: {
448
- oneOf: [
449
- {
450
- title: 'Thing',
451
- type: 'object',
452
- properties: {
453
- thing: {
454
- $ref: '#/definitions/thing'
455
- }
456
- }
457
- },
458
- {
459
- $ref: '#/definitions/thingArray'
460
- }
461
- ]
462
- }
463
- },
464
- definitions: {
465
- thing: {
466
- title: 'Thing',
467
- type: 'string'
468
- },
469
- thingArray: {
470
- title: 'Things',
471
- type: 'array',
472
- items: {
473
- $ref: '#/definitions/thing'
474
- }
475
- }
476
- }
477
- };
478
- const uischema: ControlElement = {
479
- type: 'Control',
480
- scope: '#/properties/thingOrThings'
481
- };
482
-
483
- const core = initCore(schema, uischema, {});
484
- const onChangeData: any = {
485
- data: undefined
486
- };
487
-
488
- wrapper = mount(
489
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
490
- <TestEmitter
491
- onChange={({ data }) => {
492
- onChangeData.data = data;
493
- }}
494
- />
495
- <JsonFormsDispatch
496
- schema={schema}
497
- uischema={uischema}
498
- />
499
- </JsonFormsStateProvider>
500
- );
501
-
502
- await waitForAsync();
503
-
504
- wrapper.update();
505
-
506
- selectOneOfTab(wrapper, 1, false);
507
- clickAddButton(wrapper, 2);
508
- selectOneOfTab(wrapper, 0, true);
509
-
510
- const input = wrapper.find('input').first();
511
- input.simulate('change', { target: { value: 'test' } });
512
- wrapper.update();
513
-
514
- setTimeout(() => {
515
- expect(onChangeData.data).toEqual({
516
- thingOrThings: { thing: 'test' }
517
- });
518
- done();
519
- }, 1000);
520
-
521
-
522
- });
523
-
524
- it('should show confirm dialog when data is not an empty object', async () => {
525
- const schema = {
526
- type: 'object',
527
- properties: {
528
- value: {
529
- oneOf: [
530
- {
531
- title: 'String',
532
- type: 'string'
533
- },
534
- {
535
- title: 'Number',
536
- type: 'number'
537
- }
538
- ]
539
- }
540
- }
541
- };
542
-
543
- const uischema: ControlElement = {
544
- type: 'Control',
545
- label: 'Value',
546
- scope: '#/properties/value'
547
- };
548
-
549
- const data = {
550
- value: 'Foo Bar'
551
- };
552
- wrapper = mount(
553
- <JsonForms
554
- data={data}
555
- schema={schema}
556
- uischema={uischema}
557
- renderers={materialRenderers}
558
- />
559
- );
560
- expect(wrapper.find(MaterialOneOfRenderer).length).toBeTruthy();
561
-
562
- await waitForAsync();
563
- wrapper.update();
564
- selectOneOfTab(wrapper, 1, true);
565
- });
566
-
567
- it('should be hideable', () => {
568
- const schema = {
569
- type: 'object',
570
- properties: {
571
- value: {
572
- oneOf: [
573
- {
574
- title: 'String',
575
- type: 'string'
576
- },
577
- {
578
- title: 'Number',
579
- type: 'number'
580
- }
581
- ]
582
- }
583
- }
584
- };
585
- const uischema: ControlElement = {
586
- type: 'Control',
587
- label: 'Value',
588
- scope: '#/properties/value'
589
- };
590
- const core = initCore(schema, uischema, { data: undefined });
591
- wrapper = mount(
592
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
593
- <MaterialOneOfRenderer
594
- schema={schema}
595
- uischema={uischema}
596
- visible={false}
597
- />
598
- </JsonFormsStateProvider>
599
- );
600
- const inputs = wrapper.find('input');
601
- expect(inputs.length).toBe(0);
602
- });
603
- });