@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.
- package/lib/controls/MaterialBooleanControl.d.ts +1 -1
- package/lib/controls/MaterialBooleanToggleControl.d.ts +1 -1
- package/lib/controls/index.d.ts +2 -2
- package/lib/jsonforms-react-material.cjs.js +79 -11
- package/lib/jsonforms-react-material.cjs.js.map +1 -1
- package/lib/jsonforms-react-material.esm.js +79 -11
- package/lib/jsonforms-react-material.esm.js.map +1 -1
- package/lib/mui-controls/MuiCheckbox.d.ts +6 -1
- package/lib/mui-controls/MuiToggle.d.ts +6 -1
- package/package.json +23 -12
- package/src/additional/ListWithDetailMasterItem.tsx +1 -1
- package/src/controls/MaterialBooleanControl.tsx +84 -23
- package/src/controls/MaterialBooleanToggleControl.tsx +84 -23
- package/src/mui-controls/MuiCheckbox.tsx +12 -5
- package/src/mui-controls/MuiToggle.tsx +12 -5
- package/docs/assets/css/main.css +0 -1
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -51
- package/docs/assets/js/search.json +0 -1
- package/docs/classes/combinatorproperties.html +0 -957
- package/docs/classes/materialanyofstringorenumcontrol.html +0 -822
- package/docs/classes/materialtablecontrol.html +0 -999
- package/docs/globals.html +0 -4492
- package/docs/index.html +0 -753
- package/docs/interfaces/ajvprops.html +0 -162
- package/docs/interfaces/arraylayouttoolbarprops.html +0 -253
- package/docs/interfaces/categorizationstate.html +0 -154
- package/docs/interfaces/categorizationstepperstate.html +0 -154
- package/docs/interfaces/combinatorpropertiesprops.html +0 -182
- package/docs/interfaces/deletedialogprops.html +0 -225
- package/docs/interfaces/dispatchpropsofexpandpanel.html +0 -296
- package/docs/interfaces/emptytableprops.html +0 -154
- package/docs/interfaces/expandpanelprops.html +0 -594
- package/docs/interfaces/inputref.html +0 -168
- package/docs/interfaces/jsonformstheme.html +0 -352
- package/docs/interfaces/materialcategorizationlayoutrendererprops.html +0 -460
- package/docs/interfaces/materialcategorizationstepperlayoutrendererprops.html +0 -394
- package/docs/interfaces/materiallabelablelayoutrendererprops.html +0 -328
- package/docs/interfaces/materiallayoutrendererprops.html +0 -317
- package/docs/interfaces/materialtabletoolbarprops.html +0 -302
- package/docs/interfaces/muitextinputprops.html +0 -168
- package/docs/interfaces/nonemptycellcomponentprops.html +0 -266
- package/docs/interfaces/nonemptycellprops.html +0 -277
- package/docs/interfaces/nonemptyrowprops.html +0 -366
- package/docs/interfaces/ownoneofprops.html +0 -308
- package/docs/interfaces/ownpropsofexpandpanel.html +0 -397
- package/docs/interfaces/ownpropsofnonemptycell.html +0 -229
- package/docs/interfaces/statepropsofexpandpanel.html +0 -445
- package/docs/interfaces/tableheadercellprops.html +0 -154
- package/docs/interfaces/tablerowsprop.html +0 -330
- package/docs/interfaces/validationprops.html +0 -168
- package/docs/interfaces/withdeletedialogsupport.html +0 -170
- package/docs/interfaces/withinput.html +0 -154
- package/docs/interfaces/withoptionlabel.html +0 -230
- package/example/index.html +0 -16
- package/example/index.ts +0 -31
- package/rollup.config.js +0 -51
- package/stats.html +0 -3279
- package/test/renderers/MatchMediaMock.ts +0 -36
- package/test/renderers/MaterialAllOfRenderer.test.tsx +0 -114
- package/test/renderers/MaterialAnyOfRenderer.test.tsx +0 -310
- package/test/renderers/MaterialAnyOfStringOrEnumControl.test.tsx +0 -126
- package/test/renderers/MaterialArrayControl.test.tsx +0 -633
- package/test/renderers/MaterialArrayLayout.test.tsx +0 -528
- package/test/renderers/MaterialBooleanCell.test.tsx +0 -374
- package/test/renderers/MaterialBooleanToggleCell.test.tsx +0 -466
- package/test/renderers/MaterialBooleanToggleControl.test.tsx +0 -469
- package/test/renderers/MaterialCategorizationLayout.test.tsx +0 -458
- package/test/renderers/MaterialCategorizationStepperLayout.test.tsx +0 -647
- package/test/renderers/MaterialDateCell.test.tsx +0 -303
- package/test/renderers/MaterialDateControl.test.tsx +0 -411
- package/test/renderers/MaterialDateTimeControl.test.tsx +0 -417
- package/test/renderers/MaterialEnumArrayRenderer.test.tsx +0 -207
- package/test/renderers/MaterialEnumCell.test.tsx +0 -88
- package/test/renderers/MaterialEnumControl.test.tsx +0 -75
- package/test/renderers/MaterialGroupLayout.test.tsx +0 -90
- package/test/renderers/MaterialInputControl.test.tsx +0 -370
- package/test/renderers/MaterialIntegerCell.test.tsx +0 -333
- package/test/renderers/MaterialLabelRenderer.test.tsx +0 -114
- package/test/renderers/MaterialLayouts.test.tsx +0 -542
- package/test/renderers/MaterialListWithDetailRenderer.test.tsx +0 -279
- package/test/renderers/MaterialNativeControl.test.tsx +0 -81
- package/test/renderers/MaterialNumberCell.test.tsx +0 -382
- package/test/renderers/MaterialObjectControl.test.tsx +0 -186
- package/test/renderers/MaterialOneOfEnumCell.test.tsx +0 -94
- package/test/renderers/MaterialOneOfRadioGroupControl.test.tsx +0 -108
- package/test/renderers/MaterialOneOfRenderer.test.tsx +0 -603
- package/test/renderers/MaterialRadioGroupControl.test.tsx +0 -125
- package/test/renderers/MaterialSliderControl.test.tsx +0 -438
- package/test/renderers/MaterialTextCell.test.tsx +0 -541
- package/test/renderers/MaterialTextControl.test.tsx +0 -115
- package/test/renderers/MaterialTimeCell.test.tsx +0 -331
- package/test/renderers/MaterialTimeControl.test.tsx +0 -411
- package/test/renderers/util.ts +0 -50
- package/tsconfig.json +0 -13
- package/tsconfig.test.json +0 -7
- package/webpack/webpack.dev.js +0 -11
|
@@ -1,633 +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 {
|
|
27
|
-
ControlElement,
|
|
28
|
-
DispatchCellProps,
|
|
29
|
-
JsonSchema
|
|
30
|
-
} from '@jsonforms/core';
|
|
31
|
-
import * as React from 'react';
|
|
32
|
-
|
|
33
|
-
import MaterialArrayControlRenderer from '../../src/complex/MaterialArrayControlRenderer';
|
|
34
|
-
import { materialCells, materialRenderers } from '../../src';
|
|
35
|
-
import Enzyme, { mount, ReactWrapper } from 'enzyme';
|
|
36
|
-
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
|
37
|
-
import { JsonFormsStateProvider, StatelessRenderer } from '@jsonforms/react';
|
|
38
|
-
import { initCore, TestEmitter } from './util';
|
|
39
|
-
|
|
40
|
-
Enzyme.configure({ adapter: new Adapter() });
|
|
41
|
-
|
|
42
|
-
const fixture: {
|
|
43
|
-
data: any;
|
|
44
|
-
schema: JsonSchema;
|
|
45
|
-
uischema: ControlElement;
|
|
46
|
-
} = {
|
|
47
|
-
data: [
|
|
48
|
-
{
|
|
49
|
-
message: 'El Barto was here',
|
|
50
|
-
done: true
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
message: 'Yolo'
|
|
54
|
-
}
|
|
55
|
-
],
|
|
56
|
-
schema: {
|
|
57
|
-
type: 'array',
|
|
58
|
-
items: {
|
|
59
|
-
type: 'object',
|
|
60
|
-
properties: {
|
|
61
|
-
message: {
|
|
62
|
-
type: 'string',
|
|
63
|
-
maxLength: 3
|
|
64
|
-
},
|
|
65
|
-
done: {
|
|
66
|
-
type: 'boolean'
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
uischema: {
|
|
72
|
-
type: 'Control',
|
|
73
|
-
scope: '#'
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const fixture2: {
|
|
78
|
-
data: any;
|
|
79
|
-
schema: JsonSchema;
|
|
80
|
-
uischema: ControlElement;
|
|
81
|
-
} = {
|
|
82
|
-
data: { test: ['foo', 'baz', 'bar'] },
|
|
83
|
-
schema: {
|
|
84
|
-
type: 'object',
|
|
85
|
-
properties: {
|
|
86
|
-
test: {
|
|
87
|
-
type: 'array',
|
|
88
|
-
items: { type: 'string' }
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
uischema: {
|
|
93
|
-
type: 'Control',
|
|
94
|
-
scope: '#/properties/test',
|
|
95
|
-
options: {
|
|
96
|
-
showSortButtons: true
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
describe('Material array control', () => {
|
|
102
|
-
let wrapper: ReactWrapper;
|
|
103
|
-
|
|
104
|
-
afterEach(() => wrapper.unmount());
|
|
105
|
-
|
|
106
|
-
it('should render', () => {
|
|
107
|
-
const core = initCore(fixture.schema, fixture.uischema, fixture.data);
|
|
108
|
-
wrapper = mount(
|
|
109
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
110
|
-
<MaterialArrayControlRenderer
|
|
111
|
-
schema={fixture.schema}
|
|
112
|
-
uischema={fixture.uischema}
|
|
113
|
-
/>
|
|
114
|
-
</JsonFormsStateProvider>
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
const rows = wrapper.find('tr');
|
|
118
|
-
// 2 header rows + 2 data entries
|
|
119
|
-
expect(rows.length).toBe(4);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should render empty', () => {
|
|
123
|
-
const core = initCore(fixture.schema, fixture.uischema);
|
|
124
|
-
wrapper = mount(
|
|
125
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
126
|
-
<MaterialArrayControlRenderer
|
|
127
|
-
schema={fixture.schema}
|
|
128
|
-
uischema={fixture.uischema}
|
|
129
|
-
/>
|
|
130
|
-
</JsonFormsStateProvider>
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const rows = wrapper.find('tr');
|
|
134
|
-
// two header rows + no data row
|
|
135
|
-
expect(rows.length).toBe(3);
|
|
136
|
-
const headerColumns = rows.at(1).children();
|
|
137
|
-
// 3 columns: message & done properties + column for delete button
|
|
138
|
-
expect(headerColumns).toHaveLength(3);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should render even without properties', () => {
|
|
142
|
-
// re-init
|
|
143
|
-
const data: any = { test: [] };
|
|
144
|
-
const schema: JsonSchema = {
|
|
145
|
-
type: 'object',
|
|
146
|
-
properties: {
|
|
147
|
-
test: {
|
|
148
|
-
type: 'array',
|
|
149
|
-
items: { type: 'object' }
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const uischema: ControlElement = {
|
|
154
|
-
type: 'Control',
|
|
155
|
-
scope: '#/properties/test'
|
|
156
|
-
};
|
|
157
|
-
const core = initCore(schema, uischema, data);
|
|
158
|
-
|
|
159
|
-
wrapper = mount(
|
|
160
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
161
|
-
<MaterialArrayControlRenderer schema={schema} uischema={uischema} />
|
|
162
|
-
</JsonFormsStateProvider>
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
const rows = wrapper.find('tr');
|
|
166
|
-
// two header rows + no data row
|
|
167
|
-
expect(rows.length).toBe(3);
|
|
168
|
-
const headerColumns = rows.at(1).children();
|
|
169
|
-
// 2 columns: content + buttons
|
|
170
|
-
expect(headerColumns).toHaveLength(2);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should use title as a header if it exists', () => {
|
|
174
|
-
// re-init
|
|
175
|
-
const data: any = { test: [] };
|
|
176
|
-
const schema: JsonSchema = {
|
|
177
|
-
type: 'object',
|
|
178
|
-
properties: {
|
|
179
|
-
test: {
|
|
180
|
-
type: 'array',
|
|
181
|
-
items: {
|
|
182
|
-
type: 'object',
|
|
183
|
-
properties: {
|
|
184
|
-
test1: {
|
|
185
|
-
type: 'string',
|
|
186
|
-
title: 'first test'
|
|
187
|
-
},
|
|
188
|
-
test_2: {
|
|
189
|
-
type: 'string',
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const uischema: ControlElement = {
|
|
197
|
-
type: 'Control',
|
|
198
|
-
scope: '#/properties/test'
|
|
199
|
-
};
|
|
200
|
-
const core = initCore(schema, uischema, data);
|
|
201
|
-
|
|
202
|
-
wrapper = mount(
|
|
203
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
204
|
-
<MaterialArrayControlRenderer schema={schema} uischema={uischema} />
|
|
205
|
-
</JsonFormsStateProvider>
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
// column headings are in the second row of the table, wrapped in <th>
|
|
209
|
-
const headers = wrapper.find('tr').at(1).find('th');
|
|
210
|
-
|
|
211
|
-
// the first property has a title, so we expect it to be rendered as the first column heading
|
|
212
|
-
expect(headers.at(0).text()).toEqual('first test');
|
|
213
|
-
|
|
214
|
-
// the second property has no title, so we expect to see the property name in start case
|
|
215
|
-
expect(headers.at(1).text()).toEqual('Test 2');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('should render empty primitives', () => {
|
|
219
|
-
// re-init
|
|
220
|
-
const data: any = { test: [] };
|
|
221
|
-
const schema: JsonSchema = {
|
|
222
|
-
type: 'object',
|
|
223
|
-
properties: {
|
|
224
|
-
test: {
|
|
225
|
-
type: 'array',
|
|
226
|
-
items: { type: 'string' }
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
const uischema: ControlElement = {
|
|
231
|
-
type: 'Control',
|
|
232
|
-
scope: '#/properties/test'
|
|
233
|
-
};
|
|
234
|
-
const core = initCore(schema, uischema, data);
|
|
235
|
-
wrapper = mount(
|
|
236
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
237
|
-
<MaterialArrayControlRenderer schema={schema} uischema={uischema} />
|
|
238
|
-
</JsonFormsStateProvider>
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
const rows = wrapper.find('tr');
|
|
242
|
-
// header + no data row
|
|
243
|
-
expect(rows).toHaveLength(2);
|
|
244
|
-
const emptyDataCol = rows.at(1).find('td');
|
|
245
|
-
expect(emptyDataCol).toHaveLength(1);
|
|
246
|
-
// selection column + 1 data column
|
|
247
|
-
expect(emptyDataCol.first().props().colSpan).toBe(2);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it('should render primitives', () => {
|
|
251
|
-
// re-init
|
|
252
|
-
const data = { test: ['foo', 'bar'] };
|
|
253
|
-
const schema = {
|
|
254
|
-
type: 'object',
|
|
255
|
-
properties: {
|
|
256
|
-
test: {
|
|
257
|
-
type: 'array',
|
|
258
|
-
items: { type: 'string' }
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
const uischema: ControlElement = {
|
|
263
|
-
type: 'Control',
|
|
264
|
-
scope: '#/properties/test'
|
|
265
|
-
};
|
|
266
|
-
const core = initCore(schema, uischema, data);
|
|
267
|
-
wrapper = mount(
|
|
268
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
269
|
-
<MaterialArrayControlRenderer schema={schema} uischema={uischema} />
|
|
270
|
-
</JsonFormsStateProvider>
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
const rows = wrapper.find('tr');
|
|
274
|
-
// header + 2 data entries
|
|
275
|
-
expect(rows).toHaveLength(3);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('should delete an item', () => {
|
|
279
|
-
const core = initCore(fixture.schema, fixture.uischema, fixture.data);
|
|
280
|
-
const onChangeData: any = {
|
|
281
|
-
data: undefined
|
|
282
|
-
};
|
|
283
|
-
wrapper = mount(
|
|
284
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, cells: materialCells, core }}>
|
|
285
|
-
<TestEmitter
|
|
286
|
-
onChange={({ data }) => {
|
|
287
|
-
onChangeData.data = data;
|
|
288
|
-
}}
|
|
289
|
-
/>
|
|
290
|
-
<MaterialArrayControlRenderer
|
|
291
|
-
schema={fixture.schema}
|
|
292
|
-
uischema={fixture.uischema}
|
|
293
|
-
/>
|
|
294
|
-
</JsonFormsStateProvider>
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
const buttons = wrapper.find('button');
|
|
298
|
-
// 7 buttons
|
|
299
|
-
// add row
|
|
300
|
-
// clear string
|
|
301
|
-
// delete row
|
|
302
|
-
// clear string
|
|
303
|
-
// delete row
|
|
304
|
-
// two dialog buttons (no + yes)
|
|
305
|
-
const nrOfRowsBeforeDelete = wrapper.find('tr').length;
|
|
306
|
-
|
|
307
|
-
const deleteButton = buttons.at(2);
|
|
308
|
-
deleteButton.simulate('click');
|
|
309
|
-
|
|
310
|
-
const confirmButton = buttons.at(6);
|
|
311
|
-
confirmButton.simulate('click');
|
|
312
|
-
|
|
313
|
-
const nrOfRowsAfterDelete = wrapper.find('tr').length;
|
|
314
|
-
|
|
315
|
-
expect(nrOfRowsBeforeDelete).toBe(4);
|
|
316
|
-
expect(nrOfRowsAfterDelete).toBe(3);
|
|
317
|
-
expect(onChangeData.data.length).toBe(1);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const CellRenderer1: StatelessRenderer<DispatchCellProps> = () => (
|
|
321
|
-
<div className='cell test 1' />
|
|
322
|
-
);
|
|
323
|
-
const CellRenderer2: StatelessRenderer<DispatchCellProps> = () => (
|
|
324
|
-
<div className='cell test 2' />
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
it('should use cells from store', () => {
|
|
328
|
-
const core = initCore(fixture.schema, fixture.uischema, fixture.data);
|
|
329
|
-
const cells = [
|
|
330
|
-
{
|
|
331
|
-
tester: () => 50,
|
|
332
|
-
cell: CellRenderer1
|
|
333
|
-
}, {
|
|
334
|
-
tester: () => 51,
|
|
335
|
-
cell: CellRenderer2
|
|
336
|
-
}
|
|
337
|
-
];
|
|
338
|
-
|
|
339
|
-
wrapper = mount(
|
|
340
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
341
|
-
<MaterialArrayControlRenderer
|
|
342
|
-
schema={fixture.schema}
|
|
343
|
-
uischema={fixture.uischema}
|
|
344
|
-
cells={cells}
|
|
345
|
-
/>
|
|
346
|
-
</JsonFormsStateProvider>
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
const rows = wrapper.find({ className: 'cell test 2' });
|
|
350
|
-
// 2 header rows + 2 data entries
|
|
351
|
-
expect(rows.length).toBe(4);
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('should use cells from own props', () => {
|
|
355
|
-
const core = initCore(fixture.schema, fixture.uischema, fixture.data);
|
|
356
|
-
const cell = {
|
|
357
|
-
tester: () => 50,
|
|
358
|
-
cell: CellRenderer1
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
wrapper = mount(
|
|
362
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
363
|
-
<MaterialArrayControlRenderer
|
|
364
|
-
schema={fixture.schema}
|
|
365
|
-
uischema={fixture.uischema}
|
|
366
|
-
cells={[ cell, { tester: () => 60, cell: CellRenderer2 }]}
|
|
367
|
-
/>
|
|
368
|
-
</JsonFormsStateProvider>
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
const rows = wrapper.find({ className: 'cell test 2' });
|
|
372
|
-
// 2 header rows + 2 data entries
|
|
373
|
-
expect(rows.length).toBe(4);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('should support adding rows that contain enums', () => {
|
|
377
|
-
const schema = {
|
|
378
|
-
type: 'object',
|
|
379
|
-
properties: {
|
|
380
|
-
things: {
|
|
381
|
-
type: 'array',
|
|
382
|
-
items: {
|
|
383
|
-
type: 'object',
|
|
384
|
-
properties: {
|
|
385
|
-
somethingElse: {
|
|
386
|
-
type: 'string'
|
|
387
|
-
},
|
|
388
|
-
thing: {
|
|
389
|
-
type: 'string',
|
|
390
|
-
enum: ['thing']
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
const uischema: ControlElement = {
|
|
398
|
-
type: 'Control',
|
|
399
|
-
scope: '#/properties/things'
|
|
400
|
-
};
|
|
401
|
-
const core = initCore(schema, uischema, {});
|
|
402
|
-
const onChangeData: any = {
|
|
403
|
-
data: undefined
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
wrapper = mount(
|
|
407
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
408
|
-
<TestEmitter
|
|
409
|
-
onChange={({ data }) => {
|
|
410
|
-
onChangeData.data = data;
|
|
411
|
-
}}
|
|
412
|
-
/>
|
|
413
|
-
<MaterialArrayControlRenderer schema={schema} uischema={uischema} />
|
|
414
|
-
</JsonFormsStateProvider>
|
|
415
|
-
);
|
|
416
|
-
|
|
417
|
-
const buttons = wrapper.find('button');
|
|
418
|
-
// 3 buttons
|
|
419
|
-
// add row
|
|
420
|
-
// two dialog buttons (no + yes)
|
|
421
|
-
const nrOfRowsBeforeAdd = wrapper.find('tr').length;
|
|
422
|
-
|
|
423
|
-
const addButton = buttons.at(0);
|
|
424
|
-
addButton.simulate('click');
|
|
425
|
-
addButton.simulate('click');
|
|
426
|
-
wrapper.update();
|
|
427
|
-
const nrOfRowsAfterAdd = wrapper.find('tr').length;
|
|
428
|
-
|
|
429
|
-
// 2 header rows + 'no data' row
|
|
430
|
-
expect(nrOfRowsBeforeAdd).toBe(3);
|
|
431
|
-
expect(nrOfRowsAfterAdd).toBe(4);
|
|
432
|
-
expect(onChangeData.data).toEqual({ things: [{}, {}] });
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('should be hideable', () => {
|
|
436
|
-
const schema = {
|
|
437
|
-
type: 'object',
|
|
438
|
-
properties: {
|
|
439
|
-
things: {
|
|
440
|
-
type: 'array',
|
|
441
|
-
items: {
|
|
442
|
-
type: 'object',
|
|
443
|
-
properties: {
|
|
444
|
-
somethingElse: {
|
|
445
|
-
type: 'string'
|
|
446
|
-
},
|
|
447
|
-
thing: {
|
|
448
|
-
type: 'string',
|
|
449
|
-
enum: ['thing']
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
const uischema: ControlElement = {
|
|
457
|
-
type: 'Control',
|
|
458
|
-
scope: '#/properties/things'
|
|
459
|
-
};
|
|
460
|
-
const core = initCore(schema, uischema, {});
|
|
461
|
-
wrapper = mount(
|
|
462
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
463
|
-
<MaterialArrayControlRenderer
|
|
464
|
-
schema={schema}
|
|
465
|
-
uischema={uischema}
|
|
466
|
-
visible={false}
|
|
467
|
-
/>
|
|
468
|
-
</JsonFormsStateProvider>
|
|
469
|
-
);
|
|
470
|
-
|
|
471
|
-
const nrOfButtons = wrapper.find('button').length;
|
|
472
|
-
expect(nrOfButtons).toBe(0);
|
|
473
|
-
|
|
474
|
-
const nrOfRows = wrapper.find('tr').length;
|
|
475
|
-
expect(nrOfRows).toBe(0);
|
|
476
|
-
});
|
|
477
|
-
it('should render sort buttons if showSortButtons is true', () => {
|
|
478
|
-
const data = { test: ['foo'] };
|
|
479
|
-
const core = initCore(fixture2.schema, fixture2.uischema, data);
|
|
480
|
-
wrapper = mount(
|
|
481
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
482
|
-
<MaterialArrayControlRenderer
|
|
483
|
-
schema={fixture2.schema}
|
|
484
|
-
uischema={fixture2.uischema}
|
|
485
|
-
/>
|
|
486
|
-
</JsonFormsStateProvider>
|
|
487
|
-
);
|
|
488
|
-
// up button
|
|
489
|
-
expect(
|
|
490
|
-
wrapper.find('button').find({ 'aria-label': 'Move up' }).length
|
|
491
|
-
).toBe(1);
|
|
492
|
-
// down button
|
|
493
|
-
expect(
|
|
494
|
-
wrapper.find('button').find({ 'aria-label': 'Move down' }).length
|
|
495
|
-
).toBe(1);
|
|
496
|
-
});
|
|
497
|
-
it('should be able to move item down if down button is clicked', () => {
|
|
498
|
-
const core = initCore(fixture2.schema, fixture2.uischema, fixture2.data);
|
|
499
|
-
const onChangeData: any = {
|
|
500
|
-
data: undefined
|
|
501
|
-
};
|
|
502
|
-
wrapper = mount(
|
|
503
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
504
|
-
<TestEmitter
|
|
505
|
-
onChange={({ data }) => {
|
|
506
|
-
onChangeData.data = data;
|
|
507
|
-
}}
|
|
508
|
-
/>
|
|
509
|
-
<MaterialArrayControlRenderer
|
|
510
|
-
schema={fixture2.schema}
|
|
511
|
-
uischema={fixture2.uischema}
|
|
512
|
-
/>
|
|
513
|
-
</JsonFormsStateProvider>
|
|
514
|
-
);
|
|
515
|
-
// first row is header in table
|
|
516
|
-
const downButton = wrapper
|
|
517
|
-
.find('tr')
|
|
518
|
-
.at(1)
|
|
519
|
-
.find('button')
|
|
520
|
-
.find({ 'aria-label': 'Move down' });
|
|
521
|
-
downButton.simulate('click');
|
|
522
|
-
expect(onChangeData.data).toEqual({
|
|
523
|
-
test: ['baz', 'foo', 'bar']
|
|
524
|
-
});
|
|
525
|
-
});
|
|
526
|
-
it('should be able to move item up if up button is clicked', () => {
|
|
527
|
-
const core = initCore(fixture2.schema, fixture2.uischema, fixture2.data);
|
|
528
|
-
const onChangeData: any = {
|
|
529
|
-
data: undefined
|
|
530
|
-
};
|
|
531
|
-
wrapper = mount(
|
|
532
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
533
|
-
<TestEmitter
|
|
534
|
-
onChange={({ data }) => {
|
|
535
|
-
onChangeData.data = data;
|
|
536
|
-
}}
|
|
537
|
-
/>
|
|
538
|
-
<MaterialArrayControlRenderer
|
|
539
|
-
schema={fixture2.schema}
|
|
540
|
-
uischema={fixture2.uischema}
|
|
541
|
-
/>
|
|
542
|
-
</JsonFormsStateProvider>
|
|
543
|
-
);
|
|
544
|
-
// first row is header in table
|
|
545
|
-
const upButton = wrapper
|
|
546
|
-
.find('tr')
|
|
547
|
-
.at(3)
|
|
548
|
-
.find('button')
|
|
549
|
-
.find({ 'aria-label': 'Move up' });
|
|
550
|
-
upButton.simulate('click');
|
|
551
|
-
expect(onChangeData.data).toEqual({
|
|
552
|
-
test: ['foo', 'bar', 'baz']
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
it('should have up button disabled for first element', () => {
|
|
556
|
-
const core = initCore(fixture2.schema, fixture2.uischema, fixture2.data);
|
|
557
|
-
wrapper = mount(
|
|
558
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
559
|
-
<MaterialArrayControlRenderer
|
|
560
|
-
schema={fixture2.schema}
|
|
561
|
-
uischema={fixture2.uischema}
|
|
562
|
-
/>
|
|
563
|
-
</JsonFormsStateProvider>
|
|
564
|
-
);
|
|
565
|
-
// first row is header in table
|
|
566
|
-
const upButton = wrapper
|
|
567
|
-
.find('tr')
|
|
568
|
-
.at(1)
|
|
569
|
-
.find('button')
|
|
570
|
-
.find({ 'aria-label': 'Move up' });
|
|
571
|
-
expect(upButton.is('[disabled]')).toBe(true);
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
it('should have fields enabled', () => {
|
|
575
|
-
const core = initCore(fixture2.schema, fixture2.uischema, fixture2.data);
|
|
576
|
-
wrapper = mount(
|
|
577
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, cells: materialCells, core }}>
|
|
578
|
-
<MaterialArrayControlRenderer
|
|
579
|
-
schema={fixture2.schema}
|
|
580
|
-
uischema={fixture2.uischema}
|
|
581
|
-
enabled={true}
|
|
582
|
-
/>
|
|
583
|
-
</JsonFormsStateProvider>
|
|
584
|
-
);
|
|
585
|
-
// first row is header in table
|
|
586
|
-
const input = wrapper
|
|
587
|
-
.find('tr')
|
|
588
|
-
.at(1)
|
|
589
|
-
.find('input')
|
|
590
|
-
.first();
|
|
591
|
-
expect(input.props().disabled).toBe(false);
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
it('should have fields disabled', () => {
|
|
595
|
-
const core = initCore(fixture2.schema, fixture2.uischema, fixture2.data);
|
|
596
|
-
wrapper = mount(
|
|
597
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, cells: materialCells, core }}>
|
|
598
|
-
<MaterialArrayControlRenderer
|
|
599
|
-
schema={fixture2.schema}
|
|
600
|
-
uischema={fixture2.uischema}
|
|
601
|
-
enabled={false}
|
|
602
|
-
/>
|
|
603
|
-
</JsonFormsStateProvider>
|
|
604
|
-
);
|
|
605
|
-
// first row is header in table
|
|
606
|
-
const input = wrapper
|
|
607
|
-
.find('tr')
|
|
608
|
-
.at(1)
|
|
609
|
-
.find('input')
|
|
610
|
-
.first();
|
|
611
|
-
expect(input.props().disabled).toBe(true);
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
it('should have down button disabled for last element', () => {
|
|
615
|
-
const core = initCore(fixture2.schema, fixture2.uischema, fixture2.data);
|
|
616
|
-
wrapper = mount(
|
|
617
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
618
|
-
<MaterialArrayControlRenderer
|
|
619
|
-
schema={fixture2.schema}
|
|
620
|
-
uischema={fixture2.uischema}
|
|
621
|
-
/>
|
|
622
|
-
</JsonFormsStateProvider>
|
|
623
|
-
);
|
|
624
|
-
// first row is header in table
|
|
625
|
-
// first buttton is up arrow, second button is down arrow
|
|
626
|
-
const downButton = wrapper
|
|
627
|
-
.find('tr')
|
|
628
|
-
.at(3)
|
|
629
|
-
.find('button')
|
|
630
|
-
.find({ 'aria-label': 'Move down' });
|
|
631
|
-
expect(downButton.is('[disabled]')).toBe(true);
|
|
632
|
-
});
|
|
633
|
-
});
|