@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,417 +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 {
28
- ControlElement,
29
- NOT_APPLICABLE,
30
- } from '@jsonforms/core';
31
- import MaterialDateTimeControl, {
32
- materialDateTimeControlTester
33
- } from '../../src/controls/MaterialDateTimeControl';
34
- import dayjs from 'dayjs';
35
- import { materialRenderers } from '../../src';
36
-
37
- import Enzyme, { mount, ReactWrapper } from 'enzyme';
38
- import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
39
- import { JsonFormsStateProvider } from '@jsonforms/react';
40
- import { initCore, TestEmitter } from './util';
41
-
42
- Enzyme.configure({ adapter: new Adapter() });
43
-
44
- const data = { foo: dayjs('1980-04-04 13:37').format() };
45
- const schema = {
46
- type: 'object',
47
- properties: {
48
- foo: {
49
- type: 'string',
50
- format: 'date-time'
51
- }
52
- }
53
- };
54
- const uischema: ControlElement = {
55
- type: 'Control',
56
- scope: '#/properties/foo'
57
- };
58
-
59
- describe('Material date time control tester', () => {
60
- it('should fail', () => {
61
- expect(materialDateTimeControlTester(undefined, undefined, undefined)).toBe(
62
- NOT_APPLICABLE
63
- );
64
- expect(materialDateTimeControlTester(null, undefined, undefined)).toBe(NOT_APPLICABLE);
65
- expect(materialDateTimeControlTester({ type: 'Foo' }, undefined, undefined)).toBe(
66
- NOT_APPLICABLE
67
- );
68
- expect(materialDateTimeControlTester({ type: 'Control' }, undefined, undefined)).toBe(
69
- NOT_APPLICABLE
70
- );
71
- expect(
72
- materialDateTimeControlTester(uischema, {
73
- type: 'object',
74
- properties: {
75
- foo: { type: 'string' }
76
- }
77
- },
78
- undefined)
79
- ).toBe(NOT_APPLICABLE);
80
- expect(
81
- materialDateTimeControlTester(uischema, {
82
- type: 'object',
83
- properties: {
84
- foo: { type: 'string' },
85
- bar: {
86
- type: 'string',
87
- format: 'date-time'
88
- }
89
- }
90
- },
91
- undefined)
92
- ).toBe(NOT_APPLICABLE);
93
- });
94
-
95
- it('should succeed', () => {
96
- expect(
97
- materialDateTimeControlTester(uischema, {
98
- type: 'object',
99
- properties: {
100
- foo: {
101
- type: 'string',
102
- format: 'date-time'
103
- }
104
- }
105
- },
106
- undefined)
107
- ).toBe(2);
108
- expect(
109
- materialDateTimeControlTester(
110
- { ...uischema, options: { format: 'date-time' } },
111
- {
112
- type: 'object',
113
- properties: {
114
- foo: {
115
- type: 'string'
116
- }
117
- }
118
- },
119
- undefined
120
- )
121
- ).toBe(2);
122
- });
123
- });
124
-
125
- describe('Material date time control', () => {
126
- let wrapper: ReactWrapper;
127
-
128
- afterEach(() => {
129
- wrapper.unmount();
130
- });
131
-
132
- it('should autofocus via option', () => {
133
- const control: ControlElement = {
134
- type: 'Control',
135
- scope: '#/properties/foo',
136
- options: {
137
- focus: true
138
- }
139
- };
140
- const core = initCore(schema, control, data);
141
- wrapper = mount(
142
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
143
- <MaterialDateTimeControl schema={schema} uischema={control} />
144
- </JsonFormsStateProvider>
145
- );
146
- const input = wrapper.find('input').first();
147
- expect(input.props().autoFocus).toBeTruthy();
148
- });
149
-
150
- it('should not autofocus via option', () => {
151
- const control: ControlElement = {
152
- type: 'Control',
153
- scope: '#/properties/foo',
154
- options: {
155
- focus: false
156
- }
157
- };
158
- const core = initCore(schema, control, data);
159
- wrapper = mount(
160
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
161
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
162
- </JsonFormsStateProvider>
163
- );
164
- const input = wrapper.find('input').first();
165
- expect(input.props().autoFocus).toBeFalsy();
166
- });
167
-
168
- it('should not autofocus by default', () => {
169
- const control: ControlElement = {
170
- type: 'Control',
171
- scope: '#/properties/foo'
172
- };
173
- const core = initCore(schema, uischema, data);
174
- wrapper = mount(
175
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
176
- <MaterialDateTimeControl schema={schema} uischema={control} />
177
- </JsonFormsStateProvider>
178
- );
179
- const input = wrapper.find('input').first();
180
- expect(input.props().autoFocus).toBeFalsy();
181
- });
182
-
183
- it('should render', () => {
184
- const core = initCore(schema, uischema, data);
185
- wrapper = mount(
186
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
187
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
188
- </JsonFormsStateProvider>
189
- );
190
-
191
- const input = wrapper.find('input').first();
192
- expect(input.props().type).toBe('text');
193
- expect(input.props().value).toBe('1980-04-04 13:37');
194
- });
195
-
196
- it('should update via event', () => {
197
- const core = initCore(schema, uischema, data);
198
- const onChangeData: any = {
199
- data: undefined
200
- };
201
- wrapper = mount(
202
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
203
- <TestEmitter
204
- onChange={({ data }) => {
205
- onChangeData.data = data;
206
- }}
207
- />
208
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
209
- </JsonFormsStateProvider>
210
- );
211
- const input = wrapper.find('input').first();
212
- (input.getDOMNode() as HTMLInputElement).value ='1961-12-12 20:15';
213
- input.simulate('change', input);
214
- expect(onChangeData.data.foo).toBe(
215
- dayjs('1961-12-12 20:15').format()
216
- );
217
- });
218
-
219
- it('should update via action', () => {
220
- const core = initCore(schema, uischema, data);
221
- wrapper = mount(
222
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
223
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
224
- </JsonFormsStateProvider>
225
- );
226
- core.data = { ...core.data, foo: dayjs('1961-12-04 20:15').format() };
227
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
228
- wrapper.update();
229
- const input = wrapper.find('input').first();
230
- expect(input.props().value).toBe('1961-12-04 20:15');
231
- });
232
-
233
- it('should update with null value', () => {
234
- const core = initCore(schema, uischema, data);
235
- wrapper = mount(
236
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
237
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
238
- </JsonFormsStateProvider>
239
- );
240
- core.data = { ...core.data, foo: null };
241
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
242
- wrapper.update();
243
- const input = wrapper.find('input').first();
244
- expect(input.props().value).toBe('');
245
- });
246
-
247
- it('should not update with undefined value', () => {
248
- const core = initCore(schema, uischema, data);
249
- wrapper = mount(
250
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
251
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
252
- </JsonFormsStateProvider>
253
- );
254
- core.data = { ...core.data, foo: undefined };
255
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
256
- wrapper.update();
257
- const input = wrapper.find('input').first();
258
- expect(input.props().value).toBe('');
259
- });
260
-
261
- it('should not update with wrong ref', () => {
262
- const core = initCore(schema, uischema, data);
263
- wrapper = mount(
264
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
265
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
266
- </JsonFormsStateProvider>
267
- );
268
- core.data = { ...core.data, bar: 'Bar' };
269
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
270
- wrapper.update();
271
- const input = wrapper.find('input').first();
272
- expect(input.props().value).toBe('1980-04-04 13:37');
273
- });
274
-
275
- it('should not update with null ref', () => {
276
- const core = initCore(schema, uischema, data);
277
- wrapper = mount(
278
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
279
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
280
- </JsonFormsStateProvider>
281
- );
282
- core.data = { ...core.data, null: '12.04.1961 20:15' };
283
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
284
- wrapper.update();
285
- const input = wrapper.find('input').first();
286
- expect(input.props().value).toBe('1980-04-04 13:37');
287
- });
288
-
289
- it('should not update with undefined ref', () => {
290
- const core = initCore(schema, uischema, data);
291
- wrapper = mount(
292
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
293
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
294
- </JsonFormsStateProvider>
295
- );
296
- core.data = { ...core.data, undefined: '12.04.1961 20:15' };
297
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
298
- wrapper.update();
299
- const input = wrapper.find('input').first();
300
- expect(input.props().value).toBe('1980-04-04 13:37');
301
- });
302
-
303
- it('can be disabled', () => {
304
- const core = initCore(schema, uischema, data);
305
- wrapper = mount(
306
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
307
- <MaterialDateTimeControl
308
- schema={schema}
309
- uischema={uischema}
310
- enabled={false}
311
- />
312
- </JsonFormsStateProvider>
313
- );
314
- const input = wrapper.find('input').first();
315
- expect(input.props().disabled).toBeTruthy();
316
- });
317
-
318
- it('should be enabled by default', () => {
319
- const core = initCore(schema, uischema, data);
320
- wrapper = mount(
321
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
322
- <MaterialDateTimeControl schema={schema} uischema={uischema} />
323
- </JsonFormsStateProvider>
324
- );
325
- const input = wrapper.find('input').first();
326
- expect(input.props().disabled).toBeFalsy();
327
- });
328
-
329
- it('should render input id', () => {
330
- const core = initCore(schema, uischema, data);
331
- wrapper = mount(
332
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
333
- <MaterialDateTimeControl
334
- schema={schema}
335
- uischema={uischema}
336
- id='#/properties/foo'
337
- />
338
- </JsonFormsStateProvider>
339
- );
340
- const input = wrapper.find('input').first();
341
- // there is only input id at the dayjs
342
- expect(input.props().id).toBe('#/properties/foo-input');
343
- });
344
-
345
- it('should be hideable', () => {
346
- const core = initCore(schema, uischema, data);
347
- wrapper = mount(
348
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
349
- <MaterialDateTimeControl
350
- schema={schema}
351
- uischema={uischema}
352
- visible={false}
353
- />
354
- </JsonFormsStateProvider>
355
- );
356
- const inputs = wrapper.find('input');
357
- expect(inputs.length).toBe(0);
358
- });
359
-
360
- it('should support format customizations', () => {
361
- const core = initCore(schema, uischema, {foo: dayjs('1980-04-23 13:37').format('YYYY/MM/DD h:mm a')});
362
- const onChangeData: any = {
363
- data: undefined
364
- };
365
- wrapper = mount(
366
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
367
- <TestEmitter
368
- onChange={({ data }) => {
369
- onChangeData.data = data;
370
- }}
371
- />
372
- <MaterialDateTimeControl
373
- schema={schema}
374
- uischema={{...uischema, options: {
375
- dateTimeFormat: 'DD-MM-YY hh:mm:a',
376
- dateTimeSaveFormat: 'YYYY/MM/DD h:mm a',
377
- ampm: true
378
- }}}
379
- />
380
- </JsonFormsStateProvider>
381
- );
382
-
383
- const input = wrapper.find('input').first();
384
- expect(input.props().value).toBe('23-04-80 01:37:pm');
385
-
386
- (input.getDOMNode() as HTMLInputElement).value = '10-12-05 11:22:am';
387
- input.simulate('change', input);
388
- expect(onChangeData.data.foo).toBe('2005/12/10 11:22 am');
389
- });
390
-
391
- it('should call onChange with original input value for invalid date strings', () => {
392
- const core = initCore(schema, uischema);
393
- const onChangeData: any = {
394
- data: undefined
395
- };
396
- wrapper = mount(
397
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
398
- <TestEmitter
399
- onChange={({ data }) => {
400
- onChangeData.data = data;
401
- }}
402
- />
403
- <MaterialDateTimeControl
404
- schema={schema}
405
- uischema={{...uischema}}
406
- />
407
- </JsonFormsStateProvider>
408
- );
409
-
410
- const input = wrapper.find('input').first();
411
- expect(input.props().value).toBe('');
412
-
413
- (input.getDOMNode() as HTMLInputElement).value = 'invalid date string';
414
- input.simulate('change', input);
415
- expect(onChangeData.data.foo).toBe('invalid date string');
416
- });
417
- });
@@ -1,207 +0,0 @@
1
- import './MatchMediaMock';
2
- import { ControlElement, NOT_APPLICABLE } from '@jsonforms/core';
3
- import { JsonForms } from '@jsonforms/react';
4
- import Enzyme, { mount, ReactWrapper } from 'enzyme';
5
- import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
6
- import React from 'react';
7
- import {
8
- materialEnumArrayRendererTester,
9
- MaterialEnumArrayRenderer
10
- } from '../../src';
11
-
12
- const MaterialEnumArrayRendererRegistration = {
13
- tester: materialEnumArrayRendererTester,
14
- renderer: MaterialEnumArrayRenderer
15
- };
16
- const data = ['bar'];
17
- const oneOfSchema = {
18
- type: 'array',
19
- items: {
20
- oneOf: [
21
- {
22
- const: 'foo',
23
- title: 'My Title'
24
- },
25
- {
26
- const: 'bar'
27
- }
28
- ]
29
- },
30
- uniqueItems: true
31
- };
32
-
33
- const enumSchema = {
34
- type: 'array',
35
- items: {
36
- type: 'string',
37
- enum: ['a', 'b', 'c']
38
- },
39
- uniqueItems: true
40
- };
41
- const uischema: ControlElement = {
42
- type: 'Control',
43
- scope: '#'
44
- };
45
-
46
- Enzyme.configure({ adapter: new Adapter() });
47
-
48
- describe('EnumArrayControl tester', () => {
49
- test('should fail', () => {
50
- expect(
51
- materialEnumArrayRendererTester(uischema, {
52
- type: 'array',
53
- items: {}
54
- },
55
- undefined)
56
- ).toBe(NOT_APPLICABLE);
57
- expect(
58
- materialEnumArrayRendererTester(uischema, {
59
- type: 'array',
60
- items: {
61
- anyOf: []
62
- }
63
- },
64
- undefined)
65
- ).toBe(NOT_APPLICABLE);
66
- });
67
-
68
- it('should succeed for schema with enum items', () => {
69
- expect(materialEnumArrayRendererTester(uischema, enumSchema, undefined)).toBe(5);
70
- });
71
- });
72
-
73
- describe('EnumArrayControl', () => {
74
- let wrapper: ReactWrapper;
75
-
76
- afterEach(() => {
77
- wrapper.unmount();
78
- });
79
-
80
- test('oneOf items - renders', () => {
81
- wrapper = mount(
82
- <JsonForms
83
- schema={oneOfSchema}
84
- uischema={uischema}
85
- data={undefined}
86
- renderers={[MaterialEnumArrayRendererRegistration]}
87
- />
88
- );
89
- const inputs = wrapper.find('input');
90
- expect(inputs).toHaveLength(2);
91
- });
92
-
93
- test('oneOf items - renders with data', () => {
94
- wrapper = mount(
95
- <JsonForms
96
- schema={oneOfSchema}
97
- uischema={uischema}
98
- data={data}
99
- renderers={[MaterialEnumArrayRendererRegistration]}
100
- />
101
- );
102
- const inputs = wrapper.find('input');
103
- expect(inputs.first().props().checked).toBeFalsy();
104
- expect(inputs.last().props().checked).toBeTruthy();
105
- });
106
-
107
- test('oneOf items - renders labels for options', () => {
108
- wrapper = mount(
109
- <JsonForms
110
- schema={oneOfSchema}
111
- uischema={uischema}
112
- data={data}
113
- renderers={[MaterialEnumArrayRendererRegistration]}
114
- />
115
- );
116
- const labels = wrapper.find('label');
117
- expect(labels.first().text()).toBe('My Title');
118
- expect(labels.last().text()).toBe('bar');
119
- });
120
-
121
- test('oneOf items - updates data', (done) => {
122
- let myData: any = undefined;
123
- wrapper = mount(
124
- <JsonForms
125
- schema={oneOfSchema}
126
- uischema={uischema}
127
- data={myData}
128
- renderers={[MaterialEnumArrayRendererRegistration]}
129
- onChange={({ data }) => {
130
- myData = data;
131
- }}
132
- />
133
- );
134
- const input = wrapper.find('input').first();
135
- input.simulate('change', { target: { checked: true } });
136
- // events are debounced for some time, so let's wait
137
- setTimeout(() => {
138
- expect(myData).toStrictEqual(['foo']);
139
- done();
140
- }, 50);
141
- });
142
-
143
- test('enum items - renders', () => {
144
- wrapper = mount(
145
- <JsonForms
146
- schema={enumSchema}
147
- uischema={uischema}
148
- data={undefined}
149
- renderers={[MaterialEnumArrayRendererRegistration]}
150
- />
151
- );
152
- const inputs = wrapper.find('input');
153
- expect(inputs).toHaveLength(3);
154
- });
155
-
156
- test('enum items - renders with data', () => {
157
- wrapper = mount(
158
- <JsonForms
159
- schema={enumSchema}
160
- uischema={uischema}
161
- data={['b']}
162
- renderers={[MaterialEnumArrayRendererRegistration]}
163
- />
164
- );
165
- const inputs = wrapper.find('input');
166
- expect(inputs.at(0).props().checked).toBeFalsy();
167
- expect(inputs.at(1).props().checked).toBeTruthy();
168
- expect(inputs.at(2).props().checked).toBeFalsy();
169
- });
170
-
171
- test('enum items - renders labels for options', () => {
172
- wrapper = mount(
173
- <JsonForms
174
- schema={enumSchema}
175
- uischema={uischema}
176
- data={['b']}
177
- renderers={[MaterialEnumArrayRendererRegistration]}
178
- />
179
- );
180
- const labels = wrapper.find('label');
181
- expect(labels.at(0).text()).toBe('a');
182
- expect(labels.at(1).text()).toBe('b');
183
- expect(labels.at(2).text()).toBe('c');
184
- });
185
-
186
- test('enum items - updates data', (done) => {
187
- let myData: any = undefined;
188
- wrapper = mount(
189
- <JsonForms
190
- schema={enumSchema}
191
- uischema={uischema}
192
- data={myData}
193
- renderers={[MaterialEnumArrayRendererRegistration]}
194
- onChange={({ data }) => {
195
- myData = data;
196
- }}
197
- />
198
- );
199
- const input = wrapper.find('input').first();
200
- input.simulate('change', { target: { checked: true } });
201
- // events are debounced for some time, so let's wait
202
- setTimeout(() => {
203
- expect(myData).toStrictEqual(['a']);
204
- done();
205
- }, 50);
206
- });
207
- });
@@ -1,88 +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
- } from '@jsonforms/core';
30
- import MaterialEnumCell, {
31
- materialEnumCellTester
32
- } from '../../src/cells/MaterialEnumCell';
33
- import { materialRenderers } from '../../src';
34
-
35
- import Enzyme, { mount } from 'enzyme';
36
- import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
37
- import { JsonFormsStateProvider } from '@jsonforms/react';
38
- import { initCore } from './util';
39
-
40
- Enzyme.configure({ adapter: new Adapter() });
41
-
42
- const data = { nationality: 'JP' };
43
- const schema = {
44
- type: 'string',
45
- enum: ['DE', 'IT', 'JP', 'US', 'RU', 'Other']
46
- };
47
- const uischema: ControlElement = {
48
- type: 'Control',
49
- scope: '#/properties/nationality'
50
- };
51
-
52
- describe('Material enum cell tester', () => {
53
- it('should succeed with matching prop type', () => {
54
- const control: ControlElement = {
55
- type: 'Control',
56
- scope: '#/properties/nationality'
57
- };
58
- expect(
59
- materialEnumCellTester(control, {
60
- type: 'object',
61
- properties: {
62
- nationality: {
63
- type: 'string',
64
- enum: ['DE', 'IT', 'JP', 'US', 'RU', 'Other']
65
- }
66
- }
67
- },
68
- undefined)
69
- ).toBe(2);
70
- });
71
- });
72
-
73
- describe('Material enum cell', () => {
74
- it('should select an item from dropdown list', () => {
75
- const core = initCore(schema, uischema, data);
76
- const wrapper = mount(
77
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
78
- <MaterialEnumCell
79
- schema={schema}
80
- uischema={uischema}
81
- path='nationality'
82
- />
83
- </JsonFormsStateProvider>
84
- );
85
- const input = wrapper.find('input');
86
- expect(input.props().value).toBe('JP');
87
- });
88
- });