@jsonforms/core 3.0.0-alpha.0 → 3.0.0-beta.0
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 +1 -1
- package/docs/assets/js/search.json +1 -1
- package/docs/enums/ruleeffect.html +4 -4
- package/docs/globals.html +1095 -703
- package/docs/index.html +70 -43
- package/docs/interfaces/addcellrendereraction.html +3 -3
- package/docs/interfaces/addrendereraction.html +3 -3
- package/docs/interfaces/adduischemaaction.html +3 -3
- package/docs/interfaces/andcondition.html +2 -2
- package/docs/interfaces/arraycontrolprops.html +22 -22
- package/docs/interfaces/arraylayoutprops.html +22 -22
- package/docs/interfaces/categorization.html +5 -5
- package/docs/interfaces/category.html +5 -5
- package/docs/interfaces/cellprops.html +14 -14
- package/docs/interfaces/combinatorrendererprops.html +13 -13
- package/docs/interfaces/combinatorsubschemarenderinfo.html +3 -3
- package/docs/interfaces/composablecondition.html +2 -2
- package/docs/interfaces/condition.html +1 -1
- package/docs/interfaces/controlelement.html +5 -5
- package/docs/interfaces/controlprops.html +17 -17
- package/docs/interfaces/controlstate.html +2 -2
- package/docs/interfaces/controlwithdetailprops.html +18 -18
- package/docs/interfaces/dispatchcellprops.html +13 -13
- package/docs/interfaces/dispatchcellstateprops.html +13 -13
- package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
- package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
- package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
- package/docs/interfaces/enumcellprops.html +15 -15
- package/docs/interfaces/enumoption.html +2 -2
- package/docs/interfaces/formatted.html +2 -2
- package/docs/interfaces/grouplayout.html +5 -5
- package/docs/interfaces/horizontallayout.html +4 -4
- package/docs/interfaces/initaction.html +6 -6
- package/docs/interfaces/initactionoptions.html +3 -3
- package/docs/interfaces/jsonformscellrendererregistryentry.html +2 -2
- package/docs/interfaces/jsonformscore.html +7 -7
- package/docs/interfaces/jsonformsdefaultdataregistryentry.html +2 -2
- package/docs/interfaces/jsonformsextendedstate.html +1 -1
- package/docs/interfaces/{jsonformslocalestate.html → jsonformsi18nstate.html} +20 -20
- package/docs/interfaces/jsonformsprops.html +9 -9
- package/docs/interfaces/jsonformsrendererregistryentry.html +2 -2
- package/docs/interfaces/jsonformsstate.html +1 -1
- package/docs/interfaces/jsonformsstore.html +5 -5
- package/docs/interfaces/jsonformssubstates.html +18 -8
- package/docs/interfaces/jsonformsuischemaregistryentry.html +2 -2
- package/docs/interfaces/labeldescription.html +2 -2
- package/docs/interfaces/labelelement.html +4 -4
- package/docs/interfaces/layout.html +4 -4
- package/docs/interfaces/layoutprops.html +10 -10
- package/docs/interfaces/leafcondition.html +3 -3
- package/docs/interfaces/orcondition.html +2 -2
- package/docs/interfaces/ownpropsofcell.html +10 -10
- package/docs/interfaces/ownpropsofcontrol.html +9 -9
- package/docs/interfaces/ownpropsofenum.html +1 -1
- package/docs/interfaces/ownpropsofenumcell.html +11 -11
- package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
- package/docs/interfaces/ownpropsoflayout.html +9 -9
- package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
- package/docs/interfaces/ownpropsofrenderer.html +8 -8
- package/docs/interfaces/registerdefaultdataaction.html +3 -3
- package/docs/interfaces/removecellrendereraction.html +3 -3
- package/docs/interfaces/removerendereraction.html +3 -3
- package/docs/interfaces/removeuischemaaction.html +2 -2
- package/docs/interfaces/rendererprops.html +9 -9
- package/docs/interfaces/rule.html +2 -2
- package/docs/interfaces/schemabasedcondition.html +3 -3
- package/docs/interfaces/scopable.html +1 -1
- package/docs/interfaces/setajvaction.html +3 -3
- package/docs/interfaces/setconfigaction.html +2 -2
- package/docs/interfaces/setlocaleaction.html +3 -3
- package/docs/interfaces/setschemaaction.html +2 -2
- package/docs/interfaces/{setlocalizedschemasaction.html → settranslatoraction.html} +29 -15
- package/docs/interfaces/setuischemaaction.html +2 -2
- package/docs/interfaces/setvalidationmodeaction.html +2 -2
- package/docs/interfaces/statepropsofarraycontrol.html +18 -18
- package/docs/interfaces/statepropsofarraylayout.html +18 -18
- package/docs/interfaces/statepropsofcell.html +13 -13
- package/docs/interfaces/statepropsofcombinator.html +12 -12
- package/docs/interfaces/statepropsofcontrol.html +16 -16
- package/docs/interfaces/statepropsofcontrolwithdetail.html +17 -17
- package/docs/interfaces/statepropsofenumcell.html +14 -14
- package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -9
- package/docs/interfaces/statepropsoflayout.html +10 -10
- package/docs/interfaces/statepropsofmasteritem.html +7 -7
- package/docs/interfaces/statepropsofrenderer.html +9 -9
- package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
- package/docs/interfaces/uischemaelement.html +3 -3
- package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
- package/docs/interfaces/updateaction.html +3 -3
- package/docs/interfaces/updatecoreaction.html +6 -6
- package/docs/interfaces/updateerrorsaction.html +2 -2
- package/docs/interfaces/{setlocalizeduischemasaction.html → updatei18naction.html} +43 -15
- package/docs/interfaces/verticallayout.html +4 -4
- package/docs/interfaces/withclassname.html +1 -1
- package/lib/Helpers.d.ts +5 -0
- package/lib/actions/actions.d.ts +181 -0
- package/lib/actions/index.d.ts +1 -178
- package/lib/configDefault.d.ts +6 -6
- package/lib/generators/Generate.d.ts +6 -0
- package/lib/generators/index.d.ts +3 -10
- package/lib/generators/schema.d.ts +8 -8
- package/lib/generators/uischema.d.ts +12 -13
- package/lib/i18n/i18nTypes.d.ts +15 -0
- package/lib/i18n/i18nUtil.d.ts +18 -0
- package/lib/i18n/index.d.ts +2 -0
- package/lib/index.d.ts +11 -23
- package/lib/jsonforms-core.cjs.js +2445 -0
- package/lib/jsonforms-core.cjs.js.map +1 -0
- package/lib/jsonforms-core.esm.js +2164 -0
- package/lib/jsonforms-core.esm.js.map +1 -0
- package/lib/models/draft4.d.ts +198 -198
- package/lib/models/index.d.ts +5 -0
- package/lib/models/jsonSchema.d.ts +3 -3
- package/lib/models/jsonSchema4.d.ts +110 -110
- package/lib/models/jsonSchema7.d.ts +119 -119
- package/lib/models/uischema.d.ts +201 -201
- package/lib/reducers/cells.d.ts +11 -11
- package/lib/reducers/config.d.ts +3 -3
- package/lib/reducers/core.d.ts +24 -23
- package/lib/reducers/default-data.d.ts +10 -10
- package/lib/reducers/i18n.d.ts +8 -11
- package/lib/reducers/index.d.ts +9 -47
- package/lib/reducers/reducers.d.ts +29 -0
- package/lib/reducers/renderers.d.ts +10 -10
- package/lib/reducers/selectors.d.ts +15 -0
- package/lib/reducers/uischemas.d.ts +10 -10
- package/lib/store.d.ts +53 -56
- package/lib/testers/index.d.ts +1 -204
- package/lib/testers/testers.d.ts +203 -0
- package/lib/util/Formatted.d.ts +19 -19
- package/lib/util/array.d.ts +3 -3
- package/lib/util/cell.d.ts +79 -79
- package/lib/util/combinators.d.ts +10 -11
- package/lib/util/ids.d.ts +3 -3
- package/lib/util/index.d.ts +15 -49
- package/lib/util/label.d.ts +9 -10
- package/lib/util/path.d.ts +25 -24
- package/lib/util/renderer.d.ts +398 -395
- package/lib/util/resolvers.d.ts +25 -25
- package/lib/util/runtime.d.ts +18 -19
- package/lib/util/schema.d.ts +1 -1
- package/lib/util/type.d.ts +174 -174
- package/lib/util/uischema.d.ts +5 -5
- package/lib/util/util.d.ts +31 -0
- package/lib/util/validator.d.ts +3 -2
- package/package.json +18 -14
- package/rollup.config.js +44 -0
- package/{lib/models/jsonSchema4.js → src/Helpers.ts} +16 -8
- package/src/actions/actions.ts +345 -0
- package/src/actions/index.ts +1 -310
- package/src/configDefault.ts +1 -0
- package/{lib/util/validator.js → src/generators/Generate.ts} +18 -11
- package/src/generators/index.ts +3 -21
- package/src/generators/schema.ts +1 -1
- package/src/generators/uischema.ts +4 -4
- package/src/i18n/i18nTypes.ts +17 -0
- package/src/i18n/i18nUtil.ts +105 -0
- package/src/i18n/index.ts +2 -0
- package/src/index.ts +7 -31
- package/src/models/draft4.ts +1 -0
- package/{lib/util/type.js → src/models/index.ts} +10 -7
- package/src/models/jsonSchema.ts +1 -0
- package/src/models/uischema.ts +1 -0
- package/src/reducers/cells.ts +2 -1
- package/src/reducers/config.ts +2 -1
- package/src/reducers/core.ts +74 -52
- package/src/reducers/default-data.ts +2 -1
- package/src/reducers/i18n.ts +42 -35
- package/src/reducers/index.ts +9 -154
- package/src/reducers/reducers.ts +128 -0
- package/src/reducers/renderers.ts +2 -1
- package/src/reducers/selectors.ts +65 -0
- package/src/reducers/uischemas.ts +4 -2
- package/src/store.ts +11 -8
- package/src/testers/index.ts +1 -516
- package/src/testers/testers.ts +547 -0
- package/src/util/Formatted.ts +1 -0
- package/src/util/array.ts +25 -0
- package/src/util/cell.ts +45 -10
- package/src/util/combinators.ts +2 -4
- package/src/util/ids.ts +1 -0
- package/src/util/index.ts +11 -123
- package/src/util/label.ts +2 -2
- package/src/util/path.ts +4 -1
- package/src/util/renderer.ts +139 -66
- package/src/util/resolvers.ts +2 -1
- package/src/util/runtime.ts +3 -2
- package/src/util/schema.ts +26 -1
- package/src/util/uischema.ts +2 -1
- package/src/util/util.ts +127 -0
- package/src/util/validator.ts +5 -8
- package/stats.html +3279 -0
- package/{lib/configDefault.js → test/i18n/i18nUtil.test.ts} +25 -24
- package/test/reducers/core.test.ts +31 -44
- package/test/util/cell.test.ts +2 -2
- package/test/util/renderer.test.ts +543 -31
- package/docs/interfaces/labels.html +0 -157
- package/lib/actions/index.js +0 -125
- package/lib/actions/index.js.map +0 -1
- package/lib/configDefault.js.map +0 -1
- package/lib/generators/index.js +0 -12
- package/lib/generators/index.js.map +0 -1
- package/lib/generators/schema.js +0 -152
- package/lib/generators/schema.js.map +0 -1
- package/lib/generators/uischema.js +0 -167
- package/lib/generators/uischema.js.map +0 -1
- package/lib/index.js +0 -45
- package/lib/index.js.map +0 -1
- package/lib/jsonforms-core.js +0 -19
- package/lib/jsonforms-core.js.map +0 -1
- package/lib/models/draft4.js +0 -173
- package/lib/models/draft4.js.map +0 -1
- package/lib/models/jsonSchema.js +0 -3
- package/lib/models/jsonSchema.js.map +0 -1
- package/lib/models/jsonSchema4.js.map +0 -1
- package/lib/models/jsonSchema7.js +0 -30
- package/lib/models/jsonSchema7.js.map +0 -1
- package/lib/models/uischema.js +0 -31
- package/lib/models/uischema.js.map +0 -1
- package/lib/reducers/cells.js +0 -16
- package/lib/reducers/cells.js.map +0 -1
- package/lib/reducers/config.js +0 -44
- package/lib/reducers/config.js.map +0 -1
- package/lib/reducers/core.js +0 -259
- package/lib/reducers/core.js.map +0 -1
- package/lib/reducers/default-data.js +0 -42
- package/lib/reducers/default-data.js.map +0 -1
- package/lib/reducers/i18n.js +0 -66
- package/lib/reducers/i18n.js.map +0 -1
- package/lib/reducers/index.js +0 -92
- package/lib/reducers/index.js.map +0 -1
- package/lib/reducers/renderers.js +0 -17
- package/lib/reducers/renderers.js.map +0 -1
- package/lib/reducers/uischemas.js +0 -57
- package/lib/reducers/uischemas.js.map +0 -1
- package/lib/store.js +0 -3
- package/lib/store.js.map +0 -1
- package/lib/testers/index.js +0 -402
- package/lib/testers/index.js.map +0 -1
- package/lib/util/Formatted.js +0 -3
- package/lib/util/Formatted.js.map +0 -1
- package/lib/util/array.js +0 -19
- package/lib/util/array.js.map +0 -1
- package/lib/util/cell.js +0 -133
- package/lib/util/cell.js.map +0 -1
- package/lib/util/combinators.js +0 -56
- package/lib/util/combinators.js.map +0 -1
- package/lib/util/ids.js +0 -50
- package/lib/util/ids.js.map +0 -1
- package/lib/util/index.js +0 -132
- package/lib/util/index.js.map +0 -1
- package/lib/util/label.js +0 -70
- package/lib/util/label.js.map +0 -1
- package/lib/util/path.js +0 -84
- package/lib/util/path.js.map +0 -1
- package/lib/util/renderer.js +0 -447
- package/lib/util/renderer.js.map +0 -1
- package/lib/util/resolvers.js +0 -165
- package/lib/util/resolvers.js.map +0 -1
- package/lib/util/runtime.js +0 -159
- package/lib/util/runtime.js.map +0 -1
- package/lib/util/schema.js +0 -16
- package/lib/util/schema.js.map +0 -1
- package/lib/util/type.js.map +0 -1
- package/lib/util/uischema.js +0 -52
- package/lib/util/uischema.js.map +0 -1
- package/lib/util/validator.js.map +0 -1
- package/webpack.build.js +0 -13
|
@@ -23,40 +23,25 @@
|
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
import * as _ from 'lodash';
|
|
26
|
-
import { init, update, UPDATE_DATA, UpdateAction } from '../../src/actions';
|
|
27
26
|
import * as Redux from 'redux';
|
|
28
|
-
import {
|
|
29
|
-
clearAllIds,
|
|
30
|
-
computeLabel,
|
|
31
|
-
createAjv,
|
|
32
|
-
createDefaultValue,
|
|
33
|
-
mapDispatchToArrayControlProps,
|
|
34
|
-
mapDispatchToControlProps,
|
|
35
|
-
mapStateToArrayLayoutProps,
|
|
36
|
-
mapStateToControlProps,
|
|
37
|
-
mapStateToJsonFormsRendererProps,
|
|
38
|
-
mapStateToLayoutProps,
|
|
39
|
-
mapStateToOneOfProps,
|
|
40
|
-
mapStateToMultiEnumControlProps,
|
|
41
|
-
mapDispatchToMultiEnumProps
|
|
42
|
-
} from '../../src/util';
|
|
43
27
|
import configureStore from 'redux-mock-store';
|
|
44
28
|
import test from 'ava';
|
|
45
|
-
|
|
46
|
-
import {
|
|
47
|
-
ControlElement,
|
|
48
|
-
CoreActions,
|
|
49
|
-
coreReducer,
|
|
50
|
-
Dispatch,
|
|
51
|
-
JsonFormsCore,
|
|
52
|
-
JsonFormsState,
|
|
53
|
-
JsonSchema,
|
|
54
|
-
rankWith,
|
|
55
|
-
RuleEffect,
|
|
56
|
-
UISchemaElement
|
|
57
|
-
} from '../../src';
|
|
29
|
+
|
|
58
30
|
import { ErrorObject } from 'ajv';
|
|
59
|
-
import {
|
|
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, RuleEffect, UISchemaElement } from '../../src/models/uischema';
|
|
36
|
+
import { computeLabel, createDefaultValue, mapDispatchToArrayControlProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAnyOfProps, mapStateToArrayLayoutProps, mapStateToControlProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLayoutProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, OwnPropsOfControl } from '../../src/util/renderer';
|
|
37
|
+
import { clearAllIds } from '../../src/util/ids';
|
|
38
|
+
import { generateDefaultUISchema } from '../../src/generators/uischema';
|
|
39
|
+
import { JsonSchema } from '../../src/models/jsonSchema';
|
|
40
|
+
import { rankWith } from '../../src/testers/testers';
|
|
41
|
+
import { createAjv } from '../../src/util/validator';
|
|
42
|
+
import { JsonSchema7 } from '../../src/models/jsonSchema7';
|
|
43
|
+
import { defaultJsonFormsI18nState } from '../../src/reducers/i18n';
|
|
44
|
+
import { i18nJsonSchema } from '../../src/i18n/i18nTypes';
|
|
60
45
|
|
|
61
46
|
const middlewares: Redux.Middleware[] = [];
|
|
62
47
|
const mockStore = configureStore<JsonFormsState>(middlewares);
|
|
@@ -381,7 +366,7 @@ test('mapStateToControlProps - errors', t => {
|
|
|
381
366
|
};
|
|
382
367
|
const clonedState = _.cloneDeep(createState(coreUISchema));
|
|
383
368
|
const error: ErrorObject = {
|
|
384
|
-
|
|
369
|
+
instancePath: '/firstName',
|
|
385
370
|
message: 'Duff beer',
|
|
386
371
|
keyword: 'whatever',
|
|
387
372
|
schemaPath: '',
|
|
@@ -1218,3 +1203,530 @@ test('computeLabel - should add asterisk if required but hideRequiredAsterisk is
|
|
|
1218
1203
|
const computedLabel = computeLabel('Test Label', true, false);
|
|
1219
1204
|
t.is(computedLabel, 'Test Label*');
|
|
1220
1205
|
});
|
|
1206
|
+
|
|
1207
|
+
test('mapStateToAnyOfProps - const constraint in anyOf schema should return correct indexOfFittingSchema', t => {
|
|
1208
|
+
const uischema: ControlElement = {
|
|
1209
|
+
type: 'Control',
|
|
1210
|
+
scope: '#'
|
|
1211
|
+
};
|
|
1212
|
+
const schema: JsonSchema7 = {
|
|
1213
|
+
anyOf: [
|
|
1214
|
+
{
|
|
1215
|
+
type: "object",
|
|
1216
|
+
properties: {
|
|
1217
|
+
type: {
|
|
1218
|
+
const: "type1"
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
},
|
|
1222
|
+
{
|
|
1223
|
+
type: "object",
|
|
1224
|
+
properties: {
|
|
1225
|
+
type: {
|
|
1226
|
+
const: "type2"
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
type: "object",
|
|
1232
|
+
properties: {
|
|
1233
|
+
type: {
|
|
1234
|
+
const: "type3"
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
]
|
|
1239
|
+
};
|
|
1240
|
+
const ownProps: OwnPropsOfControl = {
|
|
1241
|
+
visible: true,
|
|
1242
|
+
uischema,
|
|
1243
|
+
path: 'foo'
|
|
1244
|
+
};
|
|
1245
|
+
const state = {
|
|
1246
|
+
jsonforms: {
|
|
1247
|
+
core: {
|
|
1248
|
+
ajv: createAjv(),
|
|
1249
|
+
schema,
|
|
1250
|
+
data: {
|
|
1251
|
+
foo: { type: "type3"}
|
|
1252
|
+
},
|
|
1253
|
+
uischema,
|
|
1254
|
+
errors: [] as ErrorObject[]
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
const props = mapStateToAnyOfProps(state, ownProps);
|
|
1259
|
+
t.is(props.indexOfFittingSchema, 2);
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
test('mapStateToControlProps - i18n - mapStateToControlProps should not crash without i18n', t => {
|
|
1263
|
+
const ownProps = {
|
|
1264
|
+
uischema: coreUISchema
|
|
1265
|
+
};
|
|
1266
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1267
|
+
state.jsonforms.i18n = undefined;
|
|
1268
|
+
|
|
1269
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1270
|
+
t.is(props.label, 'First Name');
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
test('mapStateToControlProps - i18n - default translation has no effect', t => {
|
|
1274
|
+
const ownProps = {
|
|
1275
|
+
uischema: coreUISchema
|
|
1276
|
+
};
|
|
1277
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1278
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1279
|
+
|
|
1280
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1281
|
+
t.is(props.label, 'First Name');
|
|
1282
|
+
t.is(props.description, undefined);
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
test('mapStateToControlProps - i18n - translation via path key', t => {
|
|
1286
|
+
const ownProps = {
|
|
1287
|
+
uischema: coreUISchema
|
|
1288
|
+
};
|
|
1289
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1290
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1291
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1292
|
+
switch(key){
|
|
1293
|
+
case 'firstName.label': return 'my translation';
|
|
1294
|
+
default: return defaultMessage;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1299
|
+
t.is(props.label, 'my translation');
|
|
1300
|
+
t.is(props.description, undefined);
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
test('mapStateToControlProps - i18n - translation via default message', t => {
|
|
1304
|
+
const ownProps = {
|
|
1305
|
+
uischema: coreUISchema
|
|
1306
|
+
};
|
|
1307
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1308
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1309
|
+
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1310
|
+
switch(defaultMessage){
|
|
1311
|
+
case 'First Name': return 'my translation';
|
|
1312
|
+
default: return defaultMessage;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1317
|
+
t.is(props.label, 'my translation');
|
|
1318
|
+
t.is(props.description, undefined);
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
test('mapStateToControlProps - i18n - translation via JSON Schema i18n key', t => {
|
|
1322
|
+
const ownProps = {
|
|
1323
|
+
uischema: coreUISchema
|
|
1324
|
+
};
|
|
1325
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1326
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1327
|
+
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1328
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1329
|
+
switch(key){
|
|
1330
|
+
case 'my-key.label': return 'my label';
|
|
1331
|
+
case 'my-key.description': return 'my description';
|
|
1332
|
+
default: return defaultMessage;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1337
|
+
t.is(props.label, 'my label');
|
|
1338
|
+
t.is(props.description, 'my description');
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
test('mapStateToControlProps - i18n - translation via UI Schema i18n key', t => {
|
|
1342
|
+
const ownProps = {
|
|
1343
|
+
uischema: coreUISchema
|
|
1344
|
+
};
|
|
1345
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1346
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1347
|
+
ownProps.uischema = {...ownProps.uischema, options: {i18n: 'my-key'}};
|
|
1348
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1349
|
+
switch(key){
|
|
1350
|
+
case 'my-key.label': return 'my label';
|
|
1351
|
+
case 'my-key.description': return 'my description';
|
|
1352
|
+
default: return defaultMessage;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1357
|
+
t.is(props.label, 'my label');
|
|
1358
|
+
t.is(props.description, 'my description');
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
test('mapStateToControlProps - i18n errors - should not crash without i18n', t => {
|
|
1362
|
+
const ownProps = {
|
|
1363
|
+
uischema: coreUISchema
|
|
1364
|
+
};
|
|
1365
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1366
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
|
|
1367
|
+
state.jsonforms.core = coreReducer(
|
|
1368
|
+
state.jsonforms.core,
|
|
1369
|
+
init(
|
|
1370
|
+
state.jsonforms.core.data,
|
|
1371
|
+
state.jsonforms.core.schema,
|
|
1372
|
+
state.jsonforms.core.uischema,
|
|
1373
|
+
createAjv()
|
|
1374
|
+
)
|
|
1375
|
+
);
|
|
1376
|
+
state.jsonforms.i18n = undefined;
|
|
1377
|
+
|
|
1378
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1379
|
+
t.is(props.errors, 'must match pattern "[0-9]+"');
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
test('mapStateToControlProps - i18n errors - default translation has no effect', t => {
|
|
1383
|
+
const ownProps = {
|
|
1384
|
+
uischema: coreUISchema
|
|
1385
|
+
};
|
|
1386
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1387
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
|
|
1388
|
+
state.jsonforms.core = coreReducer(
|
|
1389
|
+
state.jsonforms.core,
|
|
1390
|
+
init(
|
|
1391
|
+
state.jsonforms.core.data,
|
|
1392
|
+
state.jsonforms.core.schema,
|
|
1393
|
+
state.jsonforms.core.uischema,
|
|
1394
|
+
createAjv()
|
|
1395
|
+
)
|
|
1396
|
+
);
|
|
1397
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1398
|
+
|
|
1399
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1400
|
+
t.is(props.errors, 'must match pattern "[0-9]+"');
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
test('mapStateToControlProps - i18n errors - translate via error message key', t => {
|
|
1404
|
+
const ownProps = {
|
|
1405
|
+
uischema: coreUISchema
|
|
1406
|
+
};
|
|
1407
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1408
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
|
|
1409
|
+
state.jsonforms.core = coreReducer(
|
|
1410
|
+
state.jsonforms.core,
|
|
1411
|
+
init(
|
|
1412
|
+
state.jsonforms.core.data,
|
|
1413
|
+
state.jsonforms.core.schema,
|
|
1414
|
+
state.jsonforms.core.uischema,
|
|
1415
|
+
createAjv()
|
|
1416
|
+
)
|
|
1417
|
+
);
|
|
1418
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1419
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1420
|
+
switch(key){
|
|
1421
|
+
case 'must match pattern "[0-9]+"': return 'my error message';
|
|
1422
|
+
default: return defaultMessage;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1427
|
+
t.is(props.errors, 'my error message');
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
test('mapStateToControlProps - i18n errors - translate via i18 specialized error keyword key', t => {
|
|
1431
|
+
const ownProps = {
|
|
1432
|
+
uischema: coreUISchema
|
|
1433
|
+
};
|
|
1434
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1435
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1436
|
+
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1437
|
+
state.jsonforms.core = coreReducer(
|
|
1438
|
+
state.jsonforms.core,
|
|
1439
|
+
init(
|
|
1440
|
+
state.jsonforms.core.data,
|
|
1441
|
+
state.jsonforms.core.schema,
|
|
1442
|
+
state.jsonforms.core.uischema,
|
|
1443
|
+
createAjv()
|
|
1444
|
+
)
|
|
1445
|
+
);
|
|
1446
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1447
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1448
|
+
switch(key){
|
|
1449
|
+
case 'my-key.error.pattern': return 'my error message';
|
|
1450
|
+
default: return defaultMessage;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1455
|
+
t.is(props.errors, 'my error message');
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1458
|
+
test('mapStateToControlProps - i18n errors - translate via i18 general error keyword key', t => {
|
|
1459
|
+
const ownProps = {
|
|
1460
|
+
uischema: coreUISchema
|
|
1461
|
+
};
|
|
1462
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1463
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1464
|
+
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1465
|
+
state.jsonforms.core = coreReducer(
|
|
1466
|
+
state.jsonforms.core,
|
|
1467
|
+
init(
|
|
1468
|
+
state.jsonforms.core.data,
|
|
1469
|
+
state.jsonforms.core.schema,
|
|
1470
|
+
state.jsonforms.core.uischema,
|
|
1471
|
+
createAjv()
|
|
1472
|
+
)
|
|
1473
|
+
);
|
|
1474
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1475
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1476
|
+
switch(key){
|
|
1477
|
+
case 'error.pattern': return 'my error message';
|
|
1478
|
+
default: return defaultMessage;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1483
|
+
t.is(props.errors, 'my error message');
|
|
1484
|
+
});
|
|
1485
|
+
|
|
1486
|
+
test('mapStateToControlProps - i18n errors - specialized keyword wins over generic keyword', t => {
|
|
1487
|
+
const ownProps = {
|
|
1488
|
+
uischema: coreUISchema
|
|
1489
|
+
};
|
|
1490
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1491
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1492
|
+
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1493
|
+
state.jsonforms.core = coreReducer(
|
|
1494
|
+
state.jsonforms.core,
|
|
1495
|
+
init(
|
|
1496
|
+
state.jsonforms.core.data,
|
|
1497
|
+
state.jsonforms.core.schema,
|
|
1498
|
+
state.jsonforms.core.uischema,
|
|
1499
|
+
createAjv()
|
|
1500
|
+
)
|
|
1501
|
+
);
|
|
1502
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1503
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1504
|
+
switch(key){
|
|
1505
|
+
case 'my-key.error.pattern': return 'my key error message';
|
|
1506
|
+
case 'error.pattern': return 'my error message';
|
|
1507
|
+
default: return defaultMessage;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1512
|
+
t.is(props.errors, 'my key error message');
|
|
1513
|
+
});
|
|
1514
|
+
|
|
1515
|
+
test('mapStateToControlProps - i18n errors - multiple errors customization', t => {
|
|
1516
|
+
const ownProps = {
|
|
1517
|
+
uischema: coreUISchema
|
|
1518
|
+
};
|
|
1519
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1520
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1521
|
+
state.jsonforms.core.schema.properties.firstName.maxLength = 2;
|
|
1522
|
+
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1523
|
+
state.jsonforms.core = coreReducer(
|
|
1524
|
+
state.jsonforms.core,
|
|
1525
|
+
init(
|
|
1526
|
+
state.jsonforms.core.data,
|
|
1527
|
+
state.jsonforms.core.schema,
|
|
1528
|
+
state.jsonforms.core.uischema,
|
|
1529
|
+
createAjv()
|
|
1530
|
+
)
|
|
1531
|
+
);
|
|
1532
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1533
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1534
|
+
switch(key){
|
|
1535
|
+
case 'error.maxLength': return 'max length message';
|
|
1536
|
+
case 'my-key.error.pattern': return 'my key error message';
|
|
1537
|
+
default: return defaultMessage;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1542
|
+
t.is(props.errors, 'max length message\nmy key error message');
|
|
1543
|
+
});
|
|
1544
|
+
|
|
1545
|
+
test('mapStateToControlProps - i18n errors - custom keyword wins over all other errors', t => {
|
|
1546
|
+
const ownProps = {
|
|
1547
|
+
uischema: coreUISchema
|
|
1548
|
+
};
|
|
1549
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1550
|
+
state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
|
|
1551
|
+
state.jsonforms.core.schema.properties.firstName.maxLength = 2;
|
|
1552
|
+
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1553
|
+
state.jsonforms.core = coreReducer(
|
|
1554
|
+
state.jsonforms.core,
|
|
1555
|
+
init(
|
|
1556
|
+
state.jsonforms.core.data,
|
|
1557
|
+
state.jsonforms.core.schema,
|
|
1558
|
+
state.jsonforms.core.uischema,
|
|
1559
|
+
createAjv()
|
|
1560
|
+
)
|
|
1561
|
+
);
|
|
1562
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1563
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1564
|
+
switch(key){
|
|
1565
|
+
case 'my-key.error.custom': return 'this is my error custom error message';
|
|
1566
|
+
case 'my-key.error.pattern': return 'my key error message';
|
|
1567
|
+
case 'error.pattern': return 'my error message';
|
|
1568
|
+
default: return defaultMessage;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1573
|
+
t.is(props.errors, 'this is my error custom error message');
|
|
1574
|
+
});
|
|
1575
|
+
|
|
1576
|
+
test('mapStateToEnumControlProps - i18n - should not crash without i18n', t => {
|
|
1577
|
+
const ownProps = {
|
|
1578
|
+
uischema: coreUISchema
|
|
1579
|
+
};
|
|
1580
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1581
|
+
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1582
|
+
state.jsonforms.i18n = undefined;
|
|
1583
|
+
|
|
1584
|
+
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1585
|
+
t.is(props.options[0].label, 'a');
|
|
1586
|
+
});
|
|
1587
|
+
|
|
1588
|
+
test('mapStateToEnumControlProps - i18n - default translation has no effect', t => {
|
|
1589
|
+
const ownProps = {
|
|
1590
|
+
uischema: coreUISchema
|
|
1591
|
+
};
|
|
1592
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1593
|
+
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1594
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1595
|
+
|
|
1596
|
+
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1597
|
+
t.is(props.options[0].label, 'a');
|
|
1598
|
+
});
|
|
1599
|
+
|
|
1600
|
+
test('mapStateToEnumControlProps - i18n - path label translation', t => {
|
|
1601
|
+
const ownProps = {
|
|
1602
|
+
uischema: coreUISchema
|
|
1603
|
+
};
|
|
1604
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1605
|
+
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1606
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1607
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1608
|
+
switch(key){
|
|
1609
|
+
case 'firstName.a': return 'my message';
|
|
1610
|
+
default: return defaultMessage;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1615
|
+
t.is(props.options[0].label, 'my message');
|
|
1616
|
+
});
|
|
1617
|
+
|
|
1618
|
+
test('mapStateToEnumControlProps - i18n - defaultMessage translation', t => {
|
|
1619
|
+
const ownProps = {
|
|
1620
|
+
uischema: coreUISchema
|
|
1621
|
+
};
|
|
1622
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1623
|
+
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1624
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1625
|
+
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1626
|
+
switch(defaultMessage){
|
|
1627
|
+
case 'a': return 'my message';
|
|
1628
|
+
default: return defaultMessage;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1633
|
+
t.is(props.options[0].label, 'my message');
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1636
|
+
test('mapStateToEnumControlProps - i18n - i18n key translation', t => {
|
|
1637
|
+
const ownProps = {
|
|
1638
|
+
uischema: coreUISchema
|
|
1639
|
+
};
|
|
1640
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1641
|
+
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1642
|
+
(state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
|
|
1643
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1644
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1645
|
+
switch(key){
|
|
1646
|
+
case 'my-key.a': return 'my message';
|
|
1647
|
+
default: return defaultMessage;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1652
|
+
t.is(props.options[0].label, 'my message');
|
|
1653
|
+
});
|
|
1654
|
+
|
|
1655
|
+
test('mapStateToOneOfEnumControlProps - i18n - should not crash without i18n', t => {
|
|
1656
|
+
const ownProps = {
|
|
1657
|
+
uischema: coreUISchema
|
|
1658
|
+
};
|
|
1659
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1660
|
+
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1661
|
+
state.jsonforms.i18n = undefined;
|
|
1662
|
+
|
|
1663
|
+
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1664
|
+
t.is(props.options[0].label, 'foo');
|
|
1665
|
+
});
|
|
1666
|
+
|
|
1667
|
+
test('mapStateToOneOfEnumControlProps- i18n - default translation has no effect', t => {
|
|
1668
|
+
const ownProps = {
|
|
1669
|
+
uischema: coreUISchema
|
|
1670
|
+
};
|
|
1671
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1672
|
+
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1673
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1674
|
+
|
|
1675
|
+
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1676
|
+
t.is(props.options[0].label, 'foo');
|
|
1677
|
+
});
|
|
1678
|
+
|
|
1679
|
+
test('mapStateToOneOfEnumControlProps - i18n - path label translation', t => {
|
|
1680
|
+
const ownProps = {
|
|
1681
|
+
uischema: coreUISchema
|
|
1682
|
+
};
|
|
1683
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1684
|
+
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1685
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1686
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1687
|
+
switch(key){
|
|
1688
|
+
case 'firstName.foo': return 'my message';
|
|
1689
|
+
default: return defaultMessage;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1694
|
+
t.is(props.options[0].label, 'my message');
|
|
1695
|
+
});
|
|
1696
|
+
|
|
1697
|
+
test('mapStateToOneOfEnumControlProps - i18n - default message translation', t => {
|
|
1698
|
+
const ownProps = {
|
|
1699
|
+
uischema: coreUISchema
|
|
1700
|
+
};
|
|
1701
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1702
|
+
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1703
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1704
|
+
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1705
|
+
switch(defaultMessage){
|
|
1706
|
+
case 'foo': return 'my message';
|
|
1707
|
+
default: return defaultMessage;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1712
|
+
t.is(props.options[0].label, 'my message');
|
|
1713
|
+
});
|
|
1714
|
+
|
|
1715
|
+
test('mapStateToOneOfEnumControlProps - i18n - i18n key translation', t => {
|
|
1716
|
+
const ownProps = {
|
|
1717
|
+
uischema: coreUISchema
|
|
1718
|
+
};
|
|
1719
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1720
|
+
(state.jsonforms.core.schema.properties.firstName.oneOf as any) =
|
|
1721
|
+
[{const: 'a', title: 'foo', i18n: 'my-foo'}, {const: 'b', title: 'bar', i18n:'my-bar'}];
|
|
1722
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1723
|
+
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1724
|
+
switch(key){
|
|
1725
|
+
case 'my-foo': return 'my message';
|
|
1726
|
+
default: return defaultMessage;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1731
|
+
t.is(props.options[0].label, 'my message');
|
|
1732
|
+
});
|