@jsonforms/core 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 +3 -3
- package/lib/Helpers.d.ts +1 -1
- package/lib/actions/actions.d.ts +27 -26
- package/lib/generators/Generate.d.ts +1 -1
- package/lib/generators/schema.d.ts +1 -1
- package/lib/i18n/arrayTranslations.d.ts +24 -0
- package/lib/i18n/i18nTypes.d.ts +3 -2
- package/lib/i18n/i18nUtil.d.ts +5 -2
- package/lib/i18n/index.d.ts +1 -0
- package/lib/jsonforms-core.cjs.js +428 -259
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +313 -200
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/models/jsonSchema.d.ts +2 -2
- package/lib/models/uischema.d.ts +1 -1
- package/lib/reducers/cells.d.ts +2 -2
- package/lib/reducers/config.d.ts +1 -1
- package/lib/reducers/core.d.ts +3 -2
- package/lib/reducers/default-data.d.ts +1 -1
- package/lib/reducers/i18n.d.ts +1 -1
- package/lib/reducers/reducers.d.ts +4 -4
- package/lib/reducers/renderers.d.ts +2 -2
- package/lib/reducers/selectors.d.ts +6 -6
- package/lib/reducers/uischemas.d.ts +2 -2
- package/lib/store.d.ts +3 -3
- package/lib/testers/testers.d.ts +1 -1
- package/lib/util/cell.d.ts +3 -4
- package/lib/util/combinators.d.ts +1 -1
- package/lib/util/label.d.ts +1 -1
- package/lib/util/path.d.ts +6 -3
- package/lib/util/renderer.d.ts +11 -7
- package/lib/util/resolvers.d.ts +1 -1
- package/lib/util/runtime.d.ts +2 -2
- package/lib/util/util.d.ts +2 -2
- package/lib/util/validator.d.ts +1 -1
- package/package.json +16 -5
- package/src/Helpers.ts +2 -2
- package/src/actions/actions.ts +59 -61
- package/src/configDefault.ts +1 -1
- package/src/generators/Generate.ts +4 -2
- package/src/generators/schema.ts +30 -26
- package/src/generators/uischema.ts +7 -6
- package/src/i18n/arrayTranslations.ts +54 -0
- package/src/i18n/i18nTypes.ts +12 -7
- package/src/i18n/i18nUtil.ts +66 -16
- package/src/i18n/index.ts +1 -0
- package/src/models/draft4.ts +33 -33
- package/src/models/jsonSchema.ts +2 -2
- package/src/models/uischema.ts +18 -7
- package/src/reducers/cells.ts +10 -9
- package/src/reducers/config.ts +1 -1
- package/src/reducers/core.ts +115 -75
- package/src/reducers/default-data.ts +8 -8
- package/src/reducers/i18n.ts +22 -10
- package/src/reducers/reducers.ts +24 -34
- package/src/reducers/renderers.ts +9 -9
- package/src/reducers/selectors.ts +10 -11
- package/src/reducers/uischemas.ts +27 -26
- package/src/store.ts +4 -4
- package/src/testers/testers.ts +200 -147
- package/src/util/cell.ts +27 -29
- package/src/util/combinators.ts +6 -4
- package/src/util/label.ts +2 -2
- package/src/util/path.ts +15 -8
- package/src/util/renderer.ts +123 -72
- package/src/util/resolvers.ts +16 -14
- package/src/util/runtime.ts +4 -4
- package/src/util/schema.ts +1 -1
- package/src/util/type.ts +5 -3
- package/src/util/uischema.ts +9 -9
- package/src/util/util.ts +54 -54
- package/src/util/validator.ts +2 -2
- package/.nycrc +0 -6
- 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/gen.html +0 -406
- package/docs/enums/ruleeffect.html +0 -214
- package/docs/globals.html +0 -10568
- package/docs/index.html +0 -1297
- package/docs/interfaces/action.html +0 -166
- package/docs/interfaces/addcellrendereraction.html +0 -181
- package/docs/interfaces/addrendereraction.html +0 -181
- package/docs/interfaces/adduischemaaction.html +0 -181
- package/docs/interfaces/andcondition.html +0 -181
- package/docs/interfaces/anyaction.html +0 -189
- package/docs/interfaces/arraycontrolprops.html +0 -653
- package/docs/interfaces/arraylayoutprops.html +0 -648
- package/docs/interfaces/categorization.html +0 -281
- package/docs/interfaces/category.html +0 -279
- package/docs/interfaces/cellprops.html +0 -452
- package/docs/interfaces/combinatorrendererprops.html +0 -503
- package/docs/interfaces/combinatorsubschemarenderinfo.html +0 -181
- package/docs/interfaces/composablecondition.html +0 -193
- package/docs/interfaces/condition.html +0 -176
- package/docs/interfaces/controlelement.html +0 -280
- package/docs/interfaces/controlprops.html +0 -497
- package/docs/interfaces/controlstate.html +0 -184
- package/docs/interfaces/controlwithdetailprops.html +0 -501
- package/docs/interfaces/dispatchcellprops.html +0 -388
- package/docs/interfaces/dispatchcellstateprops.html +0 -408
- package/docs/interfaces/dispatchpropsofarraycontrol.html +0 -322
- package/docs/interfaces/dispatchpropsofcontrol.html +0 -204
- package/docs/interfaces/dispatchpropsofmultienumcontrol.html +0 -215
- package/docs/interfaces/enumcellprops.html +0 -467
- package/docs/interfaces/enumoption.html +0 -167
- package/docs/interfaces/formatted.html +0 -226
- package/docs/interfaces/grouplayout.html +0 -284
- package/docs/interfaces/horizontallayout.html +0 -234
- package/docs/interfaces/initaction.html +0 -209
- package/docs/interfaces/initactionoptions.html +0 -181
- package/docs/interfaces/internationalizable.html +0 -170
- package/docs/interfaces/jsonformscellrendererregistryentry.html +0 -167
- package/docs/interfaces/jsonformscore.html +0 -251
- package/docs/interfaces/jsonformsdefaultdataregistryentry.html +0 -167
- package/docs/interfaces/jsonformsextendedstate.html +0 -175
- package/docs/interfaces/jsonformsi18nstate.html +0 -181
- package/docs/interfaces/jsonformsprops.html +0 -321
- package/docs/interfaces/jsonformsrendererregistryentry.html +0 -167
- package/docs/interfaces/jsonformsstate.html +0 -170
- package/docs/interfaces/jsonformsstore.html +0 -376
- package/docs/interfaces/jsonformssubstates.html +0 -276
- package/docs/interfaces/jsonformsuischemaregistryentry.html +0 -167
- package/docs/interfaces/jsonschema4.html +0 -758
- package/docs/interfaces/jsonschema7.html +0 -884
- package/docs/interfaces/labelable.html +0 -184
- package/docs/interfaces/labeldescription.html +0 -184
- package/docs/interfaces/labeled.html +0 -182
- package/docs/interfaces/labelelement.html +0 -251
- package/docs/interfaces/labelprops.html +0 -339
- package/docs/interfaces/layout.html +0 -253
- package/docs/interfaces/layoutprops.html +0 -359
- package/docs/interfaces/leafcondition.html +0 -209
- package/docs/interfaces/orcondition.html +0 -181
- package/docs/interfaces/ownpropsofcell.html +0 -321
- package/docs/interfaces/ownpropsofcontrol.html +0 -305
- package/docs/interfaces/ownpropsofenum.html +0 -161
- package/docs/interfaces/ownpropsofenumcell.html +0 -335
- package/docs/interfaces/ownpropsofjsonformsrenderer.html +0 -296
- package/docs/interfaces/ownpropsoflabel.html +0 -286
- package/docs/interfaces/ownpropsoflayout.html +0 -305
- package/docs/interfaces/ownpropsofmasterlistitem.html +0 -289
- package/docs/interfaces/ownpropsofrenderer.html +0 -292
- package/docs/interfaces/referenceschemamap.html +0 -138
- package/docs/interfaces/registerdefaultdataaction.html +0 -181
- package/docs/interfaces/removecellrendereraction.html +0 -181
- package/docs/interfaces/removerendereraction.html +0 -181
- package/docs/interfaces/removeuischemaaction.html +0 -167
- package/docs/interfaces/rendererprops.html +0 -331
- package/docs/interfaces/rule.html +0 -185
- package/docs/interfaces/schemabasedcondition.html +0 -202
- package/docs/interfaces/scopable.html +0 -171
- package/docs/interfaces/scoped.html +0 -183
- package/docs/interfaces/setajvaction.html +0 -167
- package/docs/interfaces/setconfigaction.html +0 -167
- package/docs/interfaces/setlocaleaction.html +0 -167
- package/docs/interfaces/setschemaaction.html +0 -167
- package/docs/interfaces/settranslatoraction.html +0 -181
- package/docs/interfaces/setuischemaaction.html +0 -167
- package/docs/interfaces/setvalidationmodeaction.html +0 -167
- package/docs/interfaces/statepropsofarraycontrol.html +0 -474
- package/docs/interfaces/statepropsofarraylayout.html +0 -461
- package/docs/interfaces/statepropsofcell.html +0 -408
- package/docs/interfaces/statepropsofcombinator.html +0 -449
- package/docs/interfaces/statepropsofcontrol.html +0 -451
- package/docs/interfaces/statepropsofcontrolwithdetail.html +0 -463
- package/docs/interfaces/statepropsofenumcell.html +0 -422
- package/docs/interfaces/statepropsofjsonformsrenderer.html +0 -324
- package/docs/interfaces/statepropsoflabel.html +0 -343
- package/docs/interfaces/statepropsoflayout.html +0 -369
- package/docs/interfaces/statepropsofmasteritem.html +0 -309
- package/docs/interfaces/statepropsofrenderer.html +0 -331
- package/docs/interfaces/statepropsofscopedrenderer.html +0 -391
- package/docs/interfaces/store.html +0 -386
- package/docs/interfaces/testercontext.html +0 -184
- package/docs/interfaces/uischemaelement.html +0 -225
- package/docs/interfaces/unregisterdefaultdataaction.html +0 -167
- package/docs/interfaces/updateaction.html +0 -202
- package/docs/interfaces/updatecoreaction.html +0 -209
- package/docs/interfaces/updateerrorsaction.html +0 -167
- package/docs/interfaces/updatei18naction.html +0 -195
- package/docs/interfaces/verticallayout.html +0 -234
- package/docs/interfaces/withclassname.html +0 -153
- package/rollup.config.js +0 -44
- package/stats.html +0 -3279
- package/test/actions/actions.test.ts +0 -93
- package/test/generators/schema.test.ts +0 -224
- package/test/generators/uischema.test.ts +0 -576
- package/test/i18n/i18nUtil.test.ts +0 -88
- package/test/reducers/core.test.ts +0 -1682
- package/test/reducers/uischemas.test.ts +0 -173
- package/test/testers.test.ts +0 -948
- package/test/util/array.test.ts +0 -28
- package/test/util/cell.test.ts +0 -354
- package/test/util/derivetype.test.ts +0 -101
- package/test/util/label.test.ts +0 -364
- package/test/util/path.test.ts +0 -259
- package/test/util/renderer.test.ts +0 -1830
- package/test/util/resolvers.test.ts +0 -157
- package/test/util/runtime.test.ts +0 -779
- package/tsconfig.json +0 -13
|
@@ -1,1830 +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 * as _ from 'lodash';
|
|
26
|
-
import * as Redux from 'redux';
|
|
27
|
-
import configureStore from 'redux-mock-store';
|
|
28
|
-
import test from 'ava';
|
|
29
|
-
|
|
30
|
-
import { ErrorObject } from 'ajv';
|
|
31
|
-
import { JsonFormsState } from '../../src/store';
|
|
32
|
-
import { coreReducer, JsonFormsCore } from '../../src/reducers/core';
|
|
33
|
-
import { Dispatch } from '../../src/util/type';
|
|
34
|
-
import { CoreActions, init, setValidationMode, update, UpdateAction, UPDATE_DATA } from '../../src/actions/actions';
|
|
35
|
-
import { ControlElement, LabelElement, RuleEffect, UISchemaElement } from '../../src/models/uischema';
|
|
36
|
-
import { computeLabel, createDefaultValue, mapDispatchToArrayControlProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAnyOfProps, mapStateToArrayLayoutProps, mapStateToControlProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLabelProps, mapStateToLayoutProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, OwnPropsOfControl } from '../../src/util/renderer';
|
|
37
|
-
import { clearAllIds } from '../../src/util/ids';
|
|
38
|
-
import { JsonSchema } from '../../src/models/jsonSchema';
|
|
39
|
-
import { rankWith } from '../../src/testers/testers';
|
|
40
|
-
import { createAjv } from '../../src/util/validator';
|
|
41
|
-
import { JsonSchema7 } from '../../src/models/jsonSchema7';
|
|
42
|
-
import { defaultJsonFormsI18nState } from '../../src/reducers/i18n';
|
|
43
|
-
import { i18nJsonSchema } from '../../src/i18n/i18nTypes';
|
|
44
|
-
|
|
45
|
-
const middlewares: Redux.Middleware[] = [];
|
|
46
|
-
const mockStore = configureStore<JsonFormsState>(middlewares);
|
|
47
|
-
|
|
48
|
-
const mockDispatch = (
|
|
49
|
-
initialCore: JsonFormsCore
|
|
50
|
-
): [() => JsonFormsCore, Dispatch<CoreActions>] => {
|
|
51
|
-
const coreContainer = { core: initialCore };
|
|
52
|
-
const dispatch: Dispatch<CoreActions> = <T extends CoreActions> (action: T) : T => {
|
|
53
|
-
coreContainer.core = coreReducer(coreContainer.core, action);
|
|
54
|
-
return action;
|
|
55
|
-
};
|
|
56
|
-
const getCore = () => coreContainer.core;
|
|
57
|
-
return [getCore, dispatch];
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const hideRule = {
|
|
61
|
-
effect: RuleEffect.HIDE,
|
|
62
|
-
condition: {
|
|
63
|
-
type: 'LEAF',
|
|
64
|
-
scope: '#/properties/firstName',
|
|
65
|
-
expectedValue: 'Homer'
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const disableRule = {
|
|
70
|
-
effect: RuleEffect.DISABLE,
|
|
71
|
-
condition: {
|
|
72
|
-
type: 'LEAF',
|
|
73
|
-
scope: '#/properties/firstName',
|
|
74
|
-
expectedValue: 'Homer'
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const enableRule = {
|
|
79
|
-
effect: RuleEffect.ENABLE,
|
|
80
|
-
condition: {
|
|
81
|
-
type: 'LEAF',
|
|
82
|
-
scope: '#/properties/firstName',
|
|
83
|
-
expectedValue: 'Homer'
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const coreUISchema: ControlElement = {
|
|
88
|
-
type: 'Control',
|
|
89
|
-
scope: '#/properties/firstName'
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const createState = (uischema: UISchemaElement) => ({
|
|
93
|
-
jsonforms: {
|
|
94
|
-
core: {
|
|
95
|
-
schema: {
|
|
96
|
-
type: 'object',
|
|
97
|
-
properties: {
|
|
98
|
-
firstName: { type: 'string' },
|
|
99
|
-
lastName: { type: 'string' }
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
data: {
|
|
103
|
-
firstName: 'Homer'
|
|
104
|
-
},
|
|
105
|
-
uischema,
|
|
106
|
-
errors: [] as ErrorObject[]
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('mapStateToControlProps - visible via ownProps ', t => {
|
|
112
|
-
const uischema = {
|
|
113
|
-
...coreUISchema,
|
|
114
|
-
rule: hideRule
|
|
115
|
-
};
|
|
116
|
-
const ownProps = {
|
|
117
|
-
visible: true,
|
|
118
|
-
uischema
|
|
119
|
-
};
|
|
120
|
-
const props = mapStateToControlProps(createState(uischema), ownProps);
|
|
121
|
-
t.false(props.visible);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('mapStateToControlProps - hidden via ownProps ', t => {
|
|
125
|
-
const uischema = {
|
|
126
|
-
...coreUISchema,
|
|
127
|
-
rule: hideRule
|
|
128
|
-
};
|
|
129
|
-
const ownProps = {
|
|
130
|
-
visible: false,
|
|
131
|
-
uischema
|
|
132
|
-
};
|
|
133
|
-
const props = mapStateToControlProps(createState(uischema), ownProps);
|
|
134
|
-
t.false(props.visible);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('mapStateToControlProps - hidden via state ', t => {
|
|
138
|
-
const uischema = {
|
|
139
|
-
...coreUISchema,
|
|
140
|
-
rule: hideRule
|
|
141
|
-
};
|
|
142
|
-
const ownProps = {
|
|
143
|
-
uischema
|
|
144
|
-
};
|
|
145
|
-
const props = mapStateToControlProps(createState(uischema), ownProps);
|
|
146
|
-
t.false(props.visible);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test('mapStateToControlProps - visible via state ', t => {
|
|
150
|
-
const uischema = {
|
|
151
|
-
...coreUISchema,
|
|
152
|
-
rule: hideRule
|
|
153
|
-
};
|
|
154
|
-
const ownProps = {
|
|
155
|
-
uischema
|
|
156
|
-
};
|
|
157
|
-
const clonedState = _.cloneDeep(createState(uischema));
|
|
158
|
-
clonedState.jsonforms.core.data.firstName = 'Lisa';
|
|
159
|
-
const props = mapStateToControlProps(clonedState, ownProps);
|
|
160
|
-
t.true(props.visible);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('mapStateToControlProps - visible via state with path from ownProps ', t => {
|
|
164
|
-
const uischema = {
|
|
165
|
-
...coreUISchema,
|
|
166
|
-
rule: hideRule
|
|
167
|
-
};
|
|
168
|
-
const ownProps = {
|
|
169
|
-
uischema,
|
|
170
|
-
path: 'foo'
|
|
171
|
-
};
|
|
172
|
-
const state = {
|
|
173
|
-
jsonforms: {
|
|
174
|
-
core: {
|
|
175
|
-
schema: {
|
|
176
|
-
type: 'object',
|
|
177
|
-
properties: {
|
|
178
|
-
firstName: { type: 'string' },
|
|
179
|
-
lastName: { type: 'string' }
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
data: {
|
|
183
|
-
foo: { firstName: 'Lisa' }
|
|
184
|
-
},
|
|
185
|
-
uischema,
|
|
186
|
-
errors: [] as ErrorObject[]
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
191
|
-
t.true(props.visible);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('mapStateToControlProps - disabled via global readonly', t => {
|
|
195
|
-
const ownProps = {
|
|
196
|
-
uischema: coreUISchema
|
|
197
|
-
};
|
|
198
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
199
|
-
state.jsonforms.readonly = true;
|
|
200
|
-
|
|
201
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
202
|
-
t.false(props.enabled);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test('mapStateToControlProps - disabled via global readonly beats enabled via ownProps', t => {
|
|
206
|
-
const ownProps = {
|
|
207
|
-
uischema: coreUISchema,
|
|
208
|
-
enabled: true
|
|
209
|
-
};
|
|
210
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
211
|
-
state.jsonforms.readonly = true;
|
|
212
|
-
|
|
213
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
214
|
-
t.false(props.enabled);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test('mapStateToControlProps - disabled via global readonly beats enabled via rule', t => {
|
|
218
|
-
const uischema = {
|
|
219
|
-
...coreUISchema,
|
|
220
|
-
rule: enableRule
|
|
221
|
-
};
|
|
222
|
-
const ownProps = {
|
|
223
|
-
uischema
|
|
224
|
-
};
|
|
225
|
-
const state: JsonFormsState = createState(uischema);
|
|
226
|
-
state.jsonforms.readonly = true;
|
|
227
|
-
|
|
228
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
229
|
-
t.false(props.enabled);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
test('mapStateToControlProps - enabled via state with path from ownProps ', t => {
|
|
233
|
-
const uischema = {
|
|
234
|
-
...coreUISchema,
|
|
235
|
-
rule: disableRule
|
|
236
|
-
};
|
|
237
|
-
const ownProps = {
|
|
238
|
-
visible: true,
|
|
239
|
-
uischema,
|
|
240
|
-
path: 'foo'
|
|
241
|
-
};
|
|
242
|
-
const state = {
|
|
243
|
-
jsonforms: {
|
|
244
|
-
core: {
|
|
245
|
-
schema: {
|
|
246
|
-
type: 'object',
|
|
247
|
-
properties: {
|
|
248
|
-
firstName: { type: 'string' },
|
|
249
|
-
lastName: { type: 'string' }
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
data: {
|
|
253
|
-
foo: { firstName: 'Lisa' }
|
|
254
|
-
},
|
|
255
|
-
uischema,
|
|
256
|
-
errors: [] as ErrorObject[]
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
261
|
-
t.true(props.enabled);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
test('mapStateToControlProps - enabled via ownProps ', t => {
|
|
265
|
-
const uischema = {
|
|
266
|
-
...coreUISchema,
|
|
267
|
-
rule: disableRule
|
|
268
|
-
};
|
|
269
|
-
const ownProps = {
|
|
270
|
-
enabled: true,
|
|
271
|
-
uischema
|
|
272
|
-
};
|
|
273
|
-
const props = mapStateToControlProps(createState(uischema), ownProps);
|
|
274
|
-
t.false(props.enabled);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
test('mapStateToControlProps - disabled via ownProps ', t => {
|
|
278
|
-
const uischema = {
|
|
279
|
-
...coreUISchema,
|
|
280
|
-
rule: disableRule
|
|
281
|
-
};
|
|
282
|
-
const ownProps = {
|
|
283
|
-
enabled: false,
|
|
284
|
-
uischema
|
|
285
|
-
};
|
|
286
|
-
const props = mapStateToControlProps(createState(uischema), ownProps);
|
|
287
|
-
t.false(props.enabled);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
test('mapStateToControlProps - disabled via state ', t => {
|
|
291
|
-
const uischema = {
|
|
292
|
-
...coreUISchema,
|
|
293
|
-
rule: disableRule
|
|
294
|
-
};
|
|
295
|
-
const ownProps = {
|
|
296
|
-
uischema
|
|
297
|
-
};
|
|
298
|
-
const props = mapStateToControlProps(createState(uischema), ownProps);
|
|
299
|
-
t.false(props.enabled);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
test('mapStateToControlProps - enabled via state ', t => {
|
|
303
|
-
const uischema = {
|
|
304
|
-
...coreUISchema,
|
|
305
|
-
rule: disableRule
|
|
306
|
-
};
|
|
307
|
-
const ownProps = {
|
|
308
|
-
uischema
|
|
309
|
-
};
|
|
310
|
-
const clonedState = _.cloneDeep(createState(uischema));
|
|
311
|
-
clonedState.jsonforms.core.data.firstName = 'Lisa';
|
|
312
|
-
const props = mapStateToControlProps(clonedState, ownProps);
|
|
313
|
-
t.true(props.enabled);
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
test('mapStateToControlProps - path', t => {
|
|
317
|
-
const ownProps = {
|
|
318
|
-
uischema: coreUISchema
|
|
319
|
-
};
|
|
320
|
-
const props = mapStateToControlProps(createState(coreUISchema), ownProps);
|
|
321
|
-
t.is(props.path, 'firstName');
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
test('mapStateToControlProps - compose path with ownProps.path', t => {
|
|
325
|
-
const ownProps = {
|
|
326
|
-
uischema: coreUISchema,
|
|
327
|
-
path: 'yo'
|
|
328
|
-
};
|
|
329
|
-
const props = mapStateToControlProps(createState(coreUISchema), ownProps);
|
|
330
|
-
t.is(props.path, 'yo.firstName');
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
test('mapStateToControlProps - derive label', t => {
|
|
334
|
-
const ownProps = {
|
|
335
|
-
uischema: coreUISchema
|
|
336
|
-
};
|
|
337
|
-
const props = mapStateToControlProps(createState(coreUISchema), ownProps);
|
|
338
|
-
t.is(props.label, 'First Name');
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
test('mapStateToControlProps - do not show label', t => {
|
|
342
|
-
const ownProps = {
|
|
343
|
-
uischema: {
|
|
344
|
-
...coreUISchema,
|
|
345
|
-
label: {
|
|
346
|
-
show: false
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
const props = mapStateToControlProps(createState(coreUISchema), ownProps);
|
|
351
|
-
t.is(props.label, '');
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
test('mapStateToControlProps - data', t => {
|
|
355
|
-
const ownProps = {
|
|
356
|
-
uischema: coreUISchema
|
|
357
|
-
};
|
|
358
|
-
const props = mapStateToControlProps(createState(coreUISchema), ownProps);
|
|
359
|
-
t.is(props.data, 'Homer');
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
test('mapStateToControlProps - errors', t => {
|
|
363
|
-
const ownProps = {
|
|
364
|
-
uischema: coreUISchema
|
|
365
|
-
};
|
|
366
|
-
const clonedState = _.cloneDeep(createState(coreUISchema));
|
|
367
|
-
const error: ErrorObject = {
|
|
368
|
-
instancePath: '/firstName',
|
|
369
|
-
message: 'Duff beer',
|
|
370
|
-
keyword: 'whatever',
|
|
371
|
-
schemaPath: '',
|
|
372
|
-
params: undefined,
|
|
373
|
-
parentSchema: { type: 'string' }
|
|
374
|
-
};
|
|
375
|
-
clonedState.jsonforms.core.errors = [error];
|
|
376
|
-
const props = mapStateToControlProps(clonedState, ownProps);
|
|
377
|
-
t.is(props.errors, 'Duff beer');
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
test('mapStateToControlProps - no duplicate error messages', t => {
|
|
381
|
-
const schema = {
|
|
382
|
-
type: 'object',
|
|
383
|
-
properties: {
|
|
384
|
-
firstName: {
|
|
385
|
-
anyOf: [
|
|
386
|
-
{ type: 'string', minLength: 5 },
|
|
387
|
-
{ type: 'string', enum: ['foo', 'bar'] }
|
|
388
|
-
]
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
const initCoreState = coreReducer(undefined, init({}, schema, coreUISchema));
|
|
393
|
-
const updateCoreState = coreReducer(
|
|
394
|
-
initCoreState,
|
|
395
|
-
update('firstName', () => true)
|
|
396
|
-
);
|
|
397
|
-
const props = mapStateToControlProps(
|
|
398
|
-
{ jsonforms: { core: updateCoreState } },
|
|
399
|
-
{ uischema: coreUISchema }
|
|
400
|
-
);
|
|
401
|
-
t.is(props.errors.split('\n').length, 1);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
test('mapStateToControlProps - id', t => {
|
|
405
|
-
clearAllIds();
|
|
406
|
-
const ownProps = {
|
|
407
|
-
uischema: coreUISchema,
|
|
408
|
-
id: '#/properties/firstName'
|
|
409
|
-
};
|
|
410
|
-
const props = mapStateToControlProps(createState(coreUISchema), ownProps);
|
|
411
|
-
t.is(props.id, '#/properties/firstName');
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
test('mapStateToControlProps - hide errors in hide validation mode', t => {
|
|
415
|
-
const schema = {
|
|
416
|
-
type: 'object',
|
|
417
|
-
properties: {
|
|
418
|
-
animal: {
|
|
419
|
-
type: 'string'
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
const uischema: ControlElement = {
|
|
424
|
-
type: 'Control',
|
|
425
|
-
scope: '#/properties/animal'
|
|
426
|
-
};
|
|
427
|
-
const initCoreState = coreReducer(undefined, init({ animal: 100 }, schema, uischema));
|
|
428
|
-
t.is(initCoreState.errors.length, 1);
|
|
429
|
-
|
|
430
|
-
const ownProps = {
|
|
431
|
-
uischema
|
|
432
|
-
};
|
|
433
|
-
const props = mapStateToControlProps(
|
|
434
|
-
{ jsonforms: { core: initCoreState } },
|
|
435
|
-
ownProps
|
|
436
|
-
);
|
|
437
|
-
t.not(props.errors.length, 0);
|
|
438
|
-
|
|
439
|
-
const hideErrorsState = coreReducer(
|
|
440
|
-
initCoreState,
|
|
441
|
-
setValidationMode('ValidateAndHide')
|
|
442
|
-
);
|
|
443
|
-
t.is(hideErrorsState.errors.length, 1);
|
|
444
|
-
|
|
445
|
-
const hideErrorsProps = mapStateToControlProps(
|
|
446
|
-
{ jsonforms: { core: hideErrorsState } },
|
|
447
|
-
ownProps
|
|
448
|
-
);
|
|
449
|
-
t.is(hideErrorsProps.errors, '');
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
test('mapDispatchToControlProps', t => {
|
|
453
|
-
const store = mockStore(createState(coreUISchema));
|
|
454
|
-
const props = mapDispatchToControlProps(store.dispatch);
|
|
455
|
-
props.handleChange('foo', 42);
|
|
456
|
-
const updateAction = _.head<any>(store.getActions()) as UpdateAction;
|
|
457
|
-
t.is(updateAction.type, UPDATE_DATA);
|
|
458
|
-
t.is(updateAction.path, 'foo');
|
|
459
|
-
t.is(updateAction.updater(), 42);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
test('createDefaultValue', t => {
|
|
463
|
-
t.true(
|
|
464
|
-
_.isDate(
|
|
465
|
-
createDefaultValue({
|
|
466
|
-
type: 'string',
|
|
467
|
-
format: 'date'
|
|
468
|
-
})
|
|
469
|
-
)
|
|
470
|
-
);
|
|
471
|
-
t.true(
|
|
472
|
-
_.isDate(
|
|
473
|
-
createDefaultValue({
|
|
474
|
-
type: 'string',
|
|
475
|
-
format: 'date-time'
|
|
476
|
-
})
|
|
477
|
-
)
|
|
478
|
-
);
|
|
479
|
-
t.true(
|
|
480
|
-
_.isDate(
|
|
481
|
-
createDefaultValue({
|
|
482
|
-
type: 'string',
|
|
483
|
-
format: 'time'
|
|
484
|
-
})
|
|
485
|
-
)
|
|
486
|
-
);
|
|
487
|
-
t.is(createDefaultValue({ type: 'string' }), '');
|
|
488
|
-
t.is(createDefaultValue({ type: 'number' }), 0);
|
|
489
|
-
t.falsy(createDefaultValue({ type: 'boolean' }));
|
|
490
|
-
t.is(createDefaultValue({ type: 'integer' }), 0);
|
|
491
|
-
t.deepEqual(createDefaultValue({ type: 'array' }), []);
|
|
492
|
-
t.is(createDefaultValue({ type: 'null' }), null);
|
|
493
|
-
t.deepEqual(createDefaultValue({ type: 'object' }), {});
|
|
494
|
-
t.deepEqual(createDefaultValue({ type: 'something' }), {});
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
test(`mapStateToJsonFormsRendererProps should use registered UI schema given ownProps schema`, t => {
|
|
498
|
-
const store = mockStore(createState(coreUISchema));
|
|
499
|
-
const schema = {
|
|
500
|
-
type: 'object',
|
|
501
|
-
properties: {
|
|
502
|
-
bar: {
|
|
503
|
-
type: 'number'
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
const props = mapStateToJsonFormsRendererProps(store.getState(), { schema });
|
|
509
|
-
t.deepEqual(props.uischema, coreUISchema);
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
test(`mapStateToJsonFormsRendererProps should use registered UI schema given no ownProps`, t => {
|
|
513
|
-
const store = mockStore(createState(coreUISchema));
|
|
514
|
-
const props = mapStateToJsonFormsRendererProps(store.getState(), {});
|
|
515
|
-
t.deepEqual(props.uischema, coreUISchema);
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
test(`mapStateToJsonFormsRendererProps should use UI schema if given via ownProps`, t => {
|
|
519
|
-
const store = mockStore(createState(coreUISchema));
|
|
520
|
-
const schema = {
|
|
521
|
-
type: 'object',
|
|
522
|
-
properties: {
|
|
523
|
-
foo: {
|
|
524
|
-
type: 'string'
|
|
525
|
-
},
|
|
526
|
-
bar: {
|
|
527
|
-
type: 'number'
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
const uischema = {
|
|
532
|
-
type: 'Control',
|
|
533
|
-
scope: '#/properties/foo'
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
const props = mapStateToJsonFormsRendererProps(store.getState(), {
|
|
537
|
-
schema,
|
|
538
|
-
uischema
|
|
539
|
-
});
|
|
540
|
-
t.deepEqual(props.uischema, uischema);
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
test('mapDispatchToArrayControlProps should adding items to array', t => {
|
|
544
|
-
const data: any = ['foo'];
|
|
545
|
-
const schema: JsonSchema = {
|
|
546
|
-
type: 'array',
|
|
547
|
-
items: {
|
|
548
|
-
type: 'string'
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
const uischema: ControlElement = {
|
|
552
|
-
type: 'Control',
|
|
553
|
-
scope: '#'
|
|
554
|
-
};
|
|
555
|
-
const initCore: JsonFormsCore = {
|
|
556
|
-
uischema,
|
|
557
|
-
schema,
|
|
558
|
-
data,
|
|
559
|
-
errors: [] as ErrorObject[]
|
|
560
|
-
};
|
|
561
|
-
const [getCore, dispatch] = mockDispatch(initCore);
|
|
562
|
-
dispatch(init(data, schema, uischema));
|
|
563
|
-
const props = mapDispatchToArrayControlProps(dispatch);
|
|
564
|
-
props.addItem('', createDefaultValue(schema))();
|
|
565
|
-
t.is(getCore().data.length, 2);
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
test('mapDispatchToArrayControlProps should remove items from array', t => {
|
|
569
|
-
const data = ['foo', 'bar', 'quux'];
|
|
570
|
-
const schema: JsonSchema = {
|
|
571
|
-
type: 'array',
|
|
572
|
-
items: {
|
|
573
|
-
type: 'string'
|
|
574
|
-
}
|
|
575
|
-
};
|
|
576
|
-
const uischema: ControlElement = {
|
|
577
|
-
type: 'Control',
|
|
578
|
-
scope: '#'
|
|
579
|
-
};
|
|
580
|
-
const initCore: JsonFormsCore = {
|
|
581
|
-
uischema,
|
|
582
|
-
schema,
|
|
583
|
-
data,
|
|
584
|
-
errors: [] as ErrorObject[]
|
|
585
|
-
};
|
|
586
|
-
const [getCore, dispatch] = mockDispatch(initCore);
|
|
587
|
-
dispatch(init(data, schema, uischema));
|
|
588
|
-
const props = mapDispatchToArrayControlProps(dispatch);
|
|
589
|
-
props.removeItems('', [0, 1])();
|
|
590
|
-
t.is(getCore().data.length, 1);
|
|
591
|
-
t.is(getCore().data[0], 'quux');
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
test('mapStateToLayoutProps - visible via state with path from ownProps ', t => {
|
|
595
|
-
const uischema = {
|
|
596
|
-
type: 'VerticalLayout',
|
|
597
|
-
elements: [coreUISchema],
|
|
598
|
-
rule: hideRule
|
|
599
|
-
};
|
|
600
|
-
const ownProps = {
|
|
601
|
-
uischema,
|
|
602
|
-
path: 'foo'
|
|
603
|
-
};
|
|
604
|
-
const state = {
|
|
605
|
-
jsonforms: {
|
|
606
|
-
core: {
|
|
607
|
-
schema: {
|
|
608
|
-
type: 'object',
|
|
609
|
-
properties: {
|
|
610
|
-
firstName: { type: 'string' },
|
|
611
|
-
lastName: { type: 'string' }
|
|
612
|
-
}
|
|
613
|
-
},
|
|
614
|
-
data: {
|
|
615
|
-
foo: { firstName: 'Lisa' }
|
|
616
|
-
},
|
|
617
|
-
uischema,
|
|
618
|
-
errors: [] as ErrorObject[]
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
const props = mapStateToLayoutProps(state, ownProps);
|
|
623
|
-
t.true(props.visible);
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
test('mapStateToArrayLayoutProps - should include minItems in array layout props', t => {
|
|
627
|
-
const schema: JsonSchema = {
|
|
628
|
-
type: 'array',
|
|
629
|
-
minItems: 42,
|
|
630
|
-
items: {
|
|
631
|
-
type: 'object',
|
|
632
|
-
properties: {
|
|
633
|
-
message: {
|
|
634
|
-
type: 'string',
|
|
635
|
-
default: 'foo'
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
const uischema: ControlElement = {
|
|
642
|
-
type: 'Control',
|
|
643
|
-
scope: '#'
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
const state = {
|
|
647
|
-
jsonforms: {
|
|
648
|
-
core: {
|
|
649
|
-
schema,
|
|
650
|
-
data: {},
|
|
651
|
-
uischema,
|
|
652
|
-
errors: [] as ErrorObject[]
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
const ownProps = {
|
|
658
|
-
uischema
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
const props = mapStateToArrayLayoutProps(state, ownProps);
|
|
662
|
-
t.is(props.minItems, 42);
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
test('mapStateToLayoutProps should return renderers prop via ownProps', t => {
|
|
666
|
-
const uischema = {
|
|
667
|
-
type: 'VerticalLayout',
|
|
668
|
-
elements: [] as UISchemaElement[]
|
|
669
|
-
};
|
|
670
|
-
const state = {
|
|
671
|
-
jsonforms: {
|
|
672
|
-
core: {
|
|
673
|
-
schema: {
|
|
674
|
-
type: 'object',
|
|
675
|
-
properties: {
|
|
676
|
-
firstName: { type: 'string' },
|
|
677
|
-
lastName: { type: 'string' }
|
|
678
|
-
}
|
|
679
|
-
},
|
|
680
|
-
data: {
|
|
681
|
-
foo: { firstName: 'Homer' }
|
|
682
|
-
},
|
|
683
|
-
uischema,
|
|
684
|
-
errors: [] as ErrorObject[]
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
const props = mapStateToLayoutProps(state, {
|
|
689
|
-
uischema,
|
|
690
|
-
path: 'foo',
|
|
691
|
-
renderers: [
|
|
692
|
-
{
|
|
693
|
-
tester: rankWith(1, () => true),
|
|
694
|
-
renderer: undefined
|
|
695
|
-
}
|
|
696
|
-
]
|
|
697
|
-
});
|
|
698
|
-
t.is(props.renderers.length, 1);
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
test('mapStateToLayoutProps - disabled via global readonly', t => {
|
|
702
|
-
const uischema = {
|
|
703
|
-
type: 'VerticalLayout',
|
|
704
|
-
elements: [coreUISchema],
|
|
705
|
-
};
|
|
706
|
-
const ownProps = {
|
|
707
|
-
uischema
|
|
708
|
-
};
|
|
709
|
-
const state: JsonFormsState = createState(uischema);
|
|
710
|
-
state.jsonforms.readonly = true;
|
|
711
|
-
|
|
712
|
-
const props = mapStateToLayoutProps(state, ownProps);
|
|
713
|
-
t.false(props.enabled);
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
test('mapStateToLayoutProps - disabled via global readonly beats enabled via ownProps', t => {
|
|
717
|
-
const uischema = {
|
|
718
|
-
type: 'VerticalLayout',
|
|
719
|
-
elements: [coreUISchema],
|
|
720
|
-
};
|
|
721
|
-
const ownProps = {
|
|
722
|
-
uischema,
|
|
723
|
-
enabled: true
|
|
724
|
-
};
|
|
725
|
-
const state: JsonFormsState = createState(uischema);
|
|
726
|
-
state.jsonforms.readonly = true;
|
|
727
|
-
|
|
728
|
-
const props = mapStateToLayoutProps(state, ownProps);
|
|
729
|
-
t.false(props.enabled);
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
test('mapStateToLayoutProps - disabled via global readonly beats enabled via rule', t => {
|
|
733
|
-
const uischema = {
|
|
734
|
-
type: 'VerticalLayout',
|
|
735
|
-
elements: [coreUISchema],
|
|
736
|
-
rule: enableRule
|
|
737
|
-
};
|
|
738
|
-
const ownProps = {
|
|
739
|
-
uischema
|
|
740
|
-
};
|
|
741
|
-
const state: JsonFormsState = createState(uischema);
|
|
742
|
-
state.jsonforms.readonly = true;
|
|
743
|
-
|
|
744
|
-
const props = mapStateToLayoutProps(state, ownProps);
|
|
745
|
-
t.false(props.enabled);
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
test('mapStateToLayoutProps - hidden via state with path from ownProps ', t => {
|
|
749
|
-
const uischema = {
|
|
750
|
-
type: 'VerticalLayout',
|
|
751
|
-
elements: [coreUISchema],
|
|
752
|
-
rule: hideRule
|
|
753
|
-
};
|
|
754
|
-
const ownProps = {
|
|
755
|
-
uischema,
|
|
756
|
-
path: 'foo'
|
|
757
|
-
};
|
|
758
|
-
const state = {
|
|
759
|
-
jsonforms: {
|
|
760
|
-
core: {
|
|
761
|
-
schema: {
|
|
762
|
-
type: 'object',
|
|
763
|
-
properties: {
|
|
764
|
-
firstName: { type: 'string' },
|
|
765
|
-
lastName: { type: 'string' }
|
|
766
|
-
}
|
|
767
|
-
},
|
|
768
|
-
data: {
|
|
769
|
-
foo: { firstName: 'Homer' }
|
|
770
|
-
},
|
|
771
|
-
uischema,
|
|
772
|
-
errors: [] as ErrorObject[]
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
};
|
|
776
|
-
const props = mapStateToLayoutProps(state, ownProps);
|
|
777
|
-
t.false(props.visible);
|
|
778
|
-
});
|
|
779
|
-
|
|
780
|
-
test("mapStateToOneOfProps - indexOfFittingSchema should not select schema if enum doesn't match", t => {
|
|
781
|
-
const uischema: ControlElement = {
|
|
782
|
-
type: 'Control',
|
|
783
|
-
scope: '#/properties/method'
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
const ownProps = {
|
|
787
|
-
uischema
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
const state = {
|
|
791
|
-
jsonforms: {
|
|
792
|
-
core: {
|
|
793
|
-
ajv: createAjv(),
|
|
794
|
-
schema: {
|
|
795
|
-
type: 'object',
|
|
796
|
-
properties: {
|
|
797
|
-
method: {
|
|
798
|
-
oneOf: [
|
|
799
|
-
{
|
|
800
|
-
title: 'Injection',
|
|
801
|
-
type: 'object',
|
|
802
|
-
properties: {
|
|
803
|
-
method: {
|
|
804
|
-
title: 'Method',
|
|
805
|
-
type: 'string',
|
|
806
|
-
enum: ['Injection'],
|
|
807
|
-
default: 'Injection'
|
|
808
|
-
}
|
|
809
|
-
},
|
|
810
|
-
required: ['method']
|
|
811
|
-
},
|
|
812
|
-
{
|
|
813
|
-
title: 'Infusion',
|
|
814
|
-
type: 'object',
|
|
815
|
-
properties: {
|
|
816
|
-
method: {
|
|
817
|
-
title: 'Method',
|
|
818
|
-
type: 'string',
|
|
819
|
-
enum: ['Infusion'],
|
|
820
|
-
default: 'Infusion'
|
|
821
|
-
}
|
|
822
|
-
},
|
|
823
|
-
required: ['method']
|
|
824
|
-
}
|
|
825
|
-
]
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
},
|
|
829
|
-
data: {
|
|
830
|
-
method: {
|
|
831
|
-
method: 'Infusion'
|
|
832
|
-
}
|
|
833
|
-
},
|
|
834
|
-
uischema
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
const oneOfProps = mapStateToOneOfProps(state, ownProps);
|
|
840
|
-
t.is(oneOfProps.indexOfFittingSchema, 1);
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
test('mapStateToMultiEnumControlProps - oneOf items', t => {
|
|
844
|
-
const uischema: ControlElement = {
|
|
845
|
-
type: 'Control',
|
|
846
|
-
scope: '#/properties/colors'
|
|
847
|
-
};
|
|
848
|
-
const state = {
|
|
849
|
-
jsonforms: {
|
|
850
|
-
core: {
|
|
851
|
-
schema: {
|
|
852
|
-
type: 'object',
|
|
853
|
-
properties: {
|
|
854
|
-
colors: {
|
|
855
|
-
type: 'array',
|
|
856
|
-
items: {
|
|
857
|
-
oneOf: [
|
|
858
|
-
{
|
|
859
|
-
const: 'red'
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
const: 'pink',
|
|
863
|
-
title: 'almost red'
|
|
864
|
-
}
|
|
865
|
-
]
|
|
866
|
-
},
|
|
867
|
-
uniqueItems: true
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
},
|
|
871
|
-
data: {},
|
|
872
|
-
uischema,
|
|
873
|
-
errors: [] as ErrorObject[]
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
const ownProps = {
|
|
878
|
-
uischema,
|
|
879
|
-
path: 'colors'
|
|
880
|
-
};
|
|
881
|
-
const props = mapStateToMultiEnumControlProps(state, ownProps);
|
|
882
|
-
t.deepEqual(props.options, [
|
|
883
|
-
{ label: 'red', value: 'red' },
|
|
884
|
-
{ label: 'almost red', value: 'pink' }
|
|
885
|
-
]);
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
test('mapStateToMultiEnumControlProps - enum items', t => {
|
|
889
|
-
const uischema: ControlElement = {
|
|
890
|
-
type: 'Control',
|
|
891
|
-
scope: '#/properties/colors'
|
|
892
|
-
};
|
|
893
|
-
const state = {
|
|
894
|
-
jsonforms: {
|
|
895
|
-
core: {
|
|
896
|
-
schema: {
|
|
897
|
-
type: 'object',
|
|
898
|
-
properties: {
|
|
899
|
-
colors: {
|
|
900
|
-
type: 'array',
|
|
901
|
-
items: {
|
|
902
|
-
type: 'string',
|
|
903
|
-
enum: ['red', 'green', 'pink']
|
|
904
|
-
},
|
|
905
|
-
uniqueItems: true
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
},
|
|
909
|
-
data: {},
|
|
910
|
-
uischema,
|
|
911
|
-
errors: [] as ErrorObject[]
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
const ownProps = {
|
|
916
|
-
uischema,
|
|
917
|
-
path: 'colors'
|
|
918
|
-
};
|
|
919
|
-
const props = mapStateToMultiEnumControlProps(state, ownProps);
|
|
920
|
-
t.deepEqual(props.options, [
|
|
921
|
-
{ label: 'red', value: 'red' },
|
|
922
|
-
{ label: 'green', value: 'green' },
|
|
923
|
-
{ label: 'pink', value: 'pink' }
|
|
924
|
-
]);
|
|
925
|
-
});
|
|
926
|
-
|
|
927
|
-
test('mapDispatchToMultiEnumProps - enum schema - addItem', t => {
|
|
928
|
-
const uischema: ControlElement = {
|
|
929
|
-
type: 'Control',
|
|
930
|
-
scope: '#/properties/colors'
|
|
931
|
-
};
|
|
932
|
-
const schema = {
|
|
933
|
-
type: 'object',
|
|
934
|
-
properties: {
|
|
935
|
-
colors: {
|
|
936
|
-
type: 'array',
|
|
937
|
-
items: {
|
|
938
|
-
type: 'string',
|
|
939
|
-
enum: ['red', 'green', 'pink']
|
|
940
|
-
},
|
|
941
|
-
uniqueItems: true
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
};
|
|
945
|
-
const data = {colors:['green']};
|
|
946
|
-
const initCore : JsonFormsCore = {
|
|
947
|
-
uischema,
|
|
948
|
-
schema,
|
|
949
|
-
data,
|
|
950
|
-
errors: [] as ErrorObject[]
|
|
951
|
-
};
|
|
952
|
-
const [getCore, dispatch] = mockDispatch(initCore);
|
|
953
|
-
dispatch(init(data, schema, uischema, createAjv({ useDefaults: true })));
|
|
954
|
-
const props = mapDispatchToMultiEnumProps(dispatch);
|
|
955
|
-
props.addItem('colors', 'pink');
|
|
956
|
-
|
|
957
|
-
t.is(getCore().data.colors.length, 2);
|
|
958
|
-
t.deepEqual(getCore().data.colors[0], 'green');
|
|
959
|
-
t.deepEqual(getCore().data.colors[1], 'pink');
|
|
960
|
-
});
|
|
961
|
-
|
|
962
|
-
test('mapDispatchToMultiEnumProps - enum schema - removeItem', t => {
|
|
963
|
-
const uischema: ControlElement = {
|
|
964
|
-
type: 'Control',
|
|
965
|
-
scope: '#/properties/colors'
|
|
966
|
-
};
|
|
967
|
-
const schema = {
|
|
968
|
-
type: 'object',
|
|
969
|
-
properties: {
|
|
970
|
-
colors: {
|
|
971
|
-
type: 'array',
|
|
972
|
-
items: {
|
|
973
|
-
type: 'string',
|
|
974
|
-
enum: ['red', 'green', 'pink']
|
|
975
|
-
},
|
|
976
|
-
uniqueItems: true
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
};
|
|
980
|
-
const data = {colors:['green', 'red']};
|
|
981
|
-
const initCore : JsonFormsCore = {
|
|
982
|
-
uischema,
|
|
983
|
-
schema,
|
|
984
|
-
data,
|
|
985
|
-
errors: [] as ErrorObject[]
|
|
986
|
-
};
|
|
987
|
-
const [getCore, dispatch] = mockDispatch(initCore);
|
|
988
|
-
dispatch(init(data, schema, uischema, createAjv({ useDefaults: true })));
|
|
989
|
-
const props = mapDispatchToMultiEnumProps(dispatch);
|
|
990
|
-
props.removeItem('colors', 'red');
|
|
991
|
-
|
|
992
|
-
t.is(getCore().data.colors.length, 1);
|
|
993
|
-
t.deepEqual(getCore().data.colors[0], 'green');
|
|
994
|
-
});
|
|
995
|
-
|
|
996
|
-
test('mapDispatchToMultiEnumProps - oneOf schema - addItem', t => {
|
|
997
|
-
const uischema: ControlElement = {
|
|
998
|
-
type: 'Control',
|
|
999
|
-
scope: '#/properties/colors'
|
|
1000
|
-
};
|
|
1001
|
-
const schema = {
|
|
1002
|
-
type: 'object',
|
|
1003
|
-
properties: {
|
|
1004
|
-
colors: {
|
|
1005
|
-
type: 'array',
|
|
1006
|
-
items: {
|
|
1007
|
-
oneOf: [
|
|
1008
|
-
{
|
|
1009
|
-
const: 'red'
|
|
1010
|
-
},
|
|
1011
|
-
{
|
|
1012
|
-
const: 'pink',
|
|
1013
|
-
title: 'almost red'
|
|
1014
|
-
}
|
|
1015
|
-
]
|
|
1016
|
-
},
|
|
1017
|
-
uniqueItems: true
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
};
|
|
1021
|
-
const data = {};
|
|
1022
|
-
const initCore : JsonFormsCore = {
|
|
1023
|
-
uischema,
|
|
1024
|
-
schema,
|
|
1025
|
-
data,
|
|
1026
|
-
errors: [] as ErrorObject[]
|
|
1027
|
-
};
|
|
1028
|
-
const [getCore, dispatch] = mockDispatch(initCore);
|
|
1029
|
-
dispatch(init(data, schema, uischema, createAjv({ useDefaults: true })));
|
|
1030
|
-
const props = mapDispatchToMultiEnumProps(dispatch);
|
|
1031
|
-
props.addItem('colors', 'pink');
|
|
1032
|
-
|
|
1033
|
-
t.is(getCore().data.colors.length, 1);
|
|
1034
|
-
t.deepEqual(getCore().data.colors[0], 'pink');
|
|
1035
|
-
});
|
|
1036
|
-
|
|
1037
|
-
test('mapDispatchToMultiEnumProps - oneOf schema - removeItem', t => {
|
|
1038
|
-
const uischema: ControlElement = {
|
|
1039
|
-
type: 'Control',
|
|
1040
|
-
scope: '#/properties/colors'
|
|
1041
|
-
};
|
|
1042
|
-
const schema = {
|
|
1043
|
-
type: 'object',
|
|
1044
|
-
properties: {
|
|
1045
|
-
colors: {
|
|
1046
|
-
type: 'array',
|
|
1047
|
-
items: {
|
|
1048
|
-
oneOf: [
|
|
1049
|
-
{
|
|
1050
|
-
const: 'red'
|
|
1051
|
-
},
|
|
1052
|
-
{
|
|
1053
|
-
const: 'pink',
|
|
1054
|
-
title: 'almost red'
|
|
1055
|
-
}
|
|
1056
|
-
]
|
|
1057
|
-
},
|
|
1058
|
-
uniqueItems: true
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
};
|
|
1062
|
-
const data = {colors:['pink']};
|
|
1063
|
-
const initCore : JsonFormsCore = {
|
|
1064
|
-
uischema,
|
|
1065
|
-
schema,
|
|
1066
|
-
data,
|
|
1067
|
-
errors: [] as ErrorObject[]
|
|
1068
|
-
};
|
|
1069
|
-
const [getCore, dispatch] = mockDispatch(initCore);
|
|
1070
|
-
dispatch(init(data, schema, uischema, createAjv({ useDefaults: true })));
|
|
1071
|
-
const props = mapDispatchToMultiEnumProps(dispatch);
|
|
1072
|
-
props.removeItem('colors', 'pink');
|
|
1073
|
-
|
|
1074
|
-
t.is(getCore().data.colors.length, 0);
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
test('should assign defaults to enum', t => {
|
|
1078
|
-
const schema: JsonSchema = {
|
|
1079
|
-
type: 'object',
|
|
1080
|
-
properties: {
|
|
1081
|
-
name: {
|
|
1082
|
-
type: 'string',
|
|
1083
|
-
minLength: 1
|
|
1084
|
-
},
|
|
1085
|
-
color: {
|
|
1086
|
-
type: 'string',
|
|
1087
|
-
enum: ['red', 'green', 'blue'],
|
|
1088
|
-
default: 'green'
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
};
|
|
1092
|
-
|
|
1093
|
-
const uischema: UISchemaElement = undefined;
|
|
1094
|
-
|
|
1095
|
-
const data = {
|
|
1096
|
-
name: 'foo'
|
|
1097
|
-
};
|
|
1098
|
-
|
|
1099
|
-
const initState: JsonFormsState = {
|
|
1100
|
-
jsonforms: {
|
|
1101
|
-
core: {
|
|
1102
|
-
uischema,
|
|
1103
|
-
schema,
|
|
1104
|
-
data,
|
|
1105
|
-
errors: [] as ErrorObject[]
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
const newCore = coreReducer(initState.jsonforms.core, init(data, schema, uischema, createAjv({ useDefaults: true })));
|
|
1110
|
-
t.is(newCore.data.color, 'green');
|
|
1111
|
-
});
|
|
1112
|
-
|
|
1113
|
-
test('should assign defaults to empty item within nested object of an array', t => {
|
|
1114
|
-
const schema: JsonSchema = {
|
|
1115
|
-
type: 'array',
|
|
1116
|
-
items: {
|
|
1117
|
-
type: 'object',
|
|
1118
|
-
properties: {
|
|
1119
|
-
message: {
|
|
1120
|
-
type: 'string',
|
|
1121
|
-
default: 'foo'
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
};
|
|
1126
|
-
|
|
1127
|
-
const uischema: ControlElement = {
|
|
1128
|
-
type: 'Control',
|
|
1129
|
-
scope: '#'
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
|
-
const data = [{}];
|
|
1133
|
-
|
|
1134
|
-
const initState: JsonFormsState = {
|
|
1135
|
-
jsonforms: {
|
|
1136
|
-
core: {
|
|
1137
|
-
uischema,
|
|
1138
|
-
schema,
|
|
1139
|
-
data,
|
|
1140
|
-
errors: [] as ErrorObject[]
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
};
|
|
1144
|
-
|
|
1145
|
-
const newCore = coreReducer(initState.jsonforms.core, init(data, schema, uischema, createAjv({ useDefaults: true })));
|
|
1146
|
-
t.is(newCore.data.length, 1);
|
|
1147
|
-
t.deepEqual(newCore.data[0], { message: 'foo' });
|
|
1148
|
-
});
|
|
1149
|
-
|
|
1150
|
-
test('should assign defaults to newly added item within nested object of an array', t => {
|
|
1151
|
-
const schema: JsonSchema = {
|
|
1152
|
-
type: 'array',
|
|
1153
|
-
items: {
|
|
1154
|
-
type: 'object',
|
|
1155
|
-
properties: {
|
|
1156
|
-
message: {
|
|
1157
|
-
type: 'string',
|
|
1158
|
-
default: 'foo'
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
};
|
|
1163
|
-
|
|
1164
|
-
const uischema: ControlElement = {
|
|
1165
|
-
type: 'Control',
|
|
1166
|
-
scope: '#'
|
|
1167
|
-
};
|
|
1168
|
-
|
|
1169
|
-
const data = [{}];
|
|
1170
|
-
|
|
1171
|
-
const initCore: JsonFormsCore = {
|
|
1172
|
-
uischema,
|
|
1173
|
-
schema,
|
|
1174
|
-
data,
|
|
1175
|
-
errors: [] as ErrorObject[]
|
|
1176
|
-
};
|
|
1177
|
-
const [getCore, dispatch] = mockDispatch(initCore);
|
|
1178
|
-
dispatch(init(data, schema, uischema, createAjv({ useDefaults: true })));
|
|
1179
|
-
const props = mapDispatchToArrayControlProps(dispatch);
|
|
1180
|
-
props.addItem('', createDefaultValue(schema))();
|
|
1181
|
-
|
|
1182
|
-
t.is(getCore().data.length, 2);
|
|
1183
|
-
t.deepEqual(getCore().data[0], { message: 'foo' });
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
test('computeLabel - should not edit label if not required and hideRequiredAsterisk is false', t => {
|
|
1187
|
-
const computedLabel = computeLabel('Test Label', false, false);
|
|
1188
|
-
t.is(computedLabel, 'Test Label');
|
|
1189
|
-
});
|
|
1190
|
-
|
|
1191
|
-
test('computeLabel - should not edit label if not required and hideRequiredAsterisk is true', t => {
|
|
1192
|
-
const computedLabel = computeLabel('Test Label', false, true);
|
|
1193
|
-
t.is(computedLabel, 'Test Label');
|
|
1194
|
-
});
|
|
1195
|
-
|
|
1196
|
-
test('computeLabel - should not edit label if required but hideRequiredAsterisk is true', t => {
|
|
1197
|
-
const computedLabel = computeLabel('Test Label', true, true);
|
|
1198
|
-
t.is(computedLabel, 'Test Label');
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
test('computeLabel - should add asterisk if required but hideRequiredAsterisk is false', t => {
|
|
1202
|
-
const computedLabel = computeLabel('Test Label', true, false);
|
|
1203
|
-
t.is(computedLabel, 'Test Label*');
|
|
1204
|
-
});
|
|
1205
|
-
|
|
1206
|
-
test('mapStateToAnyOfProps - const constraint in anyOf schema should return correct indexOfFittingSchema', t => {
|
|
1207
|
-
const uischema: ControlElement = {
|
|
1208
|
-
type: 'Control',
|
|
1209
|
-
scope: '#'
|
|
1210
|
-
};
|
|
1211
|
-
const schema: JsonSchema7 = {
|
|
1212
|
-
anyOf: [
|
|
1213
|
-
{
|
|
1214
|
-
type: "object",
|
|
1215
|
-
properties: {
|
|
1216
|
-
type: {
|
|
1217
|
-
const: "type1"
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
},
|
|
1221
|
-
{
|
|
1222
|
-
type: "object",
|
|
1223
|
-
properties: {
|
|
1224
|
-
type: {
|
|
1225
|
-
const: "type2"
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
},
|
|
1229
|
-
{
|
|
1230
|
-
type: "object",
|
|
1231
|
-
properties: {
|
|
1232
|
-
type: {
|
|
1233
|
-
const: "type3"
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
]
|
|
1238
|
-
};
|
|
1239
|
-
const ownProps: OwnPropsOfControl = {
|
|
1240
|
-
visible: true,
|
|
1241
|
-
uischema,
|
|
1242
|
-
path: 'foo'
|
|
1243
|
-
};
|
|
1244
|
-
const state = {
|
|
1245
|
-
jsonforms: {
|
|
1246
|
-
core: {
|
|
1247
|
-
ajv: createAjv(),
|
|
1248
|
-
schema,
|
|
1249
|
-
data: {
|
|
1250
|
-
foo: { type: "type3"}
|
|
1251
|
-
},
|
|
1252
|
-
uischema,
|
|
1253
|
-
errors: [] as ErrorObject[]
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
};
|
|
1257
|
-
const props = mapStateToAnyOfProps(state, ownProps);
|
|
1258
|
-
t.is(props.indexOfFittingSchema, 2);
|
|
1259
|
-
});
|
|
1260
|
-
|
|
1261
|
-
test('mapStateToControlProps - i18n - mapStateToControlProps should not crash without i18n', t => {
|
|
1262
|
-
const ownProps = {
|
|
1263
|
-
uischema: coreUISchema
|
|
1264
|
-
};
|
|
1265
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1266
|
-
state.jsonforms.i18n = undefined;
|
|
1267
|
-
|
|
1268
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1269
|
-
t.is(props.label, 'First Name');
|
|
1270
|
-
});
|
|
1271
|
-
|
|
1272
|
-
test('mapStateToControlProps - i18n - default translation has no effect', t => {
|
|
1273
|
-
const ownProps = {
|
|
1274
|
-
uischema: coreUISchema
|
|
1275
|
-
};
|
|
1276
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1277
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1278
|
-
|
|
1279
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1280
|
-
t.is(props.label, 'First Name');
|
|
1281
|
-
t.is(props.description, undefined);
|
|
1282
|
-
});
|
|
1283
|
-
|
|
1284
|
-
test('mapStateToControlProps - i18n - translation via path key', t => {
|
|
1285
|
-
const ownProps = {
|
|
1286
|
-
uischema: coreUISchema
|
|
1287
|
-
};
|
|
1288
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1289
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1290
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1291
|
-
switch(key){
|
|
1292
|
-
case 'firstName.label': return 'my translation';
|
|
1293
|
-
default: return defaultMessage;
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1298
|
-
t.is(props.label, 'my translation');
|
|
1299
|
-
t.is(props.description, undefined);
|
|
1300
|
-
});
|
|
1301
|
-
|
|
1302
|
-
test('mapStateToControlProps - i18n - translation via default message', t => {
|
|
1303
|
-
const ownProps = {
|
|
1304
|
-
uischema: coreUISchema
|
|
1305
|
-
};
|
|
1306
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1307
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1308
|
-
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1309
|
-
switch(defaultMessage){
|
|
1310
|
-
case 'First Name': return 'my translation';
|
|
1311
|
-
default: return defaultMessage;
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1316
|
-
t.is(props.label, 'my translation');
|
|
1317
|
-
t.is(props.description, undefined);
|
|
1318
|
-
});
|
|
1319
|
-
|
|
1320
|
-
test('mapStateToControlProps - i18n - translation via JSON Schema i18n key', t => {
|
|
1321
|
-
const ownProps = {
|
|
1322
|
-
uischema: coreUISchema
|
|
1323
|
-
};
|
|
1324
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1325
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1326
|
-
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1327
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1328
|
-
switch(key){
|
|
1329
|
-
case 'my-key.label': return 'my label';
|
|
1330
|
-
case 'my-key.description': return 'my description';
|
|
1331
|
-
default: return defaultMessage;
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1336
|
-
t.is(props.label, 'my label');
|
|
1337
|
-
t.is(props.description, 'my description');
|
|
1338
|
-
});
|
|
1339
|
-
|
|
1340
|
-
test('mapStateToControlProps - i18n - translation via UI Schema i18n key', t => {
|
|
1341
|
-
const ownProps = {
|
|
1342
|
-
uischema: coreUISchema
|
|
1343
|
-
};
|
|
1344
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1345
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1346
|
-
ownProps.uischema = {...ownProps.uischema, i18n: 'my-key'};
|
|
1347
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1348
|
-
switch(key){
|
|
1349
|
-
case 'my-key.label': return 'my label';
|
|
1350
|
-
case 'my-key.description': return 'my description';
|
|
1351
|
-
default: return defaultMessage;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1356
|
-
t.is(props.label, 'my label');
|
|
1357
|
-
t.is(props.description, 'my description');
|
|
1358
|
-
});
|
|
1359
|
-
|
|
1360
|
-
test('mapStateToControlProps - i18n errors - should not crash without i18n', t => {
|
|
1361
|
-
const ownProps = {
|
|
1362
|
-
uischema: coreUISchema
|
|
1363
|
-
};
|
|
1364
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1365
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
|
|
1366
|
-
state.jsonforms.core = coreReducer(
|
|
1367
|
-
state.jsonforms.core,
|
|
1368
|
-
init(
|
|
1369
|
-
state.jsonforms.core.data,
|
|
1370
|
-
state.jsonforms.core.schema,
|
|
1371
|
-
state.jsonforms.core.uischema,
|
|
1372
|
-
createAjv()
|
|
1373
|
-
)
|
|
1374
|
-
);
|
|
1375
|
-
state.jsonforms.i18n = undefined;
|
|
1376
|
-
|
|
1377
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1378
|
-
t.is(props.errors, 'must match pattern "[0-9]+"');
|
|
1379
|
-
});
|
|
1380
|
-
|
|
1381
|
-
test('mapStateToControlProps - i18n errors - default translation has no effect', t => {
|
|
1382
|
-
const ownProps = {
|
|
1383
|
-
uischema: coreUISchema
|
|
1384
|
-
};
|
|
1385
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1386
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
|
|
1387
|
-
state.jsonforms.core = coreReducer(
|
|
1388
|
-
state.jsonforms.core,
|
|
1389
|
-
init(
|
|
1390
|
-
state.jsonforms.core.data,
|
|
1391
|
-
state.jsonforms.core.schema,
|
|
1392
|
-
state.jsonforms.core.uischema,
|
|
1393
|
-
createAjv()
|
|
1394
|
-
)
|
|
1395
|
-
);
|
|
1396
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1397
|
-
|
|
1398
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1399
|
-
t.is(props.errors, 'must match pattern "[0-9]+"');
|
|
1400
|
-
});
|
|
1401
|
-
|
|
1402
|
-
test('mapStateToControlProps - i18n errors - translate via error message key', t => {
|
|
1403
|
-
const ownProps = {
|
|
1404
|
-
uischema: coreUISchema
|
|
1405
|
-
};
|
|
1406
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1407
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
|
|
1408
|
-
state.jsonforms.core = coreReducer(
|
|
1409
|
-
state.jsonforms.core,
|
|
1410
|
-
init(
|
|
1411
|
-
state.jsonforms.core.data,
|
|
1412
|
-
state.jsonforms.core.schema,
|
|
1413
|
-
state.jsonforms.core.uischema,
|
|
1414
|
-
createAjv()
|
|
1415
|
-
)
|
|
1416
|
-
);
|
|
1417
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1418
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1419
|
-
switch(key){
|
|
1420
|
-
case 'must match pattern "[0-9]+"': return 'my error message';
|
|
1421
|
-
default: return defaultMessage;
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1426
|
-
t.is(props.errors, 'my error message');
|
|
1427
|
-
});
|
|
1428
|
-
|
|
1429
|
-
test('mapStateToControlProps - i18n errors - translate via i18 specialized error keyword key', t => {
|
|
1430
|
-
const ownProps = {
|
|
1431
|
-
uischema: coreUISchema
|
|
1432
|
-
};
|
|
1433
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1434
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1435
|
-
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1436
|
-
state.jsonforms.core = coreReducer(
|
|
1437
|
-
state.jsonforms.core,
|
|
1438
|
-
init(
|
|
1439
|
-
state.jsonforms.core.data,
|
|
1440
|
-
state.jsonforms.core.schema,
|
|
1441
|
-
state.jsonforms.core.uischema,
|
|
1442
|
-
createAjv()
|
|
1443
|
-
)
|
|
1444
|
-
);
|
|
1445
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1446
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1447
|
-
switch(key){
|
|
1448
|
-
case 'my-key.error.pattern': return 'my error message';
|
|
1449
|
-
default: return defaultMessage;
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1454
|
-
t.is(props.errors, 'my error message');
|
|
1455
|
-
});
|
|
1456
|
-
|
|
1457
|
-
test('mapStateToControlProps - i18n errors - translate via i18 general error keyword key', t => {
|
|
1458
|
-
const ownProps = {
|
|
1459
|
-
uischema: coreUISchema
|
|
1460
|
-
};
|
|
1461
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1462
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1463
|
-
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1464
|
-
state.jsonforms.core = coreReducer(
|
|
1465
|
-
state.jsonforms.core,
|
|
1466
|
-
init(
|
|
1467
|
-
state.jsonforms.core.data,
|
|
1468
|
-
state.jsonforms.core.schema,
|
|
1469
|
-
state.jsonforms.core.uischema,
|
|
1470
|
-
createAjv()
|
|
1471
|
-
)
|
|
1472
|
-
);
|
|
1473
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1474
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1475
|
-
switch(key){
|
|
1476
|
-
case 'error.pattern': return 'my error message';
|
|
1477
|
-
default: return defaultMessage;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1482
|
-
t.is(props.errors, 'my error message');
|
|
1483
|
-
});
|
|
1484
|
-
|
|
1485
|
-
test('mapStateToControlProps - i18n errors - specialized keyword wins over generic keyword', t => {
|
|
1486
|
-
const ownProps = {
|
|
1487
|
-
uischema: coreUISchema
|
|
1488
|
-
};
|
|
1489
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1490
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1491
|
-
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1492
|
-
state.jsonforms.core = coreReducer(
|
|
1493
|
-
state.jsonforms.core,
|
|
1494
|
-
init(
|
|
1495
|
-
state.jsonforms.core.data,
|
|
1496
|
-
state.jsonforms.core.schema,
|
|
1497
|
-
state.jsonforms.core.uischema,
|
|
1498
|
-
createAjv()
|
|
1499
|
-
)
|
|
1500
|
-
);
|
|
1501
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1502
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1503
|
-
switch(key){
|
|
1504
|
-
case 'my-key.error.pattern': return 'my key error message';
|
|
1505
|
-
case 'error.pattern': return 'my error message';
|
|
1506
|
-
default: return defaultMessage;
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1511
|
-
t.is(props.errors, 'my key error message');
|
|
1512
|
-
});
|
|
1513
|
-
|
|
1514
|
-
test('mapStateToControlProps - i18n errors - multiple errors customization', t => {
|
|
1515
|
-
const ownProps = {
|
|
1516
|
-
uischema: coreUISchema
|
|
1517
|
-
};
|
|
1518
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1519
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1520
|
-
state.jsonforms.core.schema.properties.firstName.maxLength = 2;
|
|
1521
|
-
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1522
|
-
state.jsonforms.core = coreReducer(
|
|
1523
|
-
state.jsonforms.core,
|
|
1524
|
-
init(
|
|
1525
|
-
state.jsonforms.core.data,
|
|
1526
|
-
state.jsonforms.core.schema,
|
|
1527
|
-
state.jsonforms.core.uischema,
|
|
1528
|
-
createAjv()
|
|
1529
|
-
)
|
|
1530
|
-
);
|
|
1531
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1532
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1533
|
-
switch(key){
|
|
1534
|
-
case 'error.maxLength': return 'max length message';
|
|
1535
|
-
case 'my-key.error.pattern': return 'my key error message';
|
|
1536
|
-
default: return defaultMessage;
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1541
|
-
t.is(props.errors, 'max length message\nmy key error message');
|
|
1542
|
-
});
|
|
1543
|
-
|
|
1544
|
-
test('mapStateToControlProps - i18n errors - custom keyword wins over all other errors', t => {
|
|
1545
|
-
const ownProps = {
|
|
1546
|
-
uischema: coreUISchema
|
|
1547
|
-
};
|
|
1548
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1549
|
-
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1550
|
-
state.jsonforms.core.schema.properties.firstName.maxLength = 2;
|
|
1551
|
-
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1552
|
-
state.jsonforms.core = coreReducer(
|
|
1553
|
-
state.jsonforms.core,
|
|
1554
|
-
init(
|
|
1555
|
-
state.jsonforms.core.data,
|
|
1556
|
-
state.jsonforms.core.schema,
|
|
1557
|
-
state.jsonforms.core.uischema,
|
|
1558
|
-
createAjv()
|
|
1559
|
-
)
|
|
1560
|
-
);
|
|
1561
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1562
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1563
|
-
switch(key){
|
|
1564
|
-
case 'my-key.error.custom': return 'this is my error custom error message';
|
|
1565
|
-
case 'my-key.error.pattern': return 'my key error message';
|
|
1566
|
-
case 'error.pattern': return 'my error message';
|
|
1567
|
-
default: return defaultMessage;
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
const props = mapStateToControlProps(state, ownProps);
|
|
1572
|
-
t.is(props.errors, 'this is my error custom error message');
|
|
1573
|
-
});
|
|
1574
|
-
|
|
1575
|
-
test('mapStateToEnumControlProps - i18n - should not crash without i18n', t => {
|
|
1576
|
-
const ownProps = {
|
|
1577
|
-
uischema: coreUISchema
|
|
1578
|
-
};
|
|
1579
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1580
|
-
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1581
|
-
state.jsonforms.i18n = undefined;
|
|
1582
|
-
|
|
1583
|
-
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1584
|
-
t.is(props.options[0].label, 'a');
|
|
1585
|
-
});
|
|
1586
|
-
|
|
1587
|
-
test('mapStateToEnumControlProps - i18n - default translation has no effect', t => {
|
|
1588
|
-
const ownProps = {
|
|
1589
|
-
uischema: coreUISchema
|
|
1590
|
-
};
|
|
1591
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1592
|
-
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1593
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1594
|
-
|
|
1595
|
-
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1596
|
-
t.is(props.options[0].label, 'a');
|
|
1597
|
-
});
|
|
1598
|
-
|
|
1599
|
-
test('mapStateToEnumControlProps - i18n - path label translation', t => {
|
|
1600
|
-
const ownProps = {
|
|
1601
|
-
uischema: coreUISchema
|
|
1602
|
-
};
|
|
1603
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1604
|
-
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1605
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1606
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1607
|
-
switch(key){
|
|
1608
|
-
case 'firstName.a': return 'my message';
|
|
1609
|
-
default: return defaultMessage;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1614
|
-
t.is(props.options[0].label, 'my message');
|
|
1615
|
-
});
|
|
1616
|
-
|
|
1617
|
-
test('mapStateToEnumControlProps - i18n - defaultMessage translation', t => {
|
|
1618
|
-
const ownProps = {
|
|
1619
|
-
uischema: coreUISchema
|
|
1620
|
-
};
|
|
1621
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1622
|
-
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1623
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1624
|
-
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1625
|
-
switch(defaultMessage){
|
|
1626
|
-
case 'a': return 'my message';
|
|
1627
|
-
default: return defaultMessage;
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1632
|
-
t.is(props.options[0].label, 'my message');
|
|
1633
|
-
});
|
|
1634
|
-
|
|
1635
|
-
test('mapStateToEnumControlProps - i18n - i18n key translation', t => {
|
|
1636
|
-
const ownProps = {
|
|
1637
|
-
uischema: coreUISchema
|
|
1638
|
-
};
|
|
1639
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1640
|
-
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1641
|
-
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1642
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1643
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1644
|
-
switch(key){
|
|
1645
|
-
case 'my-key.a': return 'my message';
|
|
1646
|
-
default: return defaultMessage;
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1651
|
-
t.is(props.options[0].label, 'my message');
|
|
1652
|
-
});
|
|
1653
|
-
|
|
1654
|
-
test('mapStateToOneOfEnumControlProps - i18n - should not crash without i18n', t => {
|
|
1655
|
-
const ownProps = {
|
|
1656
|
-
uischema: coreUISchema
|
|
1657
|
-
};
|
|
1658
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1659
|
-
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1660
|
-
state.jsonforms.i18n = undefined;
|
|
1661
|
-
|
|
1662
|
-
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1663
|
-
t.is(props.options[0].label, 'foo');
|
|
1664
|
-
});
|
|
1665
|
-
|
|
1666
|
-
test('mapStateToOneOfEnumControlProps- i18n - default translation has no effect', t => {
|
|
1667
|
-
const ownProps = {
|
|
1668
|
-
uischema: coreUISchema
|
|
1669
|
-
};
|
|
1670
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1671
|
-
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1672
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1673
|
-
|
|
1674
|
-
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1675
|
-
t.is(props.options[0].label, 'foo');
|
|
1676
|
-
});
|
|
1677
|
-
|
|
1678
|
-
test('mapStateToOneOfEnumControlProps - i18n - path label translation', t => {
|
|
1679
|
-
const ownProps = {
|
|
1680
|
-
uischema: coreUISchema
|
|
1681
|
-
};
|
|
1682
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1683
|
-
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1684
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1685
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1686
|
-
switch(key){
|
|
1687
|
-
case 'firstName.foo': return 'my message';
|
|
1688
|
-
default: return defaultMessage;
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1693
|
-
t.is(props.options[0].label, 'my message');
|
|
1694
|
-
});
|
|
1695
|
-
|
|
1696
|
-
test('mapStateToOneOfEnumControlProps - i18n - default message translation', t => {
|
|
1697
|
-
const ownProps = {
|
|
1698
|
-
uischema: coreUISchema
|
|
1699
|
-
};
|
|
1700
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1701
|
-
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1702
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1703
|
-
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1704
|
-
switch(defaultMessage){
|
|
1705
|
-
case 'foo': return 'my message';
|
|
1706
|
-
default: return defaultMessage;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1711
|
-
t.is(props.options[0].label, 'my message');
|
|
1712
|
-
});
|
|
1713
|
-
|
|
1714
|
-
test('mapStateToOneOfEnumControlProps - i18n - i18n key translation', t => {
|
|
1715
|
-
const ownProps = {
|
|
1716
|
-
uischema: coreUISchema
|
|
1717
|
-
};
|
|
1718
|
-
const state: JsonFormsState = createState(coreUISchema);
|
|
1719
|
-
(state.jsonforms.core.schema.properties.firstName.oneOf as any) =
|
|
1720
|
-
[{const: 'a', title: 'foo', i18n: 'my-foo'}, {const: 'b', title: 'bar', i18n:'my-bar'}];
|
|
1721
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1722
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1723
|
-
switch(key){
|
|
1724
|
-
case 'my-foo': return 'my message';
|
|
1725
|
-
default: return defaultMessage;
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1730
|
-
t.is(props.options[0].label, 'my message');
|
|
1731
|
-
});
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
test('mapStateToLabelProps - i18n - should not crash without i18n', t => {
|
|
1735
|
-
const labelUISchema : LabelElement = {
|
|
1736
|
-
type: 'Label',
|
|
1737
|
-
text: 'foo',
|
|
1738
|
-
i18n: 'bar'
|
|
1739
|
-
}
|
|
1740
|
-
const ownProps = {
|
|
1741
|
-
uischema: labelUISchema
|
|
1742
|
-
};
|
|
1743
|
-
const state: JsonFormsState = createState(labelUISchema);
|
|
1744
|
-
state.jsonforms.i18n = undefined;
|
|
1745
|
-
|
|
1746
|
-
const props = mapStateToLabelProps(state, ownProps);
|
|
1747
|
-
t.is(props.text, 'foo');
|
|
1748
|
-
});
|
|
1749
|
-
|
|
1750
|
-
test('mapStateToLabelProps - i18n - default translation has no effect', t => {
|
|
1751
|
-
const labelUISchema : LabelElement = {
|
|
1752
|
-
type: 'Label',
|
|
1753
|
-
text: 'foo',
|
|
1754
|
-
i18n: 'bar'
|
|
1755
|
-
}
|
|
1756
|
-
const ownProps = {
|
|
1757
|
-
uischema: labelUISchema
|
|
1758
|
-
};
|
|
1759
|
-
const state: JsonFormsState = createState(labelUISchema);
|
|
1760
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1761
|
-
|
|
1762
|
-
const props = mapStateToLabelProps(state, ownProps);
|
|
1763
|
-
t.is(props.text, 'foo');
|
|
1764
|
-
});
|
|
1765
|
-
|
|
1766
|
-
test('mapStateToLabelProps - i18n - default key translation', t => {
|
|
1767
|
-
const labelUISchema : LabelElement = {
|
|
1768
|
-
type: 'Label',
|
|
1769
|
-
text: 'foo'
|
|
1770
|
-
}
|
|
1771
|
-
const ownProps = {
|
|
1772
|
-
uischema: labelUISchema
|
|
1773
|
-
};
|
|
1774
|
-
const state: JsonFormsState = createState(labelUISchema);
|
|
1775
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1776
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1777
|
-
switch(key){
|
|
1778
|
-
case 'foo': return 'my message';
|
|
1779
|
-
default: return defaultMessage;
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
const props = mapStateToLabelProps(state, ownProps);
|
|
1784
|
-
t.is(props.text, 'my message');
|
|
1785
|
-
});
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
test('mapStateToLabelProps - i18n - default message translation', t => {
|
|
1789
|
-
const labelUISchema : LabelElement = {
|
|
1790
|
-
type: 'Label',
|
|
1791
|
-
text: 'foo',
|
|
1792
|
-
i18n: 'bar'
|
|
1793
|
-
}
|
|
1794
|
-
const ownProps = {
|
|
1795
|
-
uischema: labelUISchema
|
|
1796
|
-
};
|
|
1797
|
-
const state: JsonFormsState = createState(labelUISchema);
|
|
1798
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1799
|
-
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1800
|
-
switch(defaultMessage){
|
|
1801
|
-
case 'foo': return 'my message';
|
|
1802
|
-
default: return defaultMessage;
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
const props = mapStateToLabelProps(state, ownProps);
|
|
1807
|
-
t.is(props.text, 'my message');
|
|
1808
|
-
});
|
|
1809
|
-
|
|
1810
|
-
test('mapStateToLabelProps - i18n - i18n key translation', t => {
|
|
1811
|
-
const labelUISchema : LabelElement = {
|
|
1812
|
-
type: 'Label',
|
|
1813
|
-
text: 'foo',
|
|
1814
|
-
i18n: 'bar'
|
|
1815
|
-
}
|
|
1816
|
-
const ownProps = {
|
|
1817
|
-
uischema: labelUISchema
|
|
1818
|
-
};
|
|
1819
|
-
const state: JsonFormsState = createState(labelUISchema);
|
|
1820
|
-
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1821
|
-
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined): string | undefined => {
|
|
1822
|
-
switch(key){
|
|
1823
|
-
case 'bar.text': return 'my message';
|
|
1824
|
-
default: return defaultMessage;
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
const props = mapStateToLabelProps(state, ownProps);
|
|
1829
|
-
t.is(props.text, 'my message');
|
|
1830
|
-
});
|