@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,36 +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
|
-
window.matchMedia = jest.fn().mockImplementation(query => {
|
|
26
|
-
return {
|
|
27
|
-
matches: true,
|
|
28
|
-
media: query,
|
|
29
|
-
onchange: null,
|
|
30
|
-
addListener: jest.fn(),
|
|
31
|
-
removeListener: jest.fn(),
|
|
32
|
-
addEventListener: jest.fn(),
|
|
33
|
-
removeEventListener: jest.fn(),
|
|
34
|
-
dispatchEvent: jest.fn()
|
|
35
|
-
};
|
|
36
|
-
});
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The MIT License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2017-2019 EclipseSource Munich
|
|
5
|
-
https://github.com/eclipsesource/jsonforms
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
|
15
|
-
all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
THE SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
import './MatchMediaMock';
|
|
26
|
-
import React from 'react';
|
|
27
|
-
|
|
28
|
-
import Enzyme, { mount, ReactWrapper } from 'enzyme';
|
|
29
|
-
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
|
30
|
-
import { ControlElement } from '@jsonforms/core';
|
|
31
|
-
import { MaterialAllOfRenderer, materialRenderers } from '../../src';
|
|
32
|
-
import { JsonForms, JsonFormsStateProvider } from '@jsonforms/react';
|
|
33
|
-
import { initCore } from './util';
|
|
34
|
-
|
|
35
|
-
Enzyme.configure({ adapter: new Adapter() });
|
|
36
|
-
|
|
37
|
-
describe('Material allOf renderer', () => {
|
|
38
|
-
let wrapper: ReactWrapper;
|
|
39
|
-
|
|
40
|
-
afterEach(() => wrapper.unmount());
|
|
41
|
-
|
|
42
|
-
it('should render', () => {
|
|
43
|
-
const schema = {
|
|
44
|
-
type: 'object',
|
|
45
|
-
properties: {
|
|
46
|
-
value: {
|
|
47
|
-
allOf: [
|
|
48
|
-
{
|
|
49
|
-
title: 'String',
|
|
50
|
-
type: 'string'
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
title: 'Number',
|
|
54
|
-
type: 'number'
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const uischema: ControlElement = {
|
|
61
|
-
type: 'Control',
|
|
62
|
-
label: 'Value',
|
|
63
|
-
scope: '#/properties/value'
|
|
64
|
-
};
|
|
65
|
-
wrapper = mount(
|
|
66
|
-
<JsonForms
|
|
67
|
-
data={undefined}
|
|
68
|
-
schema={schema}
|
|
69
|
-
uischema={uischema}
|
|
70
|
-
renderers={materialRenderers}
|
|
71
|
-
/>
|
|
72
|
-
);
|
|
73
|
-
expect(wrapper.find(MaterialAllOfRenderer).length).toBeTruthy();
|
|
74
|
-
const inputs = wrapper.find('input');
|
|
75
|
-
expect(inputs.length).toBe(2);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should be hideable', () => {
|
|
79
|
-
const schema = {
|
|
80
|
-
type: 'object',
|
|
81
|
-
properties: {
|
|
82
|
-
value: {
|
|
83
|
-
allOf: [
|
|
84
|
-
{
|
|
85
|
-
title: 'String',
|
|
86
|
-
type: 'string'
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
title: 'Number',
|
|
90
|
-
type: 'number'
|
|
91
|
-
}
|
|
92
|
-
]
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const uischema: ControlElement = {
|
|
97
|
-
type: 'Control',
|
|
98
|
-
label: 'Value',
|
|
99
|
-
scope: '#/properties/value'
|
|
100
|
-
};
|
|
101
|
-
const core = initCore(schema, uischema);
|
|
102
|
-
wrapper = mount(
|
|
103
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
104
|
-
<MaterialAllOfRenderer
|
|
105
|
-
schema={schema}
|
|
106
|
-
uischema={uischema}
|
|
107
|
-
visible={false}
|
|
108
|
-
/>
|
|
109
|
-
</JsonFormsStateProvider>
|
|
110
|
-
);
|
|
111
|
-
const inputs = wrapper.find('input');
|
|
112
|
-
expect(inputs.length).toBe(0);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The MIT License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2017-2019 EclipseSource Munich
|
|
5
|
-
https://github.com/eclipsesource/jsonforms
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
|
15
|
-
all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
THE SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
import './MatchMediaMock';
|
|
26
|
-
import React from 'react';
|
|
27
|
-
|
|
28
|
-
import Enzyme, { mount, ReactWrapper } from 'enzyme';
|
|
29
|
-
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
|
30
|
-
import {
|
|
31
|
-
ControlElement
|
|
32
|
-
} from '@jsonforms/core';
|
|
33
|
-
import {
|
|
34
|
-
MaterialAnyOfRenderer,
|
|
35
|
-
materialCells,
|
|
36
|
-
materialRenderers
|
|
37
|
-
} from '../../src';
|
|
38
|
-
import { JsonForms, JsonFormsStateProvider } from '@jsonforms/react';
|
|
39
|
-
import { initCore, TestEmitter } from './util';
|
|
40
|
-
|
|
41
|
-
Enzyme.configure({ adapter: new Adapter() });
|
|
42
|
-
|
|
43
|
-
const waitForAsync = () => new Promise(resolve => setImmediate(resolve));
|
|
44
|
-
|
|
45
|
-
const clickAddButton = (wrapper: ReactWrapper, times: number) => {
|
|
46
|
-
const buttons = wrapper.find('button');
|
|
47
|
-
const addButton = buttons.at(2);
|
|
48
|
-
for (let i = 0; i < times; i++) {
|
|
49
|
-
addButton.simulate('click');
|
|
50
|
-
}
|
|
51
|
-
wrapper.update();
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const selectanyOfTab = (wrapper: ReactWrapper, at: number) => {
|
|
55
|
-
const buttons = wrapper.find('button');
|
|
56
|
-
buttons.at(at).simulate('click');
|
|
57
|
-
wrapper.update();
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
describe('Material anyOf renderer', () => {
|
|
61
|
-
let wrapper: ReactWrapper;
|
|
62
|
-
|
|
63
|
-
afterEach(() => wrapper.unmount());
|
|
64
|
-
|
|
65
|
-
it('should add an item at correct path', (done) => {
|
|
66
|
-
const schema = {
|
|
67
|
-
type: 'object',
|
|
68
|
-
properties: {
|
|
69
|
-
value: {
|
|
70
|
-
anyOf: [
|
|
71
|
-
{
|
|
72
|
-
title: 'String',
|
|
73
|
-
type: 'string'
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
title: 'Number',
|
|
77
|
-
type: 'number'
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const uischema: ControlElement = {
|
|
84
|
-
type: 'Control',
|
|
85
|
-
label: 'Value',
|
|
86
|
-
scope: '#/properties/value'
|
|
87
|
-
};
|
|
88
|
-
const onChangeData: any = {
|
|
89
|
-
data: undefined
|
|
90
|
-
};
|
|
91
|
-
wrapper = mount(
|
|
92
|
-
<JsonForms
|
|
93
|
-
data={undefined}
|
|
94
|
-
schema={schema}
|
|
95
|
-
uischema={uischema}
|
|
96
|
-
renderers={materialRenderers}
|
|
97
|
-
onChange={({ data }) => {
|
|
98
|
-
onChangeData.data = data;
|
|
99
|
-
}}
|
|
100
|
-
/>
|
|
101
|
-
);
|
|
102
|
-
expect(wrapper.find(MaterialAnyOfRenderer).length).toBeTruthy();
|
|
103
|
-
const input = wrapper.find('input').first();
|
|
104
|
-
input.simulate('change', { target: { value: 'test' } });
|
|
105
|
-
wrapper.update();
|
|
106
|
-
setTimeout(() => {
|
|
107
|
-
expect(onChangeData.data).toEqual({
|
|
108
|
-
value: 'test'
|
|
109
|
-
});
|
|
110
|
-
done();
|
|
111
|
-
}, 1000);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should add a "mything"', async () => {
|
|
115
|
-
const schema = {
|
|
116
|
-
type: 'object',
|
|
117
|
-
properties: {
|
|
118
|
-
myThingsAndOrYourThings: {
|
|
119
|
-
anyOf: [
|
|
120
|
-
{
|
|
121
|
-
$ref: '#/definitions/myThings'
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
$ref: '#/definitions/yourThings'
|
|
125
|
-
}
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
definitions: {
|
|
130
|
-
myThings: {
|
|
131
|
-
title: 'MyThing',
|
|
132
|
-
type: 'array',
|
|
133
|
-
items: {
|
|
134
|
-
type: 'object',
|
|
135
|
-
properties: {
|
|
136
|
-
name: {
|
|
137
|
-
type: 'string'
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
yourThings: {
|
|
143
|
-
title: 'YourThings',
|
|
144
|
-
type: 'array',
|
|
145
|
-
items: {
|
|
146
|
-
type: 'object',
|
|
147
|
-
properties: {
|
|
148
|
-
age: {
|
|
149
|
-
type: 'number'
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const uischema: ControlElement = {
|
|
157
|
-
type: 'Control',
|
|
158
|
-
scope: '#/properties/myThingsAndOrYourThings'
|
|
159
|
-
};
|
|
160
|
-
const core = initCore(schema, uischema);
|
|
161
|
-
wrapper = mount(
|
|
162
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
163
|
-
<MaterialAnyOfRenderer
|
|
164
|
-
schema={schema}
|
|
165
|
-
uischema={uischema}
|
|
166
|
-
/>
|
|
167
|
-
</JsonFormsStateProvider>
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
await waitForAsync();
|
|
171
|
-
|
|
172
|
-
wrapper.update();
|
|
173
|
-
|
|
174
|
-
selectanyOfTab(wrapper, 1);
|
|
175
|
-
const nrOfRowsBeforeAdd = wrapper.find('tr');
|
|
176
|
-
clickAddButton(wrapper, 2);
|
|
177
|
-
const nrOfRowsAfterAdd = wrapper.find('tr');
|
|
178
|
-
|
|
179
|
-
// 2 header row + 1 no data row
|
|
180
|
-
expect(nrOfRowsBeforeAdd.length).toBe(3);
|
|
181
|
-
// 2 header row + 2 data rows (one is replacing the 'No data' one)
|
|
182
|
-
expect(nrOfRowsAfterAdd.length).toBe(4);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('should switch to "yourThing" edit, then switch back, then edit', async (done) => {
|
|
186
|
-
const schema = {
|
|
187
|
-
type: 'object',
|
|
188
|
-
properties: {
|
|
189
|
-
myThingsAndOrYourThings: {
|
|
190
|
-
anyOf: [
|
|
191
|
-
{
|
|
192
|
-
$ref: '#/definitions/myThings'
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
$ref: '#/definitions/yourThings'
|
|
196
|
-
}
|
|
197
|
-
]
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
definitions: {
|
|
201
|
-
myThings: {
|
|
202
|
-
title: 'MyThing',
|
|
203
|
-
type: 'array',
|
|
204
|
-
items: {
|
|
205
|
-
type: 'object',
|
|
206
|
-
properties: {
|
|
207
|
-
name: {
|
|
208
|
-
type: 'string'
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
yourThings: {
|
|
214
|
-
title: 'YourThings',
|
|
215
|
-
type: 'array',
|
|
216
|
-
items: {
|
|
217
|
-
type: 'object',
|
|
218
|
-
properties: {
|
|
219
|
-
age: {
|
|
220
|
-
type: 'number'
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
const uischema: ControlElement = {
|
|
228
|
-
type: 'Control',
|
|
229
|
-
scope: '#/properties/myThingsAndOrYourThings'
|
|
230
|
-
};
|
|
231
|
-
const onChangeData: any = {
|
|
232
|
-
data: undefined
|
|
233
|
-
};
|
|
234
|
-
const core = initCore(schema, uischema);
|
|
235
|
-
wrapper = mount(
|
|
236
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, cells: materialCells, core }}>
|
|
237
|
-
<TestEmitter
|
|
238
|
-
onChange={({ data }) => {
|
|
239
|
-
onChangeData.data = data;
|
|
240
|
-
}}
|
|
241
|
-
/>
|
|
242
|
-
<MaterialAnyOfRenderer
|
|
243
|
-
schema={schema}
|
|
244
|
-
uischema={uischema}
|
|
245
|
-
/>
|
|
246
|
-
</JsonFormsStateProvider>
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
await waitForAsync();
|
|
250
|
-
|
|
251
|
-
wrapper.update();
|
|
252
|
-
|
|
253
|
-
selectanyOfTab(wrapper, 1);
|
|
254
|
-
clickAddButton(wrapper, 1);
|
|
255
|
-
wrapper
|
|
256
|
-
.find('input')
|
|
257
|
-
.first()
|
|
258
|
-
.simulate('change', { target: { value: 5 } });
|
|
259
|
-
wrapper.update();
|
|
260
|
-
selectanyOfTab(wrapper, 0);
|
|
261
|
-
|
|
262
|
-
const input = wrapper.find('input').first();
|
|
263
|
-
input.simulate('change', { target: { value: 'test' } });
|
|
264
|
-
wrapper.update();
|
|
265
|
-
|
|
266
|
-
setTimeout(() => {
|
|
267
|
-
expect(onChangeData.data).toEqual({
|
|
268
|
-
myThingsAndOrYourThings: [{ age: 5, name: 'test' }]
|
|
269
|
-
});
|
|
270
|
-
done();
|
|
271
|
-
}, 1000);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('should be hideable', () => {
|
|
275
|
-
const schema = {
|
|
276
|
-
type: 'object',
|
|
277
|
-
properties: {
|
|
278
|
-
value: {
|
|
279
|
-
anyOf: [
|
|
280
|
-
{
|
|
281
|
-
title: 'String',
|
|
282
|
-
type: 'string'
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
title: 'Number',
|
|
286
|
-
type: 'number'
|
|
287
|
-
}
|
|
288
|
-
]
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
const uischema: ControlElement = {
|
|
293
|
-
type: 'Control',
|
|
294
|
-
label: 'Value',
|
|
295
|
-
scope: '#/properties/value'
|
|
296
|
-
};
|
|
297
|
-
const core = initCore(schema, uischema);
|
|
298
|
-
wrapper = mount(
|
|
299
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
300
|
-
<MaterialAnyOfRenderer
|
|
301
|
-
schema={schema}
|
|
302
|
-
uischema={uischema}
|
|
303
|
-
visible={false}
|
|
304
|
-
/>
|
|
305
|
-
</JsonFormsStateProvider>
|
|
306
|
-
);
|
|
307
|
-
const inputs = wrapper.find('input');
|
|
308
|
-
expect(inputs.length).toBe(0);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The MIT License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2017-2019 EclipseSource Munich
|
|
5
|
-
https://github.com/eclipsesource/jsonforms
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
|
15
|
-
all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
THE SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
import './MatchMediaMock';
|
|
26
|
-
import React from 'react';
|
|
27
|
-
|
|
28
|
-
import Enzyme, { mount, ReactWrapper } from 'enzyme';
|
|
29
|
-
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
|
30
|
-
import {
|
|
31
|
-
ControlElement,
|
|
32
|
-
JsonSchema
|
|
33
|
-
} from '@jsonforms/core';
|
|
34
|
-
import {
|
|
35
|
-
MaterialAnyOfStringOrEnumControl,
|
|
36
|
-
materialAnyOfStringOrEnumControlTester,
|
|
37
|
-
materialRenderers
|
|
38
|
-
} from '../../src';
|
|
39
|
-
import { JsonForms } from '@jsonforms/react';
|
|
40
|
-
|
|
41
|
-
Enzyme.configure({ adapter: new Adapter() });
|
|
42
|
-
|
|
43
|
-
const schema: JsonSchema = {
|
|
44
|
-
anyOf: [{ type: 'string' }, { enum: ['foo', 'bar'] }]
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const uischema: ControlElement = {
|
|
48
|
-
type: 'Control',
|
|
49
|
-
scope: '#'
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('Material simple any of control tester', () => {
|
|
53
|
-
it('should only be applicable for simple any of cases', () => {
|
|
54
|
-
expect(
|
|
55
|
-
materialAnyOfStringOrEnumControlTester({ type: 'Foo' }, schema, undefined)
|
|
56
|
-
).toBe(-1);
|
|
57
|
-
expect(materialAnyOfStringOrEnumControlTester(uischema, schema, undefined)).toBe(5);
|
|
58
|
-
|
|
59
|
-
const nestedSchema: JsonSchema = {
|
|
60
|
-
properties: {
|
|
61
|
-
foo: { anyOf: [{ type: 'string' }, { enum: ['foo', 'bar'] }] }
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const nestedUischema: ControlElement = {
|
|
65
|
-
type: 'Control',
|
|
66
|
-
scope: '#/properties/foo'
|
|
67
|
-
};
|
|
68
|
-
expect(
|
|
69
|
-
materialAnyOfStringOrEnumControlTester(nestedUischema, nestedSchema, undefined)
|
|
70
|
-
).toBe(5);
|
|
71
|
-
const schemaNoEnum: JsonSchema = {
|
|
72
|
-
anyOf: [{ type: 'string' }]
|
|
73
|
-
};
|
|
74
|
-
const schemaConflictTypes: JsonSchema = {
|
|
75
|
-
anyOf: [{ type: 'string' }, { type: 'integer', enum: [1, 2] }]
|
|
76
|
-
};
|
|
77
|
-
const schemaAdditionalProps: JsonSchema = {
|
|
78
|
-
anyOf: [{ type: 'string' }, { enum: ['foo', 'bar'] }, { maxLength: 5 }]
|
|
79
|
-
};
|
|
80
|
-
const schemaNoString: JsonSchema = {
|
|
81
|
-
anyOf: [{ type: 'integer' }, { enum: [1, 2] }]
|
|
82
|
-
};
|
|
83
|
-
expect(materialAnyOfStringOrEnumControlTester(uischema, schemaNoEnum, undefined)).toBe(
|
|
84
|
-
-1
|
|
85
|
-
);
|
|
86
|
-
expect(
|
|
87
|
-
materialAnyOfStringOrEnumControlTester(uischema, schemaConflictTypes, undefined)
|
|
88
|
-
).toBe(-1);
|
|
89
|
-
expect(
|
|
90
|
-
materialAnyOfStringOrEnumControlTester(uischema, schemaAdditionalProps, undefined)
|
|
91
|
-
).toBe(5);
|
|
92
|
-
expect(
|
|
93
|
-
materialAnyOfStringOrEnumControlTester(uischema, schemaNoString, undefined)
|
|
94
|
-
).toBe(-1);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('Material any of string or enum control', () => {
|
|
99
|
-
let wrapper: ReactWrapper;
|
|
100
|
-
|
|
101
|
-
afterEach(() => {
|
|
102
|
-
wrapper.unmount();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('render', () => {
|
|
106
|
-
wrapper = mount(
|
|
107
|
-
<JsonForms
|
|
108
|
-
data={'foo'}
|
|
109
|
-
schema={schema}
|
|
110
|
-
uischema={uischema}
|
|
111
|
-
renderers={materialRenderers}
|
|
112
|
-
/>
|
|
113
|
-
);
|
|
114
|
-
expect(wrapper.find(MaterialAnyOfStringOrEnumControl).length).toBeTruthy();
|
|
115
|
-
const inputs = wrapper.find('input');
|
|
116
|
-
expect(inputs).toHaveLength(1);
|
|
117
|
-
|
|
118
|
-
const datalist = wrapper.find('datalist');
|
|
119
|
-
expect(datalist).toHaveLength(1);
|
|
120
|
-
expect(datalist.children()).toHaveLength(2);
|
|
121
|
-
|
|
122
|
-
const validation = wrapper.find('p').first();
|
|
123
|
-
expect(validation.props().className).toContain('MuiFormHelperText-root');
|
|
124
|
-
expect(validation.children()).toHaveLength(0);
|
|
125
|
-
});
|
|
126
|
-
});
|