@@ -36,9 +36,13 @@ import { UPDATE_DATA, UpdateAction } from '../../src/actions';
3636import configureStore from 'redux-mock-store' ;
3737import {
3838 ControlElement ,
39+ createAjv ,
40+ defaultErrorTranslator ,
3941 JsonFormsState ,
42+ JsonSchema ,
4043 RuleEffect ,
41- UISchemaElement
44+ UISchemaElement ,
45+ validate
4246} from '../../src' ;
4347import { enumToEnumOptionMapper } from '../../src/util/renderer' ;
4448
@@ -270,6 +274,29 @@ test('mapStateToCellProps - id', t => {
270274 t . is ( props . id , '#/properties/firstName' ) ;
271275} ) ;
272276
277+ test ( 'mapStateToCellProps - translated error' , t => {
278+ const ownProps = {
279+ uischema : coreUISchema ,
280+ id : '#/properties/firstName'
281+ } ;
282+ const state = createState ( coreUISchema ) ;
283+ const schema = state . jsonforms . core ?. schema as JsonSchema ;
284+ const data = state . jsonforms . core ?. data as any ;
285+ // mark firstName as required, delete the value from data, then get errors from ajv from the compiled schema
286+ schema . required = [ "firstName" ] ;
287+ delete data . firstName ;
288+ const ajv = createAjv ( ) ;
289+ const v = ajv . compile ( schema ) ;
290+ state . jsonforms . errors = validate ( v , data ) ;
291+ // add a mock i18n state to verify that the error gets translated
292+ state . jsonforms . i18n = {
293+ translateError : ( error ) => `i18n-error:${ error . keyword } ` ,
294+ translate : ( id : string ) => `i18n-key:${ id } `
295+ } ;
296+ const props = mapStateToCellProps ( state , ownProps ) ;
297+ t . is ( props . errors , 'i18n-error:required' ) ;
298+ } ) ;
299+
273300test ( 'mapStateToEnumCellProps - set default options for dropdown list' , t => {
274301 const uischema : ControlElement = {
275302 type : 'Control' ,
0 commit comments