@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.
- package/README.md +16 -17
- package/lib/additional/ListWithDetailMasterItem.d.ts +2 -0
- package/lib/additional/MaterialListWithDetailRenderer.d.ts +1 -1
- package/lib/additional/index.d.ts +2 -2
- package/lib/additional/unwrapped.d.ts +5 -0
- package/lib/cells/index.d.ts +1 -1
- package/lib/complex/CombinatorProperties.d.ts +1 -2
- package/lib/complex/DeleteDialog.d.ts +5 -1
- package/lib/complex/MaterialAllOfRenderer.d.ts +1 -1
- package/lib/complex/MaterialAnyOfRenderer.d.ts +1 -1
- package/lib/complex/MaterialArrayControlRenderer.d.ts +2 -1
- package/lib/complex/MaterialEnumArrayRenderer.d.ts +1 -1
- package/lib/complex/MaterialObjectRenderer.d.ts +1 -1
- package/lib/complex/MaterialOneOfRenderer.d.ts +1 -1
- package/lib/complex/MaterialTableControl.d.ts +4 -2
- package/lib/complex/NoBorderTableCell.d.ts +2 -2
- package/lib/complex/TableToolbar.d.ts +3 -2
- package/lib/complex/index.d.ts +11 -16
- package/lib/complex/unwrapped.d.ts +9 -0
- package/lib/controls/MaterialBooleanControl.d.ts +1 -1
- package/lib/controls/MaterialBooleanToggleControl.d.ts +1 -1
- package/lib/controls/index.d.ts +8 -26
- package/lib/controls/unwrapped.d.ts +19 -0
- package/lib/index.d.ts +34 -1
- package/lib/jsonforms-react-material.cjs.js +731 -572
- package/lib/jsonforms-react-material.cjs.js.map +1 -1
- package/lib/jsonforms-react-material.esm.js +648 -517
- package/lib/jsonforms-react-material.esm.js.map +1 -1
- package/lib/layouts/ArrayToolbar.d.ts +3 -1
- package/lib/layouts/ExpandPanelRenderer.d.ts +3 -1
- package/lib/layouts/MaterialGroupLayout.d.ts +1 -1
- package/lib/layouts/MaterialHorizontalLayout.d.ts +1 -1
- package/lib/layouts/MaterialVerticalLayout.d.ts +1 -1
- package/lib/layouts/index.d.ts +3 -1
- package/lib/layouts/unwrapped.d.ts +10 -0
- package/lib/mui-controls/MuiCheckbox.d.ts +6 -1
- package/lib/mui-controls/MuiInputInteger.d.ts +1 -1
- package/lib/mui-controls/MuiInputNumber.d.ts +1 -1
- package/lib/mui-controls/MuiInputNumberFormat.d.ts +1 -1
- package/lib/mui-controls/MuiInputText.d.ts +1 -1
- package/lib/mui-controls/MuiInputTime.d.ts +1 -1
- package/lib/mui-controls/MuiSelect.d.ts +1 -1
- package/lib/mui-controls/MuiToggle.d.ts +6 -1
- package/lib/mui-controls/index.d.ts +3 -1
- package/lib/util/layout.d.ts +2 -3
- package/package.json +33 -15
- package/src/additional/ListWithDetailMasterItem.tsx +32 -24
- package/src/additional/MaterialLabelRenderer.tsx +8 -15
- package/src/additional/MaterialListWithDetailRenderer.tsx +8 -5
- package/src/additional/index.ts +12 -4
- package/{example/index.ts → src/additional/unwrapped.ts} +7 -6
- package/src/cells/MaterialBooleanCell.tsx +1 -1
- package/src/cells/MaterialBooleanToggleCell.tsx +2 -2
- package/src/cells/MaterialDateCell.tsx +4 -12
- package/src/cells/MaterialEnumCell.tsx +13 -6
- package/src/cells/MaterialIntegerCell.tsx +1 -1
- package/src/cells/MaterialNumberCell.tsx +1 -1
- package/src/cells/MaterialNumberFormatCell.tsx +1 -1
- package/src/cells/MaterialOneOfEnumCell.tsx +17 -7
- package/src/cells/MaterialTextCell.tsx +1 -1
- package/src/cells/MaterialTimeCell.tsx +1 -1
- package/src/cells/index.ts +7 -7
- package/src/complex/CombinatorProperties.tsx +20 -9
- package/src/complex/DeleteDialog.tsx +48 -37
- package/src/complex/MaterialAllOfRenderer.tsx +2 -2
- package/src/complex/MaterialAnyOfRenderer.tsx +3 -3
- package/src/complex/MaterialArrayControlRenderer.tsx +27 -11
- package/src/complex/MaterialEnumArrayRenderer.tsx +6 -8
- package/src/complex/MaterialObjectRenderer.tsx +6 -3
- package/src/complex/MaterialOneOfRenderer.tsx +105 -88
- package/src/complex/MaterialTableControl.tsx +145 -97
- package/src/complex/NoBorderTableCell.tsx +3 -5
- package/src/complex/TableToolbar.tsx +24 -25
- package/src/complex/ValidationIcon.tsx +10 -18
- package/src/complex/index.ts +35 -32
- package/{test/renderers/MatchMediaMock.ts → src/complex/unwrapped.ts} +19 -16
- package/src/controls/MaterialAnyOfStringOrEnumControl.tsx +19 -11
- package/src/controls/MaterialBooleanControl.tsx +90 -23
- package/src/controls/MaterialBooleanToggleControl.tsx +90 -23
- package/src/controls/MaterialDateControl.tsx +16 -19
- package/src/controls/MaterialDateTimeControl.tsx +24 -23
- package/src/controls/MaterialEnumControl.tsx +21 -15
- package/src/controls/MaterialInputControl.tsx +7 -8
- package/src/controls/MaterialIntegerControl.tsx +1 -1
- package/src/controls/MaterialNativeControl.tsx +12 -9
- package/src/controls/MaterialNumberControl.tsx +1 -1
- package/src/controls/MaterialOneOfEnumControl.tsx +21 -15
- package/src/controls/MaterialOneOfRadioGroupControl.tsx +5 -3
- package/src/controls/MaterialRadioGroup.tsx +11 -17
- package/src/controls/MaterialRadioGroupControl.tsx +8 -3
- package/src/controls/MaterialSliderControl.tsx +17 -16
- package/src/controls/MaterialTextControl.tsx +1 -1
- package/src/controls/MaterialTimeControl.tsx +19 -22
- package/src/controls/index.ts +36 -72
- package/src/controls/unwrapped.ts +57 -0
- package/src/index.ts +41 -22
- package/src/layouts/ArrayToolbar.tsx +38 -42
- package/src/layouts/ExpandPanelRenderer.tsx +96 -67
- package/src/layouts/MaterialArrayLayout.tsx +21 -16
- package/src/layouts/MaterialArrayLayoutRenderer.tsx +6 -9
- package/src/layouts/MaterialCategorizationLayout.tsx +52 -21
- package/src/layouts/MaterialCategorizationStepperLayout.tsx +60 -44
- package/src/layouts/MaterialGroupLayout.tsx +25 -6
- package/src/layouts/MaterialHorizontalLayout.tsx +18 -4
- package/src/layouts/MaterialVerticalLayout.tsx +18 -4
- package/src/layouts/index.ts +18 -7
- package/{test/renderers/util.ts → src/layouts/unwrapped.ts} +19 -28
- package/src/mui-controls/MuiAutocomplete.tsx +51 -35
- package/src/mui-controls/MuiCheckbox.tsx +14 -5
- package/src/mui-controls/MuiInputInteger.tsx +31 -32
- package/src/mui-controls/MuiInputNumber.tsx +16 -16
- package/src/mui-controls/MuiInputNumberFormat.tsx +51 -42
- package/src/mui-controls/MuiInputText.tsx +30 -19
- package/src/mui-controls/MuiInputTime.tsx +11 -12
- package/src/mui-controls/MuiSelect.tsx +15 -6
- package/src/mui-controls/MuiToggle.tsx +14 -5
- package/src/mui-controls/index.ts +3 -1
- package/src/util/datejs.tsx +41 -20
- package/src/util/debounce.ts +26 -11
- package/src/util/focus.ts +7 -7
- package/src/util/i18nDefaults.ts +2 -2
- package/src/util/layout.tsx +47 -42
- package/src/util/theme.ts +2 -2
- 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/rollup.config.js +0 -51
- package/stats.html +0 -3279
- 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/tsconfig.json +0 -13
- package/tsconfig.test.json +0 -7
- package/webpack/webpack.dev.js +0 -11
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The MIT License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2017-2019 EclipseSource Munich
|
|
5
|
-
https://github.com/eclipsesource/jsonforms
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
|
15
|
-
all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
THE SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
import './MatchMediaMock';
|
|
26
|
-
import * as React from 'react';
|
|
27
|
-
import {
|
|
28
|
-
ControlElement
|
|
29
|
-
} from '@jsonforms/core';
|
|
30
|
-
import { materialRenderers, MuiSelect } from '../../src';
|
|
31
|
-
|
|
32
|
-
import Enzyme, { mount } from 'enzyme';
|
|
33
|
-
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
|
34
|
-
import { JsonFormsStateProvider } from '@jsonforms/react';
|
|
35
|
-
import { initCore } from './util';
|
|
36
|
-
import { MaterialEnumControl } from '../../src';
|
|
37
|
-
|
|
38
|
-
Enzyme.configure({ adapter: new Adapter() });
|
|
39
|
-
|
|
40
|
-
const data = { nationality: 'JP' };
|
|
41
|
-
const schema = {
|
|
42
|
-
type: 'string',
|
|
43
|
-
enum: ['DE', 'IT', 'JP', 'US', 'RU', 'Other']
|
|
44
|
-
};
|
|
45
|
-
const uischema: ControlElement = {
|
|
46
|
-
type: 'Control',
|
|
47
|
-
scope: '#/properties/nationality',
|
|
48
|
-
options: {
|
|
49
|
-
autocomplete: false
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
describe('Material enum control', () => {
|
|
54
|
-
it('enum options should change when translation changes', () => {
|
|
55
|
-
const core = initCore(schema, uischema, data);
|
|
56
|
-
const translate = () => 'Translated';
|
|
57
|
-
const changedTranslate = () => 'OtherTranslation';
|
|
58
|
-
const wrapper = mount(
|
|
59
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core, i18n: {translate} }}>
|
|
60
|
-
<MaterialEnumControl
|
|
61
|
-
schema={schema}
|
|
62
|
-
uischema={uischema}
|
|
63
|
-
path='nationality'
|
|
64
|
-
/>
|
|
65
|
-
</JsonFormsStateProvider>
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(wrapper.find(MuiSelect).props().options[0].label).toBe('Translated');
|
|
69
|
-
|
|
70
|
-
wrapper.setProps({ initState: { renderers: materialRenderers, core, i18n: {translate: changedTranslate} }} );
|
|
71
|
-
wrapper.update();
|
|
72
|
-
|
|
73
|
-
expect(wrapper.find(MuiSelect).props().options[0].label).toBe('OtherTranslation');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,90 +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 Enzyme, { mount } from 'enzyme';
|
|
28
|
-
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
|
29
|
-
import MaterialGroupLayout from '../../src/layouts/MaterialGroupLayout';
|
|
30
|
-
import { MaterialLayoutRenderer } from '../../src/util/layout';
|
|
31
|
-
|
|
32
|
-
Enzyme.configure({ adapter: new Adapter() });
|
|
33
|
-
|
|
34
|
-
const schema = {
|
|
35
|
-
type: 'object',
|
|
36
|
-
properties: {
|
|
37
|
-
name: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
minLength: 3,
|
|
40
|
-
description: 'Please enter your name'
|
|
41
|
-
},
|
|
42
|
-
birthDate: {
|
|
43
|
-
type: 'string',
|
|
44
|
-
format: 'date',
|
|
45
|
-
description: 'Please enter your birth date.'
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const uischema = {
|
|
51
|
-
type: 'Group',
|
|
52
|
-
label: 'My Group',
|
|
53
|
-
elements: [
|
|
54
|
-
{
|
|
55
|
-
type: 'Control',
|
|
56
|
-
label: 'Name',
|
|
57
|
-
scope: '#/properties/name'
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
type: 'Control',
|
|
61
|
-
label: 'Birth Date',
|
|
62
|
-
scope: '#/properties/birthDate'
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
describe('Material group layout', () => {
|
|
68
|
-
it('should render a GroupComponent with direction column when given no direction LayoutProp', () => {
|
|
69
|
-
const wrapper = mount(
|
|
70
|
-
<MaterialGroupLayout schema={schema} uischema={uischema} direction="column" enabled visible path=""/>
|
|
71
|
-
);
|
|
72
|
-
expect(wrapper.find(MaterialLayoutRenderer).props().direction).toBe(
|
|
73
|
-
'column'
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should render a GroupComponent with direction row when this is provided as a direction prop', () => {
|
|
78
|
-
const wrapper = mount(
|
|
79
|
-
<MaterialGroupLayout
|
|
80
|
-
schema={schema}
|
|
81
|
-
uischema={uischema}
|
|
82
|
-
direction={'row'}
|
|
83
|
-
enabled
|
|
84
|
-
visible
|
|
85
|
-
path=""
|
|
86
|
-
/>
|
|
87
|
-
);
|
|
88
|
-
expect(wrapper.find(MaterialLayoutRenderer).props().direction).toBe('row');
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1,370 +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 Enzyme, { mount, ReactWrapper } from 'enzyme';
|
|
27
|
-
import { materialRenderers } from '../../src';
|
|
28
|
-
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
|
29
|
-
import * as React from 'react';
|
|
30
|
-
import {
|
|
31
|
-
ControlElement,
|
|
32
|
-
ControlProps,
|
|
33
|
-
ControlState,
|
|
34
|
-
HorizontalLayout,
|
|
35
|
-
isControl,
|
|
36
|
-
JsonSchema,
|
|
37
|
-
RankedTester,
|
|
38
|
-
rankWith,
|
|
39
|
-
} from '@jsonforms/core';
|
|
40
|
-
import { Control, JsonFormsStateProvider, withJsonFormsControlProps } from '@jsonforms/react';
|
|
41
|
-
import { MaterialInputControl } from '../../src/controls/MaterialInputControl';
|
|
42
|
-
import MaterialHorizontalLayoutRenderer from '../../src/layouts/MaterialHorizontalLayout';
|
|
43
|
-
import { MuiInputText } from '../../src/mui-controls';
|
|
44
|
-
import { initCore } from './util';
|
|
45
|
-
|
|
46
|
-
Enzyme.configure({ adapter: new Adapter() });
|
|
47
|
-
|
|
48
|
-
const data = { foo: 'bar' };
|
|
49
|
-
const schema = {
|
|
50
|
-
type: 'object',
|
|
51
|
-
properties: {
|
|
52
|
-
foo: {
|
|
53
|
-
type: 'string'
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const uischema: ControlElement = {
|
|
58
|
-
type: 'Control',
|
|
59
|
-
scope: '#/properties/foo'
|
|
60
|
-
};
|
|
61
|
-
class TestControlInner extends Control<ControlProps, ControlState> {
|
|
62
|
-
render() {
|
|
63
|
-
return <MaterialInputControl {...this.props} input={MuiInputText} />;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export const testControlTester: RankedTester = rankWith(1, isControl);
|
|
67
|
-
const TestControl = withJsonFormsControlProps(TestControlInner);
|
|
68
|
-
|
|
69
|
-
describe('Material input control', () => {
|
|
70
|
-
let wrapper: ReactWrapper;
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
wrapper.unmount();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('render', () => {
|
|
77
|
-
const core = initCore(schema, uischema, data);
|
|
78
|
-
wrapper = mount(
|
|
79
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
80
|
-
<TestControl
|
|
81
|
-
schema={schema}
|
|
82
|
-
uischema={uischema}
|
|
83
|
-
/>
|
|
84
|
-
</JsonFormsStateProvider>
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const control = wrapper.find('div').first();
|
|
88
|
-
expect(control.children()).toHaveLength(4);
|
|
89
|
-
|
|
90
|
-
const label = wrapper.find('label');
|
|
91
|
-
expect(label.text()).toBe('Foo');
|
|
92
|
-
|
|
93
|
-
const inputs = wrapper.find('input');
|
|
94
|
-
expect(inputs).toHaveLength(1);
|
|
95
|
-
|
|
96
|
-
const validation = wrapper.find('p').first();
|
|
97
|
-
expect(validation.props().className).toContain('MuiFormHelperText-root');
|
|
98
|
-
expect(validation.children()).toHaveLength(0);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should render without label', () => {
|
|
102
|
-
const control: ControlElement = {
|
|
103
|
-
type: 'Control',
|
|
104
|
-
scope: '#/properties/foo',
|
|
105
|
-
label: false
|
|
106
|
-
};
|
|
107
|
-
const core = initCore(schema, uischema);
|
|
108
|
-
wrapper = mount(
|
|
109
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
110
|
-
<TestControl schema={schema} uischema={control} />
|
|
111
|
-
</JsonFormsStateProvider>
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const div = wrapper.find('div').first();
|
|
115
|
-
expect(div.children()).toHaveLength(4);
|
|
116
|
-
|
|
117
|
-
const label = wrapper.find('label');
|
|
118
|
-
expect(label.text()).toBe('');
|
|
119
|
-
|
|
120
|
-
const inputs = wrapper.find('input');
|
|
121
|
-
expect(inputs).toHaveLength(1);
|
|
122
|
-
|
|
123
|
-
const validation = wrapper.find('p').first();
|
|
124
|
-
expect(validation.props().className).toContain('MuiFormHelperText-root');
|
|
125
|
-
expect(validation.children()).toHaveLength(0);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('can be hidden', () => {
|
|
129
|
-
const core = initCore(schema, uischema, data);
|
|
130
|
-
wrapper = mount(
|
|
131
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
132
|
-
<TestControl schema={schema} uischema={uischema} visible={false} />
|
|
133
|
-
</JsonFormsStateProvider>
|
|
134
|
-
);
|
|
135
|
-
const inputs = wrapper.find('input');
|
|
136
|
-
expect(inputs.length).toBe(0);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should be shown by default', () => {
|
|
140
|
-
const core = initCore(schema, uischema, data);
|
|
141
|
-
wrapper = mount(
|
|
142
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
143
|
-
<TestControl schema={schema} uischema={uischema} />
|
|
144
|
-
</JsonFormsStateProvider>
|
|
145
|
-
);
|
|
146
|
-
const control = wrapper.find('div').first();
|
|
147
|
-
expect(control.props().hidden).toBeFalsy();
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('should display a single error', () => {
|
|
151
|
-
const core = initCore(schema, uischema, data );
|
|
152
|
-
wrapper = mount(
|
|
153
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
154
|
-
<TestControl schema={schema} uischema={uischema} />
|
|
155
|
-
</JsonFormsStateProvider>
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
core.data = { ...core.data, foo: 2 };
|
|
159
|
-
wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
|
|
160
|
-
wrapper.update();
|
|
161
|
-
const validation = wrapper.find('p').first();
|
|
162
|
-
expect(validation.text()).toBe('must be string');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should display multiple errors', () => {
|
|
166
|
-
const core = initCore(schema, uischema, data);
|
|
167
|
-
wrapper = mount(
|
|
168
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
169
|
-
<TestControl schema={schema} uischema={uischema} />
|
|
170
|
-
</JsonFormsStateProvider>
|
|
171
|
-
);
|
|
172
|
-
core.data = { ...core.data, foo: 3 };
|
|
173
|
-
wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
|
|
174
|
-
wrapper.update();
|
|
175
|
-
const validation = wrapper.find('p').first();
|
|
176
|
-
expect(validation.text()).toBe('must be string');
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should not show any errors', () => {
|
|
180
|
-
const core = initCore(schema, uischema, data);
|
|
181
|
-
wrapper = mount(
|
|
182
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
183
|
-
<TestControl schema={schema} uischema={uischema} />
|
|
184
|
-
</JsonFormsStateProvider>
|
|
185
|
-
);
|
|
186
|
-
const validation = wrapper.find('p').first();
|
|
187
|
-
expect(validation.text()).toBe('');
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('should handle validation updates', () => {
|
|
191
|
-
const core = initCore(schema, uischema, data);
|
|
192
|
-
wrapper = mount(
|
|
193
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
194
|
-
<TestControl schema={schema} uischema={uischema} />
|
|
195
|
-
</JsonFormsStateProvider>
|
|
196
|
-
);
|
|
197
|
-
core.data = { ...core.data, foo: 3 };
|
|
198
|
-
core.data = { ...core.data, foo: 'bar' };
|
|
199
|
-
wrapper.setProps({ initState: { renderers: materialRenderers, core }} );
|
|
200
|
-
wrapper.update();
|
|
201
|
-
const validation = wrapper.find('p').first();
|
|
202
|
-
expect(validation.text()).toBe('');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('should handle validation with nested schemas', () => {
|
|
206
|
-
const jsonSchema = {
|
|
207
|
-
type: 'object',
|
|
208
|
-
properties: {
|
|
209
|
-
name: {
|
|
210
|
-
type: 'string'
|
|
211
|
-
},
|
|
212
|
-
personalData: {
|
|
213
|
-
type: 'object',
|
|
214
|
-
properties: {
|
|
215
|
-
middleName: {
|
|
216
|
-
type: 'string'
|
|
217
|
-
},
|
|
218
|
-
lastName: {
|
|
219
|
-
type: 'string'
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
required: ['middleName', 'lastName']
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
required: ['name']
|
|
226
|
-
};
|
|
227
|
-
const firstControlElement: ControlElement = {
|
|
228
|
-
type: 'Control',
|
|
229
|
-
scope: '#/properties/name'
|
|
230
|
-
};
|
|
231
|
-
const secondControlElement: ControlElement = {
|
|
232
|
-
type: 'Control',
|
|
233
|
-
scope: '#/properties/personalData/properties/middleName'
|
|
234
|
-
};
|
|
235
|
-
const thirdControlElement: ControlElement = {
|
|
236
|
-
type: 'Control',
|
|
237
|
-
scope: '#/properties/personalData/properties/lastName'
|
|
238
|
-
};
|
|
239
|
-
const layout: HorizontalLayout = {
|
|
240
|
-
type: 'HorizontalLayout',
|
|
241
|
-
elements: [firstControlElement, secondControlElement, thirdControlElement]
|
|
242
|
-
};
|
|
243
|
-
const newData = {
|
|
244
|
-
name: 'John Doe',
|
|
245
|
-
personalData: {}
|
|
246
|
-
};
|
|
247
|
-
const core = initCore(jsonSchema, layout, newData);
|
|
248
|
-
wrapper = mount(
|
|
249
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }} >
|
|
250
|
-
<MaterialHorizontalLayoutRenderer
|
|
251
|
-
schema={jsonSchema}
|
|
252
|
-
uischema={layout}
|
|
253
|
-
direction="row"
|
|
254
|
-
enabled
|
|
255
|
-
visible
|
|
256
|
-
path=""
|
|
257
|
-
/>
|
|
258
|
-
</ JsonFormsStateProvider>
|
|
259
|
-
);
|
|
260
|
-
const validation = wrapper.find('p');
|
|
261
|
-
expect(validation).toHaveLength(6);
|
|
262
|
-
expect(validation.at(0).text()).toBe('');
|
|
263
|
-
expect(validation.at(2).text()).toBe('is a required property');
|
|
264
|
-
expect(validation.at(4).text()).toBe('is a required property');
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('should display a marker for a required prop', () => {
|
|
268
|
-
const jsonSchema: JsonSchema = {
|
|
269
|
-
type: 'object',
|
|
270
|
-
properties: {
|
|
271
|
-
dateCell: {
|
|
272
|
-
type: 'string',
|
|
273
|
-
format: 'date'
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
required: ['dateCell']
|
|
277
|
-
};
|
|
278
|
-
const control: ControlElement = {
|
|
279
|
-
type: 'Control',
|
|
280
|
-
scope: '#/properties/dateCell'
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
const core = initCore(jsonSchema, control, {});
|
|
284
|
-
wrapper = mount(
|
|
285
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
286
|
-
<TestControl schema={jsonSchema} uischema={control} />
|
|
287
|
-
</JsonFormsStateProvider>
|
|
288
|
-
);
|
|
289
|
-
const label = wrapper.find('label').first();
|
|
290
|
-
expect(label.text()).toBe('Date Cell *');
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('should not display a marker for a non-required prop', () => {
|
|
294
|
-
const jsonSchema: JsonSchema = {
|
|
295
|
-
type: 'object',
|
|
296
|
-
properties: {
|
|
297
|
-
dateCell: {
|
|
298
|
-
type: 'string',
|
|
299
|
-
format: 'date'
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
const control: ControlElement = {
|
|
304
|
-
type: 'Control',
|
|
305
|
-
scope: '#/properties/dateCell'
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
const core = initCore(jsonSchema, control, {});
|
|
309
|
-
wrapper = mount(
|
|
310
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
311
|
-
<TestControl schema={jsonSchema} uischema={control} />
|
|
312
|
-
</JsonFormsStateProvider>
|
|
313
|
-
);
|
|
314
|
-
const label = wrapper.find('label').first();
|
|
315
|
-
expect(label.text()).toBe('Date Cell');
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it('should display a password cell if the password option is set', () => {
|
|
319
|
-
const jsonSchema = {
|
|
320
|
-
type: 'object',
|
|
321
|
-
properties: {
|
|
322
|
-
password: { type: 'string' }
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
const control: ControlElement = {
|
|
326
|
-
type: 'Control',
|
|
327
|
-
scope: '#/properties/password',
|
|
328
|
-
options: { format: 'password' }
|
|
329
|
-
};
|
|
330
|
-
const core = initCore(jsonSchema, control, {});
|
|
331
|
-
wrapper = mount(
|
|
332
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
333
|
-
<TestControl schema={jsonSchema} uischema={control} />
|
|
334
|
-
</JsonFormsStateProvider>
|
|
335
|
-
);
|
|
336
|
-
const input = wrapper.find('input');
|
|
337
|
-
expect(input.props().type).toBe('password');
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
it('should render own id and create/use input id', () => {
|
|
341
|
-
const jsonSchema = {
|
|
342
|
-
type: 'object',
|
|
343
|
-
properties: {
|
|
344
|
-
name: { type: 'string' }
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
const control: ControlElement = {
|
|
348
|
-
type: 'Control',
|
|
349
|
-
scope: '#/properties/name'
|
|
350
|
-
};
|
|
351
|
-
const core = initCore(jsonSchema, control, {});
|
|
352
|
-
wrapper = mount(
|
|
353
|
-
<JsonFormsStateProvider initState={{ renderers: materialRenderers, core }}>
|
|
354
|
-
<TestControl
|
|
355
|
-
schema={jsonSchema}
|
|
356
|
-
uischema={control}
|
|
357
|
-
id={control.scope}
|
|
358
|
-
/>
|
|
359
|
-
</JsonFormsStateProvider>
|
|
360
|
-
);
|
|
361
|
-
const input = wrapper.find('input').first();
|
|
362
|
-
expect(input.props().id).toBe('#/properties/name-input');
|
|
363
|
-
|
|
364
|
-
const label = wrapper.find('label').first();
|
|
365
|
-
expect(label.props().htmlFor).toBe('#/properties/name-input');
|
|
366
|
-
|
|
367
|
-
const rootDiv = wrapper.find('div').first();
|
|
368
|
-
expect(rootDiv.props().id).toBe('#/properties/name');
|
|
369
|
-
});
|
|
370
|
-
});
|