@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,541 +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
- JsonSchema,
30
- NOT_APPLICABLE
31
- } from '@jsonforms/core';
32
- import TextCell, {
33
- materialTextCellTester
34
- } from '../../src/cells/MaterialTextCell';
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 DEFAULT_MAX_LENGTH = 524288;
45
- const DEFAULT_SIZE = 20;
46
-
47
- const data = { name: 'Foo' };
48
- const minLengthSchema = {
49
- type: 'string',
50
- minLength: 3
51
- };
52
- const maxLengthSchema = {
53
- type: 'string',
54
- maxLength: 5
55
- };
56
- const schema = { type: 'string' };
57
-
58
- const uischema: ControlElement = {
59
- type: 'Control',
60
- scope: '#/properties/name'
61
- };
62
-
63
- describe('Material text cell tester', () => {
64
- it('should fail', () => {
65
- expect(materialTextCellTester(undefined, undefined, undefined)).toBe(NOT_APPLICABLE);
66
- expect(materialTextCellTester(null, undefined, undefined)).toBe(NOT_APPLICABLE);
67
- expect(materialTextCellTester({ type: 'Foo' }, undefined, undefined)).toBe(
68
- NOT_APPLICABLE
69
- );
70
- expect(materialTextCellTester({ type: 'Control' }, undefined, undefined)).toBe(
71
- NOT_APPLICABLE
72
- );
73
- });
74
- it('should fail with wrong schema type', () => {
75
- const control: ControlElement = {
76
- type: 'Control',
77
- scope: '#/properties/foo'
78
- };
79
- expect(
80
- materialTextCellTester(control, {
81
- type: 'object',
82
- properties: {
83
- foo: {
84
- type: 'number'
85
- }
86
- }
87
- },
88
- undefined)
89
- ).toBe(NOT_APPLICABLE);
90
- });
91
-
92
- it('should fail if only sibling has correct type', () => {
93
- const control: ControlElement = {
94
- type: 'Control',
95
- scope: '#/properties/foo'
96
- };
97
- expect(
98
- materialTextCellTester(control, {
99
- type: 'object',
100
- properties: {
101
- foo: {
102
- type: 'number'
103
- },
104
- bar: {
105
- type: 'string'
106
- }
107
- }
108
- },
109
- undefined)
110
- ).toBe(NOT_APPLICABLE);
111
- });
112
-
113
- it('should succeed with matching prop type', () => {
114
- const control: ControlElement = {
115
- type: 'Control',
116
- scope: '#/properties/foo'
117
- };
118
- expect(
119
- materialTextCellTester(control, {
120
- type: 'object',
121
- properties: {
122
- foo: {
123
- type: 'string'
124
- }
125
- }
126
- },
127
- undefined)
128
- ).toBe(1);
129
- });
130
- });
131
-
132
- describe('Material text cell', () => {
133
- let wrapper: ReactWrapper;
134
-
135
- afterEach(() => wrapper.unmount());
136
-
137
- it('should autofocus via option', () => {
138
- const control: ControlElement = {
139
- type: 'Control',
140
- scope: '#/properties/name',
141
- options: { focus: true }
142
- };
143
- const core = initCore(minLengthSchema, control, data);
144
- wrapper = mount(
145
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
146
- <TextCell schema={minLengthSchema} uischema={control} path='name' />
147
- </JsonFormsStateProvider>
148
- );
149
- const input = wrapper.find('input').first();
150
- expect(input.props().autoFocus).toBeTruthy();
151
- });
152
-
153
- it('should not autofocus via option', () => {
154
- const control: ControlElement = {
155
- type: 'Control',
156
- scope: '#/properties/name',
157
- options: { focus: false }
158
- };
159
- const core = initCore(schema, control, data);
160
- wrapper = mount(
161
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
162
- <TextCell schema={minLengthSchema} uischema={control} path={'name'} />
163
- </JsonFormsStateProvider>
164
- );
165
- const input = wrapper.find('input').first();
166
- expect(input.props().autoFocus).toBeFalsy();
167
- });
168
-
169
- it('should not autofocus by default', () => {
170
- const control: ControlElement = {
171
- type: 'Control',
172
- scope: '#/properties/name'
173
- };
174
- const core = initCore(minLengthSchema, control, data);
175
- wrapper = mount(
176
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
177
- <TextCell schema={minLengthSchema} uischema={control} path='name' />
178
- </JsonFormsStateProvider>
179
- );
180
- const input = wrapper.find('input').first();
181
- expect(document.activeElement).not.toBe(input);
182
- });
183
-
184
- it('should render', () => {
185
- const jsonSchema: JsonSchema = {
186
- type: 'object',
187
- properties: {
188
- name: { type: 'string' }
189
- }
190
- };
191
- const core = initCore(minLengthSchema, uischema, { name: 'Foo' });
192
- wrapper = mount(
193
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
194
- <TextCell schema={jsonSchema} uischema={uischema} path={'name'} />
195
- </JsonFormsStateProvider>
196
- );
197
-
198
- const input = wrapper.find('input').first();
199
- expect(input.props().value).toBe('Foo');
200
- });
201
-
202
- it('should update via input event', (done) => {
203
- const core = initCore(minLengthSchema, uischema, data);
204
- const onChangeData: any = {
205
- data: undefined
206
- };
207
- wrapper = mount(
208
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
209
- <TestEmitter
210
- onChange={({ data }) => {
211
- onChangeData.data = data;
212
- }}
213
- />
214
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
215
- </JsonFormsStateProvider>
216
- );
217
-
218
- const input = wrapper.find('input').first();
219
- input.simulate('change', { target: { value: 'Bar' } });
220
- setTimeout(() => {
221
- expect(onChangeData.data.name).toBe('Bar');
222
- done();
223
- }, 1000);
224
- });
225
-
226
- it('should update via action', (done) => {
227
- const core = initCore(minLengthSchema, uischema, data);
228
- wrapper = mount(
229
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
230
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
231
- </JsonFormsStateProvider>
232
- );
233
- core.data = { ...core.data, name: 'Bar' };
234
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
235
- wrapper.update();
236
- setTimeout(() => {
237
- const input = wrapper.find('input').first();
238
- expect(input.props().value).toBe('Bar');
239
- done();
240
- }, 1000);
241
- });
242
-
243
- it('should update with undefined value', (done) => {
244
- const core = initCore(minLengthSchema, uischema, data);
245
- wrapper = mount(
246
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
247
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
248
- </JsonFormsStateProvider>
249
- );
250
- core.data = { ...core.data, name: undefined };
251
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
252
- wrapper.update();
253
- setTimeout(() => {
254
- const input = wrapper.find('input').first();
255
- expect(input.props().value).toBe('');
256
- done();
257
- }, 1000);
258
- });
259
-
260
- it('should update with null value', (done) => {
261
- const core = initCore(minLengthSchema, uischema, data);
262
- wrapper = mount(
263
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
264
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
265
- </JsonFormsStateProvider>
266
- );
267
- core.data = { ...core.data, name: null };
268
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
269
- wrapper.update();
270
- setTimeout(() => {
271
- const input = wrapper.find('input').first();
272
- expect(input.props().value).toBe('');
273
- done();
274
- }, 1000);
275
- });
276
-
277
- it('should not update if wrong ref', (done) => {
278
- const core = initCore(minLengthSchema, uischema, data);
279
- wrapper = mount(
280
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
281
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
282
- </JsonFormsStateProvider>
283
- );
284
- core.data = { ...core.data, firstname: 'Bar' };
285
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
286
- wrapper.update();
287
- setTimeout(() => {
288
- const input = wrapper.find('input').first();
289
- expect(input.props().value).toBe('Foo');
290
- done();
291
- }, 1000);
292
- });
293
-
294
- it('should not update if null ref', (done) => {
295
- const core = initCore(minLengthSchema, uischema, data);
296
- wrapper = mount(
297
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
298
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
299
- </JsonFormsStateProvider>
300
- );
301
- core.data = { ...core.data, null: 'Bar' };
302
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
303
- wrapper.update();
304
- setTimeout(() => {
305
- const input = wrapper.find('input').first();
306
- expect(input.props().value).toBe('Foo');
307
- done();
308
- }, 1000);
309
- });
310
-
311
- it('should not update if undefined ref', (done) => {
312
- const core = initCore(minLengthSchema, uischema, data);
313
- wrapper = mount(
314
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
315
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
316
- </JsonFormsStateProvider>
317
- );
318
- core.data = { ...core.data, undefined: 'Bar' };
319
- wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
320
- wrapper.update();
321
- setTimeout(() => {
322
- const input = wrapper.find('input').first();
323
- expect(input.props().value).toBe('Foo');
324
- done();
325
- }, 1000);
326
- });
327
-
328
- it('can be disabled', () => {
329
- const core = initCore(minLengthSchema, uischema, data);
330
- wrapper = mount(
331
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
332
- <TextCell
333
- schema={minLengthSchema}
334
- uischema={uischema}
335
- path='name'
336
- enabled={false}
337
- />
338
- </JsonFormsStateProvider>
339
- );
340
- const input = wrapper.find('input').first();
341
- expect(input.props().disabled).toBeTruthy();
342
- });
343
-
344
- it('should be enabled by default', () => {
345
- const core = initCore(minLengthSchema, uischema, data);
346
- wrapper = mount(
347
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
348
- <TextCell schema={minLengthSchema} uischema={uischema} path='name' />
349
- </JsonFormsStateProvider>
350
- );
351
- const input = wrapper.find('input').first();
352
- expect(input.props().disabled).toBeFalsy();
353
- });
354
-
355
- it('should use maxLength for size and maxlength attributes', () => {
356
- const control: ControlElement = {
357
- type: 'Control',
358
- scope: '#/properties/name',
359
- options: {
360
- trim: true,
361
- restrict: true
362
- }
363
- };
364
- const core = initCore(maxLengthSchema, control, data);
365
- wrapper = mount(
366
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
367
- <TextCell schema={maxLengthSchema} uischema={control} path='name' />
368
- </JsonFormsStateProvider>
369
- );
370
- const input = wrapper.find('input').first();
371
- expect(input.props().maxLength).toBe(5);
372
- expect(input.parent().props().width).not.toBe('100%');
373
- expect(input.props().size).toBe(5);
374
- });
375
-
376
- it('should use maxLength for size attribute', () => {
377
- const control: ControlElement = {
378
- type: 'Control',
379
- scope: '#/properties/name',
380
- options: { trim: true }
381
- };
382
- const core = initCore(maxLengthSchema, control, data);
383
- wrapper = mount(
384
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
385
- <TextCell schema={maxLengthSchema} uischema={control} path='name' />
386
- </JsonFormsStateProvider>
387
- );
388
- const input = wrapper
389
- .find('input')
390
- .first()
391
- .getDOMNode() as HTMLInputElement;
392
- expect(input.maxLength).toBe(DEFAULT_MAX_LENGTH);
393
- expect(
394
- getComputedStyle(input.parentElement, null).getPropertyValue('width')
395
- ).not.toBe('100%');
396
- expect(input.size).toBe(5);
397
- });
398
-
399
- it('should use maxLength for maxlength attribute', () => {
400
- const control: ControlElement = {
401
- type: 'Control',
402
- scope: '#/properties/name',
403
- options: { restrict: true }
404
- };
405
- const core = initCore(maxLengthSchema, control, data);
406
- wrapper = mount(
407
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
408
- <TextCell schema={maxLengthSchema} uischema={control} path='name' />
409
- </JsonFormsStateProvider>
410
- );
411
- const input = wrapper
412
- .find('input')
413
- .first()
414
- .getDOMNode() as HTMLInputElement;
415
- expect(input.maxLength).toBe(5);
416
- expect(
417
- getComputedStyle(input.parentElement, null).getPropertyValue('width')
418
- ).toBe('100%');
419
- expect(input.size).toBe(DEFAULT_SIZE);
420
- });
421
-
422
- it('should not use maxLength by default', () => {
423
- const core = initCore(maxLengthSchema, uischema, data);
424
- wrapper = mount(
425
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
426
- <TextCell schema={schema} uischema={uischema} path='name' />
427
- </JsonFormsStateProvider>
428
- );
429
- const input = wrapper
430
- .find('input')
431
- .first()
432
- .getDOMNode() as HTMLInputElement;
433
- expect(input.maxLength).toBe(DEFAULT_MAX_LENGTH);
434
- expect(
435
- getComputedStyle(input.parentElement, null).getPropertyValue('width')
436
- ).toBe('100%');
437
- expect(input.size).toBe(DEFAULT_SIZE);
438
- });
439
-
440
- it('should have default values for trim and restrict', () => {
441
- const control: ControlElement = {
442
- type: 'Control',
443
- scope: '#/properties/name',
444
- options: {
445
- trim: true,
446
- restrict: true
447
- }
448
- };
449
- const core = initCore(schema, control, data);
450
- wrapper = mount(
451
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
452
- <TextCell schema={schema} uischema={control} path='name' />
453
- </JsonFormsStateProvider>
454
- );
455
- const input = wrapper
456
- .find('input')
457
- .first()
458
- .getDOMNode() as HTMLInputElement;
459
- expect(input.maxLength).toBe(DEFAULT_MAX_LENGTH);
460
-
461
- expect(input.parentElement.classList.contains('MuiInputBase-fullWidth')).toBeTruthy;
462
- expect(input.size).toBe(DEFAULT_SIZE);
463
- });
464
-
465
- it('should have a default value for trim', () => {
466
- const control: ControlElement = {
467
- type: 'Control',
468
- scope: '#/properties/name',
469
- options: { trim: true }
470
- };
471
- const core = initCore(schema, control, data);
472
- wrapper = mount(
473
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
474
- <TextCell schema={schema} uischema={control} path='name' />
475
- </JsonFormsStateProvider>
476
- );
477
-
478
- const input = wrapper
479
- .find('input')
480
- .first()
481
- .getDOMNode() as HTMLInputElement;
482
- expect(input.maxLength).toBe(DEFAULT_MAX_LENGTH);
483
- expect(input.parentElement.classList.contains('MuiInputBase-fullWidth')).toBeTruthy;
484
- expect(input.size).toBe(DEFAULT_SIZE);
485
- });
486
-
487
- it('should have default values for restrict', () => {
488
- const control: ControlElement = {
489
- type: 'Control',
490
- scope: '#/properties/name',
491
- options: { restrict: true }
492
- };
493
- const core = initCore(schema, control, data);
494
- wrapper = mount(
495
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
496
- <TextCell schema={schema} uischema={control} path='name' />
497
- </JsonFormsStateProvider>
498
- );
499
-
500
- const input = wrapper
501
- .find('input')
502
- .first()
503
- .getDOMNode() as HTMLInputElement;
504
- expect(input.maxLength).toBe(DEFAULT_MAX_LENGTH);
505
- expect(input.parentElement.classList.contains('MuiInputBase-fullWidth')).toBeTruthy;
506
- expect(input.size).toBe(DEFAULT_SIZE);
507
- });
508
-
509
- it('should have default values for attributes', () => {
510
- const core = initCore(schema, uischema, data);
511
- wrapper = mount(
512
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
513
- <TextCell schema={schema} uischema={uischema} path='name' />
514
- </JsonFormsStateProvider>
515
- );
516
- const input = wrapper
517
- .find('input')
518
- .first()
519
- .getDOMNode() as HTMLInputElement;
520
- expect(input.maxLength).toBe(DEFAULT_MAX_LENGTH);
521
- expect(input.parentElement.classList.contains('MuiInputBase-fullWidth')).toBeTruthy;
522
- expect(input.size).toBe(DEFAULT_SIZE);
523
- });
524
-
525
- it('should be disabled', () => {
526
- const core = initCore(minLengthSchema, uischema, data);
527
- wrapper = mount(
528
- <JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
529
- <TextCell
530
- schema={schema}
531
- uischema={uischema}
532
- path={'name'}
533
- enabled={false}
534
- />
535
- </JsonFormsStateProvider>
536
- );
537
-
538
- const input = wrapper.find('input').first();
539
- expect(input.props().disabled).toBe(true);
540
- });
541
- });
@@ -1,115 +0,0 @@
1
- /*
2
- The MIT License
3
-
4
- Copyright (c) 2018-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 Enzyme, { mount, ReactWrapper } from 'enzyme';
28
- import { MaterialTextControl } from '../../src/controls/MaterialTextControl';
29
- import { MaterialInputControl } from '../../src/controls/MaterialInputControl';
30
- import { MuiInputText } from '../../src/mui-controls/MuiInputText';
31
- import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
32
- import { ControlElement, ControlProps } from '@jsonforms/core';
33
- import { Input, InputAdornment } from '@mui/material';
34
-
35
- Enzyme.configure({ adapter: new Adapter() });
36
-
37
- const schema = {
38
- type: 'object',
39
- properties: {
40
- foo: {
41
- type: 'string'
42
- }
43
- }
44
- };
45
- const uischema: ControlElement = {
46
- type: 'Control',
47
- scope: '#/properties/foo'
48
- };
49
-
50
- const createMaterialTextControl = (props: ControlProps) => {
51
- return <MaterialTextControl {...props} />;
52
- };
53
-
54
- const defaultControlProps = (): ControlProps => {
55
- return {
56
- handleChange: () => {},
57
- enabled: true,
58
- visible: true,
59
- path: 'path',
60
- rootSchema: schema,
61
- schema: schema.properties.foo,
62
- uischema: uischema,
63
- label: 'Foo',
64
- id: 'foo-id',
65
- errors: '',
66
- data: ''
67
- };
68
- };
69
-
70
- describe('Material text control', () => {
71
- let wrapper: ReactWrapper;
72
-
73
- afterEach(() => {
74
- wrapper.unmount();
75
- });
76
-
77
- it('render', () => {
78
- const props = defaultControlProps();
79
- wrapper = mount(createMaterialTextControl(props));
80
- expect(wrapper.find(MaterialInputControl).props()).toEqual({
81
- ...props,
82
- input: MuiInputText
83
- });
84
-
85
- expect(wrapper.find('input').props().id).toEqual(`${props.id}-input`);
86
- });
87
-
88
- it('allows adding of mui input props', () => {
89
- const props = {
90
- ...defaultControlProps(),
91
- muiInputProps: { spellCheck: false }
92
- };
93
- wrapper = mount(createMaterialTextControl(props));
94
- expect(wrapper.find('input').props().spellCheck).toEqual(false);
95
- });
96
-
97
- it('shows clear button when data exists', () => {
98
- const props = defaultControlProps();
99
- wrapper = mount(createMaterialTextControl(props));
100
- // call onPointerEnter prop manually as the tests seem to ignore 'pointerenter' events, 'mouseover' events work however.
101
- wrapper.find(Input).props().onPointerEnter.call(this);
102
- wrapper.update();
103
- expect(wrapper.find(InputAdornment).props().style).not.toHaveProperty('display', 'none');
104
- });
105
-
106
- it('hides clear button when data is undefined', () => {
107
- const props = defaultControlProps();
108
- delete props.data;
109
- wrapper = mount(createMaterialTextControl(props));
110
- // call onPointerEnter prop manually as the tests seem to ignore 'pointerenter' events, 'mouseover' events work however.
111
- wrapper.find(Input).props().onPointerEnter.call(this);
112
- wrapper.update();
113
- expect(wrapper.find(InputAdornment).props().style).toHaveProperty('display', 'none');
114
- });
115
- });