Skip to content

Commit

Permalink
Add support for const constraint to mapStateToCombinatorRendererProps…
Browse files Browse the repository at this point in the history
… indexOfFittingSchema resolution
  • Loading branch information
richturner committed Jul 22, 2021
1 parent d6edf4b commit 2dcdf8c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/util/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,8 @@ const mapStateToCombinatorRendererProps = (
'required',
'additionalProperties',
'type',
'enum'
'enum',
'const'
];
const dataIsValid = (errors: ErrorObject[]): boolean => {
return (
Expand Down
59 changes: 59 additions & 0 deletions packages/core/test/util/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ import {
JsonFormsCore,
JsonFormsState,
JsonSchema,
JsonSchema7,
mapStateToAnyOfProps,
OwnPropsOfControl,
rankWith,
RuleEffect,
UISchemaElement
Expand Down Expand Up @@ -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);
});

0 comments on commit 2dcdf8c

Please sign in to comment.