diff --git a/packages/core/src/util/renderer.ts b/packages/core/src/util/renderer.ts index cd43d3ee5..c0217a5c7 100644 --- a/packages/core/src/util/renderer.ts +++ b/packages/core/src/util/renderer.ts @@ -877,7 +877,8 @@ const mapStateToCombinatorRendererProps = ( 'required', 'additionalProperties', 'type', - 'enum' + 'enum', + 'const' ]; const dataIsValid = (errors: ErrorObject[]): boolean => { return ( diff --git a/packages/core/test/util/renderer.test.ts b/packages/core/test/util/renderer.test.ts index de25b96f2..fb3237064 100644 --- a/packages/core/test/util/renderer.test.ts +++ b/packages/core/test/util/renderer.test.ts @@ -51,6 +51,9 @@ import { JsonFormsCore, JsonFormsState, JsonSchema, + JsonSchema7, + mapStateToAnyOfProps, + OwnPropsOfControl, rankWith, RuleEffect, UISchemaElement @@ -1218,3 +1221,59 @@ test('computeLabel - should add asterisk if required but hideRequiredAsterisk is const computedLabel = computeLabel('Test Label', true, false); t.is(computedLabel, 'Test Label*'); }); + +test('mapStateToAnyOfProps - const constraint in anyOf schema should return correct indexOfFittingSchema', t => { + const uischema: ControlElement = { + type: 'Control', + scope: '#' + }; + const schema: JsonSchema7 = { + anyOf: [ + { + type: "object", + properties: { + type: { + const: "type1" + } + } + }, + { + type: "object", + properties: { + type: { + const: "type2" + } + } + }, + { + type: "object", + properties: { + type: { + const: "type3" + } + } + } + ] + }; + const ownProps: OwnPropsOfControl = { + visible: true, + uischema, + path: 'foo' + }; + const state = { + jsonforms: { + core: { + ajv: createAjv(), + schema, + data: { + foo: { type: "type3"} + }, + uischema, + errors: [] as ErrorObject[] + } + } + }; + const props = mapStateToAnyOfProps(state, ownProps); + console.log(JSON.stringify(props, null, 2)); + t.is(props.indexOfFittingSchema, 2); +});