-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support overridable combinator labels
'title' can be defined in both the resolving subschema and the resolved to subschema. This fix enhances JSON Forms to take both of these cases into account when resolving subschemas in combinators. Intermediate titles will still be ignored. Fixes #2164
- Loading branch information
Showing
2 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import test from 'ava'; | ||
import { createCombinatorRenderInfos } from '../../src/util/combinators'; | ||
import { ControlElement } from '../../src'; | ||
|
||
const rootSchema = { | ||
type: 'object', | ||
properties: { | ||
widget: { | ||
anyOf: [ | ||
{ | ||
$ref: '#/definitions/Dua', | ||
}, | ||
{ | ||
$ref: '#/definitions/Lipa', | ||
}, | ||
], | ||
}, | ||
}, | ||
definitions: { | ||
Dua: { | ||
title: 'Dua', | ||
type: 'object', | ||
properties: { name: { type: 'string' } }, | ||
}, | ||
Lipa: { | ||
title: 'Lipa', | ||
type: 'object', | ||
properties: { name: { type: 'string' } }, | ||
}, | ||
}, | ||
}; | ||
|
||
const rootSchemaWithOverrides = { | ||
...rootSchema, | ||
properties: { | ||
...rootSchema.properties, | ||
widget: { | ||
...rootSchema.properties.widget, | ||
anyOf: [ | ||
{ | ||
...rootSchema.properties.widget.anyOf[0], | ||
title: 'DuaOverride', | ||
}, | ||
{ | ||
...rootSchema.properties.widget.anyOf[1], | ||
title: 'LipaOverride', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
const control: ControlElement = { | ||
type: 'Control', | ||
scope: '#', | ||
}; | ||
|
||
test('createCombinatorRenderInfos - uses titles for labels when subschemas are refs', (t) => { | ||
const [duaRenderInfo, lipaRenderInfo] = createCombinatorRenderInfos( | ||
rootSchema.properties.widget.anyOf, | ||
rootSchema, | ||
'anyOf', | ||
control, | ||
'widget', | ||
[] | ||
); | ||
t.deepEqual(duaRenderInfo.label, 'Dua'); | ||
t.deepEqual(lipaRenderInfo.label, 'Lipa'); | ||
}); | ||
|
||
test('createCombinatorRenderInfos - uses overrides for labels when subschemas are refs', (t) => { | ||
const [duaRenderInfo, lipaRenderInfo] = createCombinatorRenderInfos( | ||
rootSchemaWithOverrides.properties.widget.anyOf, | ||
rootSchemaWithOverrides, | ||
'anyOf', | ||
control, | ||
'widget', | ||
[] | ||
); | ||
t.deepEqual(duaRenderInfo.label, 'DuaOverride'); | ||
t.deepEqual(lipaRenderInfo.label, 'LipaOverride'); | ||
}); |