@jsonforms/core 2.5.2-alpha.0 → 3.0.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.
Files changed (273) hide show
  1. package/README.md +1 -1
  2. package/docs/assets/js/search.json +1 -1
  3. package/docs/enums/ruleeffect.html +4 -4
  4. package/docs/globals.html +1061 -1120
  5. package/docs/index.html +64 -91
  6. package/docs/interfaces/addcellrendereraction.html +3 -3
  7. package/docs/interfaces/addrendereraction.html +3 -3
  8. package/docs/interfaces/adduischemaaction.html +3 -3
  9. package/docs/interfaces/andcondition.html +2 -2
  10. package/docs/interfaces/arraycontrolprops.html +22 -22
  11. package/docs/interfaces/arraylayoutprops.html +22 -22
  12. package/docs/interfaces/categorization.html +5 -5
  13. package/docs/interfaces/category.html +5 -5
  14. package/docs/interfaces/cellprops.html +14 -14
  15. package/docs/interfaces/combinatorrendererprops.html +13 -13
  16. package/docs/interfaces/combinatorsubschemarenderinfo.html +3 -3
  17. package/docs/interfaces/composablecondition.html +2 -2
  18. package/docs/interfaces/condition.html +1 -1
  19. package/docs/interfaces/controlelement.html +5 -5
  20. package/docs/interfaces/controlprops.html +17 -17
  21. package/docs/interfaces/controlstate.html +2 -2
  22. package/docs/interfaces/controlwithdetailprops.html +18 -18
  23. package/docs/interfaces/dispatchcellprops.html +13 -13
  24. package/docs/interfaces/dispatchcellstateprops.html +13 -13
  25. package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
  26. package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
  27. package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
  28. package/docs/interfaces/enumcellprops.html +15 -15
  29. package/docs/interfaces/enumoption.html +2 -2
  30. package/docs/interfaces/formatted.html +2 -2
  31. package/docs/interfaces/grouplayout.html +5 -5
  32. package/docs/interfaces/horizontallayout.html +4 -4
  33. package/docs/interfaces/initaction.html +6 -6
  34. package/docs/interfaces/initactionoptions.html +3 -17
  35. package/docs/interfaces/jsonformscellrendererregistryentry.html +2 -2
  36. package/docs/interfaces/jsonformscore.html +7 -21
  37. package/docs/interfaces/jsonformsdefaultdataregistryentry.html +2 -2
  38. package/docs/interfaces/jsonformsextendedstate.html +1 -1
  39. package/docs/interfaces/{jsonformslocalestate.html → jsonformsi18nstate.html} +20 -20
  40. package/docs/interfaces/jsonformsprops.html +9 -24
  41. package/docs/interfaces/jsonformsrendererregistryentry.html +2 -2
  42. package/docs/interfaces/jsonformsstate.html +1 -1
  43. package/docs/interfaces/jsonformsstore.html +5 -5
  44. package/docs/interfaces/jsonformssubstates.html +18 -8
  45. package/docs/interfaces/jsonformsuischemaregistryentry.html +2 -2
  46. package/docs/interfaces/labeldescription.html +2 -2
  47. package/docs/interfaces/labelelement.html +4 -4
  48. package/docs/interfaces/layout.html +4 -4
  49. package/docs/interfaces/layoutprops.html +10 -10
  50. package/docs/interfaces/leafcondition.html +3 -3
  51. package/docs/interfaces/orcondition.html +2 -2
  52. package/docs/interfaces/ownpropsofcell.html +10 -10
  53. package/docs/interfaces/ownpropsofcontrol.html +9 -9
  54. package/docs/interfaces/ownpropsofenum.html +1 -1
  55. package/docs/interfaces/ownpropsofenumcell.html +11 -11
  56. package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
  57. package/docs/interfaces/ownpropsoflayout.html +9 -9
  58. package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
  59. package/docs/interfaces/ownpropsofrenderer.html +8 -8
  60. package/docs/interfaces/registerdefaultdataaction.html +3 -3
  61. package/docs/interfaces/removecellrendereraction.html +3 -3
  62. package/docs/interfaces/removerendereraction.html +3 -3
  63. package/docs/interfaces/removeuischemaaction.html +2 -2
  64. package/docs/interfaces/rendererprops.html +9 -9
  65. package/docs/interfaces/rule.html +2 -2
  66. package/docs/interfaces/schemabasedcondition.html +3 -3
  67. package/docs/interfaces/scopable.html +1 -1
  68. package/docs/interfaces/setajvaction.html +3 -3
  69. package/docs/interfaces/setconfigaction.html +2 -2
  70. package/docs/interfaces/setlocaleaction.html +3 -3
  71. package/docs/interfaces/setschemaaction.html +2 -2
  72. package/docs/interfaces/{setlocalizeduischemasaction.html → settranslatoraction.html} +29 -15
  73. package/docs/interfaces/setuischemaaction.html +2 -2
  74. package/docs/interfaces/setvalidationmodeaction.html +2 -2
  75. package/docs/interfaces/statepropsofarraycontrol.html +18 -18
  76. package/docs/interfaces/statepropsofarraylayout.html +18 -18
  77. package/docs/interfaces/statepropsofcell.html +13 -13
  78. package/docs/interfaces/statepropsofcombinator.html +12 -12
  79. package/docs/interfaces/statepropsofcontrol.html +16 -16
  80. package/docs/interfaces/statepropsofcontrolwithdetail.html +17 -17
  81. package/docs/interfaces/statepropsofenumcell.html +14 -14
  82. package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -23
  83. package/docs/interfaces/statepropsoflayout.html +10 -10
  84. package/docs/interfaces/statepropsofmasteritem.html +7 -7
  85. package/docs/interfaces/statepropsofrenderer.html +9 -9
  86. package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
  87. package/docs/interfaces/uischemaelement.html +3 -3
  88. package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
  89. package/docs/interfaces/updateaction.html +3 -3
  90. package/docs/interfaces/updatecoreaction.html +6 -6
  91. package/docs/interfaces/updateerrorsaction.html +2 -2
  92. package/docs/interfaces/{setlocalizedschemasaction.html → updatei18naction.html} +43 -15
  93. package/docs/interfaces/verticallayout.html +4 -4
  94. package/docs/interfaces/withclassname.html +1 -1
  95. package/lib/Helpers.d.ts +5 -0
  96. package/lib/Helpers.js +33 -0
  97. package/lib/Helpers.js.map +1 -0
  98. package/lib/actions/actions.d.ts +181 -0
  99. package/lib/actions/actions.js +173 -0
  100. package/lib/actions/actions.js.map +1 -0
  101. package/lib/actions/index.d.ts +1 -180
  102. package/lib/actions/index.js +26 -122
  103. package/lib/actions/index.js.map +1 -1
  104. package/lib/configDefault.js +2 -1
  105. package/lib/configDefault.js.map +1 -1
  106. package/lib/generators/Generate.d.ts +6 -0
  107. package/lib/generators/Generate.js +35 -0
  108. package/lib/generators/Generate.js.map +1 -0
  109. package/lib/generators/index.d.ts +3 -10
  110. package/lib/generators/index.js +28 -9
  111. package/lib/generators/index.js.map +1 -1
  112. package/lib/generators/schema.d.ts +1 -1
  113. package/lib/generators/schema.js +3 -1
  114. package/lib/generators/schema.js.map +1 -1
  115. package/lib/generators/uischema.d.ts +1 -2
  116. package/lib/generators/uischema.js +12 -10
  117. package/lib/generators/uischema.js.map +1 -1
  118. package/lib/i18n/i18nTypes.d.ts +15 -0
  119. package/lib/i18n/i18nTypes.js +3 -0
  120. package/lib/i18n/i18nTypes.js.map +1 -0
  121. package/lib/i18n/i18nUtil.d.ts +11 -0
  122. package/lib/i18n/i18nUtil.js +58 -0
  123. package/lib/i18n/i18nUtil.js.map +1 -0
  124. package/lib/i18n/index.d.ts +2 -0
  125. package/lib/i18n/index.js +6 -0
  126. package/lib/i18n/index.js.map +1 -0
  127. package/lib/index.d.ts +6 -18
  128. package/lib/index.js +10 -15
  129. package/lib/index.js.map +1 -1
  130. package/lib/jsonforms-core.js +9 -12
  131. package/lib/jsonforms-core.js.map +1 -1
  132. package/lib/models/draft4.js +2 -1
  133. package/lib/models/draft4.js.map +1 -1
  134. package/lib/models/index.d.ts +5 -0
  135. package/lib/models/index.js +33 -0
  136. package/lib/models/index.js.map +1 -0
  137. package/lib/models/jsonSchema.js +24 -0
  138. package/lib/models/jsonSchema.js.map +1 -1
  139. package/lib/models/uischema.js +29 -2
  140. package/lib/models/uischema.js.map +1 -1
  141. package/lib/reducers/cells.d.ts +1 -1
  142. package/lib/reducers/cells.js +27 -1
  143. package/lib/reducers/cells.js.map +1 -1
  144. package/lib/reducers/config.d.ts +1 -1
  145. package/lib/reducers/config.js +5 -3
  146. package/lib/reducers/config.js.map +1 -1
  147. package/lib/reducers/core.d.ts +5 -7
  148. package/lib/reducers/core.js +78 -63
  149. package/lib/reducers/core.js.map +1 -1
  150. package/lib/reducers/default-data.d.ts +1 -1
  151. package/lib/reducers/default-data.js +6 -3
  152. package/lib/reducers/default-data.js.map +1 -1
  153. package/lib/reducers/i18n.d.ts +8 -11
  154. package/lib/reducers/i18n.js +40 -23
  155. package/lib/reducers/i18n.js.map +1 -1
  156. package/lib/reducers/index.d.ts +9 -49
  157. package/lib/reducers/index.js +33 -91
  158. package/lib/reducers/index.js.map +1 -1
  159. package/lib/reducers/reducers.d.ts +37 -0
  160. package/lib/reducers/reducers.js +107 -0
  161. package/lib/reducers/reducers.js.map +1 -0
  162. package/lib/reducers/renderers.d.ts +1 -1
  163. package/lib/reducers/renderers.js +27 -1
  164. package/lib/reducers/renderers.js.map +1 -1
  165. package/lib/reducers/selectors.d.ts +15 -0
  166. package/lib/reducers/selectors.js +56 -0
  167. package/lib/reducers/selectors.js.map +1 -0
  168. package/lib/reducers/uischemas.d.ts +2 -2
  169. package/lib/reducers/uischemas.js +9 -6
  170. package/lib/reducers/uischemas.js.map +1 -1
  171. package/lib/store.d.ts +5 -8
  172. package/lib/store.js +24 -0
  173. package/lib/store.js.map +1 -1
  174. package/lib/testers/index.d.ts +1 -204
  175. package/lib/testers/index.js +3 -376
  176. package/lib/testers/index.js.map +1 -1
  177. package/lib/testers/testers.d.ts +203 -0
  178. package/lib/testers/testers.js +421 -0
  179. package/lib/testers/testers.js.map +1 -0
  180. package/lib/util/Formatted.js +24 -0
  181. package/lib/util/Formatted.js.map +1 -1
  182. package/lib/util/array.js +25 -0
  183. package/lib/util/array.js.map +1 -1
  184. package/lib/util/cell.d.ts +11 -4
  185. package/lib/util/cell.js +61 -17
  186. package/lib/util/cell.js.map +1 -1
  187. package/lib/util/combinators.d.ts +2 -3
  188. package/lib/util/combinators.js +5 -2
  189. package/lib/util/combinators.js.map +1 -1
  190. package/lib/util/ids.js +8 -4
  191. package/lib/util/ids.js.map +1 -1
  192. package/lib/util/index.d.ts +11 -45
  193. package/lib/util/index.js +14 -104
  194. package/lib/util/index.js.map +1 -1
  195. package/lib/util/label.d.ts +1 -2
  196. package/lib/util/label.js +7 -4
  197. package/lib/util/label.js.map +1 -1
  198. package/lib/util/path.d.ts +2 -1
  199. package/lib/util/path.js +12 -6
  200. package/lib/util/path.js.map +1 -1
  201. package/lib/util/renderer.d.ts +17 -17
  202. package/lib/util/renderer.js +163 -76
  203. package/lib/util/renderer.js.map +1 -1
  204. package/lib/util/resolvers.d.ts +1 -14
  205. package/lib/util/resolvers.js +9 -215
  206. package/lib/util/resolvers.js.map +1 -1
  207. package/lib/util/runtime.d.ts +12 -2
  208. package/lib/util/runtime.js +59 -17
  209. package/lib/util/runtime.js.map +1 -1
  210. package/lib/util/schema.js +27 -1
  211. package/lib/util/schema.js.map +1 -1
  212. package/lib/util/uischema.d.ts +1 -1
  213. package/lib/util/uischema.js +11 -7
  214. package/lib/util/uischema.js.map +1 -1
  215. package/lib/util/util.d.ts +31 -0
  216. package/lib/util/util.js +112 -0
  217. package/lib/util/util.js.map +1 -0
  218. package/lib/util/validator.d.ts +3 -2
  219. package/lib/util/validator.js +6 -5
  220. package/lib/util/validator.js.map +1 -1
  221. package/package.json +7 -9
  222. package/src/Helpers.ts +38 -0
  223. package/src/actions/actions.ts +345 -0
  224. package/src/actions/index.ts +1 -312
  225. package/src/configDefault.ts +1 -0
  226. package/src/generators/Generate.ts +43 -0
  227. package/src/generators/index.ts +3 -21
  228. package/src/generators/schema.ts +1 -1
  229. package/src/generators/uischema.ts +4 -4
  230. package/src/i18n/i18nTypes.ts +17 -0
  231. package/src/i18n/i18nUtil.ts +76 -0
  232. package/src/i18n/index.ts +2 -0
  233. package/src/index.ts +7 -31
  234. package/src/models/draft4.ts +1 -0
  235. package/src/models/index.ts +30 -0
  236. package/src/models/jsonSchema.ts +1 -0
  237. package/src/models/uischema.ts +1 -0
  238. package/src/reducers/cells.ts +2 -1
  239. package/src/reducers/config.ts +2 -1
  240. package/src/reducers/core.ts +74 -81
  241. package/src/reducers/default-data.ts +2 -1
  242. package/src/reducers/i18n.ts +42 -35
  243. package/src/reducers/index.ts +9 -158
  244. package/src/reducers/reducers.ts +148 -0
  245. package/src/reducers/renderers.ts +2 -1
  246. package/src/reducers/selectors.ts +65 -0
  247. package/src/reducers/uischemas.ts +4 -2
  248. package/src/store.ts +11 -8
  249. package/src/testers/index.ts +1 -516
  250. package/src/testers/testers.ts +547 -0
  251. package/src/util/Formatted.ts +1 -0
  252. package/src/util/array.ts +25 -0
  253. package/src/util/cell.ts +91 -19
  254. package/src/util/combinators.ts +2 -4
  255. package/src/util/ids.ts +1 -0
  256. package/src/util/index.ts +11 -126
  257. package/src/util/label.ts +2 -2
  258. package/src/util/path.ts +4 -1
  259. package/src/util/renderer.ts +168 -85
  260. package/src/util/resolvers.ts +2 -261
  261. package/src/util/runtime.ts +46 -2
  262. package/src/util/schema.ts +26 -1
  263. package/src/util/uischema.ts +2 -1
  264. package/src/util/util.ts +127 -0
  265. package/src/util/validator.ts +5 -8
  266. package/test/reducers/core.test.ts +31 -223
  267. package/test/util/cell.test.ts +33 -2
  268. package/test/util/renderer.test.ts +483 -3
  269. package/test/util/resolvers.test.ts +1 -59
  270. package/test/util/runtime.test.ts +264 -4
  271. package/docs/interfaces/labels.html +0 -157
  272. package/docs/interfaces/schemaref.html +0 -160
  273. package/docs/interfaces/schemarefs.html +0 -138
@@ -51,12 +51,19 @@ import {
51
51
  JsonFormsCore,
52
52
  JsonFormsState,
53
53
  JsonSchema,
54
+ JsonSchema7,
55
+ mapStateToAnyOfProps,
56
+ OwnPropsOfControl,
54
57
  rankWith,
55
58
  RuleEffect,
56
- UISchemaElement
59
+ UISchemaElement,
60
+ setValidationMode,
61
+ defaultJsonFormsI18nState,
62
+ i18nJsonSchema,
63
+ mapStateToEnumControlProps,
64
+ mapStateToOneOfEnumControlProps
57
65
  } from '../../src';
58
66
  import { ErrorObject } from 'ajv';
59
- import { setValidationMode } from '../../lib';
60
67
 
61
68
  const middlewares: Redux.Middleware[] = [];
62
69
  const mockStore = configureStore<JsonFormsState>(middlewares);
@@ -381,7 +388,7 @@ test('mapStateToControlProps - errors', t => {
381
388
  };
382
389
  const clonedState = _.cloneDeep(createState(coreUISchema));
383
390
  const error: ErrorObject = {
384
- dataPath: 'firstName',
391
+ instancePath: '/firstName',
385
392
  message: 'Duff beer',
386
393
  keyword: 'whatever',
387
394
  schemaPath: '',
@@ -1218,3 +1225,476 @@ test('computeLabel - should add asterisk if required but hideRequiredAsterisk is
1218
1225
  const computedLabel = computeLabel('Test Label', true, false);
1219
1226
  t.is(computedLabel, 'Test Label*');
1220
1227
  });
1228
+
1229
+ test('mapStateToAnyOfProps - const constraint in anyOf schema should return correct indexOfFittingSchema', t => {
1230
+ const uischema: ControlElement = {
1231
+ type: 'Control',
1232
+ scope: '#'
1233
+ };
1234
+ const schema: JsonSchema7 = {
1235
+ anyOf: [
1236
+ {
1237
+ type: "object",
1238
+ properties: {
1239
+ type: {
1240
+ const: "type1"
1241
+ }
1242
+ }
1243
+ },
1244
+ {
1245
+ type: "object",
1246
+ properties: {
1247
+ type: {
1248
+ const: "type2"
1249
+ }
1250
+ }
1251
+ },
1252
+ {
1253
+ type: "object",
1254
+ properties: {
1255
+ type: {
1256
+ const: "type3"
1257
+ }
1258
+ }
1259
+ }
1260
+ ]
1261
+ };
1262
+ const ownProps: OwnPropsOfControl = {
1263
+ visible: true,
1264
+ uischema,
1265
+ path: 'foo'
1266
+ };
1267
+ const state = {
1268
+ jsonforms: {
1269
+ core: {
1270
+ ajv: createAjv(),
1271
+ schema,
1272
+ data: {
1273
+ foo: { type: "type3"}
1274
+ },
1275
+ uischema,
1276
+ errors: [] as ErrorObject[]
1277
+ }
1278
+ }
1279
+ };
1280
+ const props = mapStateToAnyOfProps(state, ownProps);
1281
+ t.is(props.indexOfFittingSchema, 2);
1282
+ });
1283
+
1284
+ test('mapStateToControlProps - i18n - mapStateToControlProps should not crash without i18n', t => {
1285
+ const ownProps = {
1286
+ uischema: coreUISchema
1287
+ };
1288
+ const state: JsonFormsState = createState(coreUISchema);
1289
+ state.jsonforms.i18n = undefined;
1290
+
1291
+ const props = mapStateToControlProps(state, ownProps);
1292
+ t.is(props.label, 'First Name');
1293
+ });
1294
+
1295
+ test('mapStateToControlProps - i18n - default translation has no effect', t => {
1296
+ const ownProps = {
1297
+ uischema: coreUISchema
1298
+ };
1299
+ const state: JsonFormsState = createState(coreUISchema);
1300
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1301
+
1302
+ const props = mapStateToControlProps(state, ownProps);
1303
+ t.is(props.label, 'First Name');
1304
+ t.is(props.description, undefined);
1305
+ });
1306
+
1307
+ test('mapStateToControlProps - i18n - translation via label key', t => {
1308
+ const ownProps = {
1309
+ uischema: coreUISchema
1310
+ };
1311
+ const state: JsonFormsState = createState(coreUISchema);
1312
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1313
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1314
+ switch(key){
1315
+ case 'First Name': return 'my translation';
1316
+ default: return defaultMessage;
1317
+ }
1318
+ }
1319
+
1320
+ const props = mapStateToControlProps(state, ownProps);
1321
+ t.is(props.label, 'my translation');
1322
+ t.is(props.description, undefined);
1323
+ });
1324
+
1325
+ test('mapStateToControlProps - i18n - translation via JSON Schema i18n key', t => {
1326
+ const ownProps = {
1327
+ uischema: coreUISchema
1328
+ };
1329
+ const state: JsonFormsState = createState(coreUISchema);
1330
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1331
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1332
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1333
+ switch(key){
1334
+ case 'my-key.label': return 'my label';
1335
+ case 'my-key.description': return 'my description';
1336
+ default: return defaultMessage;
1337
+ }
1338
+ }
1339
+
1340
+ const props = mapStateToControlProps(state, ownProps);
1341
+ t.is(props.label, 'my label');
1342
+ t.is(props.description, 'my description');
1343
+ });
1344
+
1345
+ test('mapStateToControlProps - i18n - translation via UI Schema i18n key', t => {
1346
+ const ownProps = {
1347
+ uischema: coreUISchema
1348
+ };
1349
+ const state: JsonFormsState = createState(coreUISchema);
1350
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1351
+ ownProps.uischema = {...ownProps.uischema, options: {i18n: 'my-key'}};
1352
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1353
+ switch(key){
1354
+ case 'my-key.label': return 'my label';
1355
+ case 'my-key.description': return 'my description';
1356
+ default: return defaultMessage;
1357
+ }
1358
+ }
1359
+
1360
+ const props = mapStateToControlProps(state, ownProps);
1361
+ t.is(props.label, 'my label');
1362
+ t.is(props.description, 'my description');
1363
+ });
1364
+
1365
+ test('mapStateToControlProps - i18n errors - should not crash without i18n', t => {
1366
+ const ownProps = {
1367
+ uischema: coreUISchema
1368
+ };
1369
+ const state: JsonFormsState = createState(coreUISchema);
1370
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
1371
+ state.jsonforms.core = coreReducer(
1372
+ state.jsonforms.core,
1373
+ init(
1374
+ state.jsonforms.core.data,
1375
+ state.jsonforms.core.schema,
1376
+ state.jsonforms.core.uischema,
1377
+ createAjv()
1378
+ )
1379
+ );
1380
+ state.jsonforms.i18n = undefined;
1381
+
1382
+ const props = mapStateToControlProps(state, ownProps);
1383
+ t.is(props.errors, 'must match pattern "[0-9]+"');
1384
+ });
1385
+
1386
+ test('mapStateToControlProps - i18n errors - default translation has no effect', t => {
1387
+ const ownProps = {
1388
+ uischema: coreUISchema
1389
+ };
1390
+ const state: JsonFormsState = createState(coreUISchema);
1391
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
1392
+ state.jsonforms.core = coreReducer(
1393
+ state.jsonforms.core,
1394
+ init(
1395
+ state.jsonforms.core.data,
1396
+ state.jsonforms.core.schema,
1397
+ state.jsonforms.core.uischema,
1398
+ createAjv()
1399
+ )
1400
+ );
1401
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1402
+
1403
+ const props = mapStateToControlProps(state, ownProps);
1404
+ t.is(props.errors, 'must match pattern "[0-9]+"');
1405
+ });
1406
+
1407
+ test('mapStateToControlProps - i18n errors - translate via error message key', t => {
1408
+ const ownProps = {
1409
+ uischema: coreUISchema
1410
+ };
1411
+ const state: JsonFormsState = createState(coreUISchema);
1412
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
1413
+ state.jsonforms.core = coreReducer(
1414
+ state.jsonforms.core,
1415
+ init(
1416
+ state.jsonforms.core.data,
1417
+ state.jsonforms.core.schema,
1418
+ state.jsonforms.core.uischema,
1419
+ createAjv()
1420
+ )
1421
+ );
1422
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1423
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1424
+ switch(key){
1425
+ case 'must match pattern "[0-9]+"': return 'my error message';
1426
+ default: return defaultMessage;
1427
+ }
1428
+ }
1429
+
1430
+ const props = mapStateToControlProps(state, ownProps);
1431
+ t.is(props.errors, 'my error message');
1432
+ });
1433
+
1434
+ test('mapStateToControlProps - i18n errors - translate via i18 specialized error keyword key', t => {
1435
+ const ownProps = {
1436
+ uischema: coreUISchema
1437
+ };
1438
+ const state: JsonFormsState = createState(coreUISchema);
1439
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1440
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1441
+ state.jsonforms.core = coreReducer(
1442
+ state.jsonforms.core,
1443
+ init(
1444
+ state.jsonforms.core.data,
1445
+ state.jsonforms.core.schema,
1446
+ state.jsonforms.core.uischema,
1447
+ createAjv()
1448
+ )
1449
+ );
1450
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1451
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1452
+ switch(key){
1453
+ case 'my-key.error.pattern': return 'my error message';
1454
+ default: return defaultMessage;
1455
+ }
1456
+ }
1457
+
1458
+ const props = mapStateToControlProps(state, ownProps);
1459
+ t.is(props.errors, 'my error message');
1460
+ });
1461
+
1462
+ test('mapStateToControlProps - i18n errors - translate via i18 general error keyword key', t => {
1463
+ const ownProps = {
1464
+ uischema: coreUISchema
1465
+ };
1466
+ const state: JsonFormsState = createState(coreUISchema);
1467
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1468
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1469
+ state.jsonforms.core = coreReducer(
1470
+ state.jsonforms.core,
1471
+ init(
1472
+ state.jsonforms.core.data,
1473
+ state.jsonforms.core.schema,
1474
+ state.jsonforms.core.uischema,
1475
+ createAjv()
1476
+ )
1477
+ );
1478
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1479
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1480
+ switch(key){
1481
+ case 'error.pattern': return 'my error message';
1482
+ default: return defaultMessage;
1483
+ }
1484
+ }
1485
+
1486
+ const props = mapStateToControlProps(state, ownProps);
1487
+ t.is(props.errors, 'my error message');
1488
+ });
1489
+
1490
+ test('mapStateToControlProps - i18n errors - specialized keyword wins over generic keyword', t => {
1491
+ const ownProps = {
1492
+ uischema: coreUISchema
1493
+ };
1494
+ const state: JsonFormsState = createState(coreUISchema);
1495
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1496
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1497
+ state.jsonforms.core = coreReducer(
1498
+ state.jsonforms.core,
1499
+ init(
1500
+ state.jsonforms.core.data,
1501
+ state.jsonforms.core.schema,
1502
+ state.jsonforms.core.uischema,
1503
+ createAjv()
1504
+ )
1505
+ );
1506
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1507
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1508
+ switch(key){
1509
+ case 'my-key.error.pattern': return 'my key error message';
1510
+ case 'error.pattern': return 'my error message';
1511
+ default: return defaultMessage;
1512
+ }
1513
+ }
1514
+
1515
+ const props = mapStateToControlProps(state, ownProps);
1516
+ t.is(props.errors, 'my key error message');
1517
+ });
1518
+
1519
+ test('mapStateToControlProps - i18n errors - multiple errors customization', t => {
1520
+ const ownProps = {
1521
+ uischema: coreUISchema
1522
+ };
1523
+ const state: JsonFormsState = createState(coreUISchema);
1524
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1525
+ state.jsonforms.core.schema.properties.firstName.maxLength = 2;
1526
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1527
+ state.jsonforms.core = coreReducer(
1528
+ state.jsonforms.core,
1529
+ init(
1530
+ state.jsonforms.core.data,
1531
+ state.jsonforms.core.schema,
1532
+ state.jsonforms.core.uischema,
1533
+ createAjv()
1534
+ )
1535
+ );
1536
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1537
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1538
+ switch(key){
1539
+ case 'error.maxLength': return 'max length message';
1540
+ case 'my-key.error.pattern': return 'my key error message';
1541
+ default: return defaultMessage;
1542
+ }
1543
+ }
1544
+
1545
+ const props = mapStateToControlProps(state, ownProps);
1546
+ t.is(props.errors, 'max length message\nmy key error message');
1547
+ });
1548
+
1549
+ test('mapStateToControlProps - i18n errors - custom keyword wins over all other errors', t => {
1550
+ const ownProps = {
1551
+ uischema: coreUISchema
1552
+ };
1553
+ const state: JsonFormsState = createState(coreUISchema);
1554
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1555
+ state.jsonforms.core.schema.properties.firstName.maxLength = 2;
1556
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1557
+ state.jsonforms.core = coreReducer(
1558
+ state.jsonforms.core,
1559
+ init(
1560
+ state.jsonforms.core.data,
1561
+ state.jsonforms.core.schema,
1562
+ state.jsonforms.core.uischema,
1563
+ createAjv()
1564
+ )
1565
+ );
1566
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1567
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1568
+ switch(key){
1569
+ case 'my-key.error.custom': return 'this is my error custom error message';
1570
+ case 'my-key.error.pattern': return 'my key error message';
1571
+ case 'error.pattern': return 'my error message';
1572
+ default: return defaultMessage;
1573
+ }
1574
+ }
1575
+
1576
+ const props = mapStateToControlProps(state, ownProps);
1577
+ t.is(props.errors, 'this is my error custom error message');
1578
+ });
1579
+
1580
+ test('mapStateToEnumControlProps - i18n - should not crash without i18n', t => {
1581
+ const ownProps = {
1582
+ uischema: coreUISchema
1583
+ };
1584
+ const state: JsonFormsState = createState(coreUISchema);
1585
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1586
+ state.jsonforms.i18n = undefined;
1587
+
1588
+ const props = mapStateToEnumControlProps(state, ownProps);
1589
+ t.is(props.options[0].label, 'a');
1590
+ });
1591
+
1592
+ test('mapStateToEnumControlProps - i18n - default translation has no effect', t => {
1593
+ const ownProps = {
1594
+ uischema: coreUISchema
1595
+ };
1596
+ const state: JsonFormsState = createState(coreUISchema);
1597
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1598
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1599
+
1600
+ const props = mapStateToEnumControlProps(state, ownProps);
1601
+ t.is(props.options[0].label, 'a');
1602
+ });
1603
+
1604
+ test('mapStateToEnumControlProps - i18n - label translation', t => {
1605
+ const ownProps = {
1606
+ uischema: coreUISchema
1607
+ };
1608
+ const state: JsonFormsState = createState(coreUISchema);
1609
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1610
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1611
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1612
+ switch(key){
1613
+ case 'a': return 'my message';
1614
+ default: return defaultMessage;
1615
+ }
1616
+ }
1617
+
1618
+ const props = mapStateToEnumControlProps(state, ownProps);
1619
+ t.is(props.options[0].label, 'my message');
1620
+ });
1621
+
1622
+ test('mapStateToEnumControlProps - i18n - i18n key translation', t => {
1623
+ const ownProps = {
1624
+ uischema: coreUISchema
1625
+ };
1626
+ const state: JsonFormsState = createState(coreUISchema);
1627
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1628
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1629
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1630
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1631
+ switch(key){
1632
+ case 'my-key.a': return 'my message';
1633
+ default: return defaultMessage;
1634
+ }
1635
+ }
1636
+
1637
+ const props = mapStateToEnumControlProps(state, ownProps);
1638
+ t.is(props.options[0].label, 'my message');
1639
+ });
1640
+
1641
+ test('mapStateToOneOfEnumControlProps - i18n - should not crash without i18n', t => {
1642
+ const ownProps = {
1643
+ uischema: coreUISchema
1644
+ };
1645
+ const state: JsonFormsState = createState(coreUISchema);
1646
+ state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
1647
+ state.jsonforms.i18n = undefined;
1648
+
1649
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1650
+ t.is(props.options[0].label, 'foo');
1651
+ });
1652
+
1653
+ test('mapStateToOneOfEnumControlProps- i18n - default translation has no effect', t => {
1654
+ const ownProps = {
1655
+ uischema: coreUISchema
1656
+ };
1657
+ const state: JsonFormsState = createState(coreUISchema);
1658
+ state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
1659
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1660
+
1661
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1662
+ t.is(props.options[0].label, 'foo');
1663
+ });
1664
+
1665
+ test('mapStateToOneOfEnumControlProps - i18n - label translation', t => {
1666
+ const ownProps = {
1667
+ uischema: coreUISchema
1668
+ };
1669
+ const state: JsonFormsState = createState(coreUISchema);
1670
+ state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
1671
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1672
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1673
+ switch(key){
1674
+ case 'foo': return 'my message';
1675
+ default: return defaultMessage;
1676
+ }
1677
+ }
1678
+
1679
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1680
+ t.is(props.options[0].label, 'my message');
1681
+ });
1682
+
1683
+ test('mapStateToOneOfEnumControlProps - i18n - i18n key translation', t => {
1684
+ const ownProps = {
1685
+ uischema: coreUISchema
1686
+ };
1687
+ const state: JsonFormsState = createState(coreUISchema);
1688
+ (state.jsonforms.core.schema.properties.firstName.oneOf as any) =
1689
+ [{const: 'a', title: 'foo', i18n: 'my-foo'}, {const: 'b', title: 'bar', i18n:'my-bar'}];
1690
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1691
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1692
+ switch(key){
1693
+ case 'my-foo': return 'my message';
1694
+ default: return defaultMessage;
1695
+ }
1696
+ }
1697
+
1698
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1699
+ t.is(props.options[0].label, 'my message');
1700
+ });
@@ -22,67 +22,9 @@
22
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
23
  THE SOFTWARE.
24
24
  */
25
- import { findRefs, resolveSchema } from '../../src/util/resolvers';
25
+ import { resolveSchema } from '../../src/util/resolvers';
26
26
  import test from 'ava';
27
27
 
28
- test('findRef - does not fail on empty input object ', t => {
29
- const refObject = {};
30
- t.true(Object.keys(findRefs(refObject)).length === 0);
31
- });
32
-
33
- test('findRef - finds http ref on level 1', t => {
34
- const refObject = {
35
- type: 'object',
36
- properties: {
37
- myitem: {
38
- $ref: 'http://myref.com/ref'
39
- }
40
- }
41
- };
42
- t.true(Object.keys(findRefs(refObject)).length > 0);
43
- });
44
-
45
- test('findRef - finds http ref on root level ', t => {
46
- const refObject = {
47
- $ref: 'http://myref.com/ref'
48
- };
49
- t.true(Object.keys(findRefs(refObject)).length > 0);
50
- });
51
-
52
- test('findRef - finds any ref on root level ', t => {
53
- const refObject = {
54
- $ref: 'xxx'
55
- };
56
- t.true(Object.keys(findRefs(refObject)).length > 0);
57
- });
58
-
59
- test('findRef - no ref in no ref object ', t => {
60
- const refObject = {
61
- type: 'object',
62
- properties: {
63
- name: {
64
- type: 'string',
65
- minLength: 3,
66
- description: 'Please enter your name'
67
- },
68
- vegetarian: {
69
- type: 'boolean'
70
- },
71
- birthDate: {
72
- type: 'string',
73
- format: 'date',
74
- description: 'Please enter your birth date.'
75
- },
76
- nationality: {
77
- type: 'string',
78
- enum: ['DE', 'IT', 'JP', 'US', 'RU', 'Other']
79
- }
80
- }
81
- };
82
- t.true(Object.keys(findRefs(refObject)).length === 0);
83
- });
84
-
85
-
86
28
  test('resolveSchema - resolves schema with any ', t => {
87
29
  const schema = {
88
30
  type: 'object',