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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/README.md +16 -17
  2. package/lib/additional/ListWithDetailMasterItem.d.ts +2 -0
  3. package/lib/additional/MaterialListWithDetailRenderer.d.ts +1 -1
  4. package/lib/additional/index.d.ts +2 -2
  5. package/lib/additional/unwrapped.d.ts +5 -0
  6. package/lib/cells/index.d.ts +1 -1
  7. package/lib/complex/CombinatorProperties.d.ts +1 -2
  8. package/lib/complex/DeleteDialog.d.ts +5 -1
  9. package/lib/complex/MaterialAllOfRenderer.d.ts +1 -1
  10. package/lib/complex/MaterialAnyOfRenderer.d.ts +1 -1
  11. package/lib/complex/MaterialArrayControlRenderer.d.ts +2 -1
  12. package/lib/complex/MaterialEnumArrayRenderer.d.ts +1 -1
  13. package/lib/complex/MaterialObjectRenderer.d.ts +1 -1
  14. package/lib/complex/MaterialOneOfRenderer.d.ts +1 -1
  15. package/lib/complex/MaterialTableControl.d.ts +4 -2
  16. package/lib/complex/NoBorderTableCell.d.ts +2 -2
  17. package/lib/complex/TableToolbar.d.ts +3 -2
  18. package/lib/complex/index.d.ts +11 -16
  19. package/lib/complex/unwrapped.d.ts +9 -0
  20. package/lib/controls/MaterialBooleanControl.d.ts +1 -1
  21. package/lib/controls/MaterialBooleanToggleControl.d.ts +1 -1
  22. package/lib/controls/index.d.ts +8 -26
  23. package/lib/controls/unwrapped.d.ts +19 -0
  24. package/lib/index.d.ts +34 -1
  25. package/lib/jsonforms-react-material.cjs.js +731 -572
  26. package/lib/jsonforms-react-material.cjs.js.map +1 -1
  27. package/lib/jsonforms-react-material.esm.js +648 -517
  28. package/lib/jsonforms-react-material.esm.js.map +1 -1
  29. package/lib/layouts/ArrayToolbar.d.ts +3 -1
  30. package/lib/layouts/ExpandPanelRenderer.d.ts +3 -1
  31. package/lib/layouts/MaterialGroupLayout.d.ts +1 -1
  32. package/lib/layouts/MaterialHorizontalLayout.d.ts +1 -1
  33. package/lib/layouts/MaterialVerticalLayout.d.ts +1 -1
  34. package/lib/layouts/index.d.ts +3 -1
  35. package/lib/layouts/unwrapped.d.ts +10 -0
  36. package/lib/mui-controls/MuiCheckbox.d.ts +6 -1
  37. package/lib/mui-controls/MuiInputInteger.d.ts +1 -1
  38. package/lib/mui-controls/MuiInputNumber.d.ts +1 -1
  39. package/lib/mui-controls/MuiInputNumberFormat.d.ts +1 -1
  40. package/lib/mui-controls/MuiInputText.d.ts +1 -1
  41. package/lib/mui-controls/MuiInputTime.d.ts +1 -1
  42. package/lib/mui-controls/MuiSelect.d.ts +1 -1
  43. package/lib/mui-controls/MuiToggle.d.ts +6 -1
  44. package/lib/mui-controls/index.d.ts +3 -1
  45. package/lib/util/layout.d.ts +2 -3
  46. package/package.json +33 -15
  47. package/src/additional/ListWithDetailMasterItem.tsx +32 -24
  48. package/src/additional/MaterialLabelRenderer.tsx +8 -15
  49. package/src/additional/MaterialListWithDetailRenderer.tsx +8 -5
  50. package/src/additional/index.ts +12 -4
  51. package/{example/index.ts → src/additional/unwrapped.ts} +7 -6
  52. package/src/cells/MaterialBooleanCell.tsx +1 -1
  53. package/src/cells/MaterialBooleanToggleCell.tsx +2 -2
  54. package/src/cells/MaterialDateCell.tsx +4 -12
  55. package/src/cells/MaterialEnumCell.tsx +13 -6
  56. package/src/cells/MaterialIntegerCell.tsx +1 -1
  57. package/src/cells/MaterialNumberCell.tsx +1 -1
  58. package/src/cells/MaterialNumberFormatCell.tsx +1 -1
  59. package/src/cells/MaterialOneOfEnumCell.tsx +17 -7
  60. package/src/cells/MaterialTextCell.tsx +1 -1
  61. package/src/cells/MaterialTimeCell.tsx +1 -1
  62. package/src/cells/index.ts +7 -7
  63. package/src/complex/CombinatorProperties.tsx +20 -9
  64. package/src/complex/DeleteDialog.tsx +48 -37
  65. package/src/complex/MaterialAllOfRenderer.tsx +2 -2
  66. package/src/complex/MaterialAnyOfRenderer.tsx +3 -3
  67. package/src/complex/MaterialArrayControlRenderer.tsx +27 -11
  68. package/src/complex/MaterialEnumArrayRenderer.tsx +6 -8
  69. package/src/complex/MaterialObjectRenderer.tsx +6 -3
  70. package/src/complex/MaterialOneOfRenderer.tsx +105 -88
  71. package/src/complex/MaterialTableControl.tsx +145 -97
  72. package/src/complex/NoBorderTableCell.tsx +3 -5
  73. package/src/complex/TableToolbar.tsx +24 -25
  74. package/src/complex/ValidationIcon.tsx +10 -18
  75. package/src/complex/index.ts +35 -32
  76. package/{test/renderers/MatchMediaMock.ts → src/complex/unwrapped.ts} +19 -16
  77. package/src/controls/MaterialAnyOfStringOrEnumControl.tsx +19 -11
  78. package/src/controls/MaterialBooleanControl.tsx +90 -23
  79. package/src/controls/MaterialBooleanToggleControl.tsx +90 -23
  80. package/src/controls/MaterialDateControl.tsx +16 -19
  81. package/src/controls/MaterialDateTimeControl.tsx +24 -23
  82. package/src/controls/MaterialEnumControl.tsx +21 -15
  83. package/src/controls/MaterialInputControl.tsx +7 -8
  84. package/src/controls/MaterialIntegerControl.tsx +1 -1
  85. package/src/controls/MaterialNativeControl.tsx +12 -9
  86. package/src/controls/MaterialNumberControl.tsx +1 -1
  87. package/src/controls/MaterialOneOfEnumControl.tsx +21 -15
  88. package/src/controls/MaterialOneOfRadioGroupControl.tsx +5 -3
  89. package/src/controls/MaterialRadioGroup.tsx +11 -17
  90. package/src/controls/MaterialRadioGroupControl.tsx +8 -3
  91. package/src/controls/MaterialSliderControl.tsx +17 -16
  92. package/src/controls/MaterialTextControl.tsx +1 -1
  93. package/src/controls/MaterialTimeControl.tsx +19 -22
  94. package/src/controls/index.ts +36 -72
  95. package/src/controls/unwrapped.ts +57 -0
  96. package/src/index.ts +41 -22
  97. package/src/layouts/ArrayToolbar.tsx +38 -42
  98. package/src/layouts/ExpandPanelRenderer.tsx +96 -67
  99. package/src/layouts/MaterialArrayLayout.tsx +21 -16
  100. package/src/layouts/MaterialArrayLayoutRenderer.tsx +6 -9
  101. package/src/layouts/MaterialCategorizationLayout.tsx +52 -21
  102. package/src/layouts/MaterialCategorizationStepperLayout.tsx +60 -44
  103. package/src/layouts/MaterialGroupLayout.tsx +25 -6
  104. package/src/layouts/MaterialHorizontalLayout.tsx +18 -4
  105. package/src/layouts/MaterialVerticalLayout.tsx +18 -4
  106. package/src/layouts/index.ts +18 -7
  107. package/{test/renderers/util.ts → src/layouts/unwrapped.ts} +19 -28
  108. package/src/mui-controls/MuiAutocomplete.tsx +51 -35
  109. package/src/mui-controls/MuiCheckbox.tsx +14 -5
  110. package/src/mui-controls/MuiInputInteger.tsx +31 -32
  111. package/src/mui-controls/MuiInputNumber.tsx +16 -16
  112. package/src/mui-controls/MuiInputNumberFormat.tsx +51 -42
  113. package/src/mui-controls/MuiInputText.tsx +30 -19
  114. package/src/mui-controls/MuiInputTime.tsx +11 -12
  115. package/src/mui-controls/MuiSelect.tsx +15 -6
  116. package/src/mui-controls/MuiToggle.tsx +14 -5
  117. package/src/mui-controls/index.ts +3 -1
  118. package/src/util/datejs.tsx +41 -20
  119. package/src/util/debounce.ts +26 -11
  120. package/src/util/focus.ts +7 -7
  121. package/src/util/i18nDefaults.ts +2 -2
  122. package/src/util/layout.tsx +47 -42
  123. package/src/util/theme.ts +2 -2
  124. package/docs/assets/css/main.css +0 -1
  125. package/docs/assets/images/icons.png +0 -0
  126. package/docs/assets/images/icons@2x.png +0 -0
  127. package/docs/assets/images/widgets.png +0 -0
  128. package/docs/assets/images/widgets@2x.png +0 -0
  129. package/docs/assets/js/main.js +0 -51
  130. package/docs/assets/js/search.json +0 -1
  131. package/docs/classes/combinatorproperties.html +0 -957
  132. package/docs/classes/materialanyofstringorenumcontrol.html +0 -822
  133. package/docs/classes/materialtablecontrol.html +0 -999
  134. package/docs/globals.html +0 -4492
  135. package/docs/index.html +0 -753
  136. package/docs/interfaces/ajvprops.html +0 -162
  137. package/docs/interfaces/arraylayouttoolbarprops.html +0 -253
  138. package/docs/interfaces/categorizationstate.html +0 -154
  139. package/docs/interfaces/categorizationstepperstate.html +0 -154
  140. package/docs/interfaces/combinatorpropertiesprops.html +0 -182
  141. package/docs/interfaces/deletedialogprops.html +0 -225
  142. package/docs/interfaces/dispatchpropsofexpandpanel.html +0 -296
  143. package/docs/interfaces/emptytableprops.html +0 -154
  144. package/docs/interfaces/expandpanelprops.html +0 -594
  145. package/docs/interfaces/inputref.html +0 -168
  146. package/docs/interfaces/jsonformstheme.html +0 -352
  147. package/docs/interfaces/materialcategorizationlayoutrendererprops.html +0 -460
  148. package/docs/interfaces/materialcategorizationstepperlayoutrendererprops.html +0 -394
  149. package/docs/interfaces/materiallabelablelayoutrendererprops.html +0 -328
  150. package/docs/interfaces/materiallayoutrendererprops.html +0 -317
  151. package/docs/interfaces/materialtabletoolbarprops.html +0 -302
  152. package/docs/interfaces/muitextinputprops.html +0 -168
  153. package/docs/interfaces/nonemptycellcomponentprops.html +0 -266
  154. package/docs/interfaces/nonemptycellprops.html +0 -277
  155. package/docs/interfaces/nonemptyrowprops.html +0 -366
  156. package/docs/interfaces/ownoneofprops.html +0 -308
  157. package/docs/interfaces/ownpropsofexpandpanel.html +0 -397
  158. package/docs/interfaces/ownpropsofnonemptycell.html +0 -229
  159. package/docs/interfaces/statepropsofexpandpanel.html +0 -445
  160. package/docs/interfaces/tableheadercellprops.html +0 -154
  161. package/docs/interfaces/tablerowsprop.html +0 -330
  162. package/docs/interfaces/validationprops.html +0 -168
  163. package/docs/interfaces/withdeletedialogsupport.html +0 -170
  164. package/docs/interfaces/withinput.html +0 -154
  165. package/docs/interfaces/withoptionlabel.html +0 -230
  166. package/example/index.html +0 -16
  167. package/rollup.config.js +0 -51
  168. package/stats.html +0 -3279
  169. package/test/renderers/MaterialAllOfRenderer.test.tsx +0 -114
  170. package/test/renderers/MaterialAnyOfRenderer.test.tsx +0 -310
  171. package/test/renderers/MaterialAnyOfStringOrEnumControl.test.tsx +0 -126
  172. package/test/renderers/MaterialArrayControl.test.tsx +0 -633
  173. package/test/renderers/MaterialArrayLayout.test.tsx +0 -528
  174. package/test/renderers/MaterialBooleanCell.test.tsx +0 -374
  175. package/test/renderers/MaterialBooleanToggleCell.test.tsx +0 -466
  176. package/test/renderers/MaterialBooleanToggleControl.test.tsx +0 -469
  177. package/test/renderers/MaterialCategorizationLayout.test.tsx +0 -458
  178. package/test/renderers/MaterialCategorizationStepperLayout.test.tsx +0 -647
  179. package/test/renderers/MaterialDateCell.test.tsx +0 -303
  180. package/test/renderers/MaterialDateControl.test.tsx +0 -411
  181. package/test/renderers/MaterialDateTimeControl.test.tsx +0 -417
  182. package/test/renderers/MaterialEnumArrayRenderer.test.tsx +0 -207
  183. package/test/renderers/MaterialEnumCell.test.tsx +0 -88
  184. package/test/renderers/MaterialEnumControl.test.tsx +0 -75
  185. package/test/renderers/MaterialGroupLayout.test.tsx +0 -90
  186. package/test/renderers/MaterialInputControl.test.tsx +0 -370
  187. package/test/renderers/MaterialIntegerCell.test.tsx +0 -333
  188. package/test/renderers/MaterialLabelRenderer.test.tsx +0 -114
  189. package/test/renderers/MaterialLayouts.test.tsx +0 -542
  190. package/test/renderers/MaterialListWithDetailRenderer.test.tsx +0 -279
  191. package/test/renderers/MaterialNativeControl.test.tsx +0 -81
  192. package/test/renderers/MaterialNumberCell.test.tsx +0 -382
  193. package/test/renderers/MaterialObjectControl.test.tsx +0 -186
  194. package/test/renderers/MaterialOneOfEnumCell.test.tsx +0 -94
  195. package/test/renderers/MaterialOneOfRadioGroupControl.test.tsx +0 -108
  196. package/test/renderers/MaterialOneOfRenderer.test.tsx +0 -603
  197. package/test/renderers/MaterialRadioGroupControl.test.tsx +0 -125
  198. package/test/renderers/MaterialSliderControl.test.tsx +0 -438
  199. package/test/renderers/MaterialTextCell.test.tsx +0 -541
  200. package/test/renderers/MaterialTextControl.test.tsx +0 -115
  201. package/test/renderers/MaterialTimeCell.test.tsx +0 -331
  202. package/test/renderers/MaterialTimeControl.test.tsx +0 -411
  203. package/tsconfig.json +0 -13
  204. package/tsconfig.test.json +0 -7
  205. 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
- });