Skip to content

Commit 0fe4586

Browse files
committed
[material] Add oneOf tests
1 parent 4eb1005 commit 0fe4586

File tree

3 files changed

+440
-7
lines changed

3 files changed

+440
-7
lines changed

packages/examples/src/1253.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,53 @@ const schema2 = {
5555
}
5656
};
5757

58+
const schema3 = {
59+
type: 'object',
60+
properties: {
61+
thingOrThings: {
62+
oneOf: [
63+
{
64+
title: 'Thing',
65+
type: 'object',
66+
properties: {
67+
thing: {
68+
$ref: '#/definitions/thing'
69+
}
70+
}
71+
},
72+
{
73+
$ref: '#/definitions/thingArray'
74+
}
75+
]
76+
}
77+
},
78+
definitions: {
79+
thing: {
80+
title: 'Thing',
81+
type: 'string'
82+
},
83+
thingArray: {
84+
title: 'Things',
85+
type: 'array',
86+
items: {
87+
$ref: '#/definitions/thing'
88+
}
89+
}
90+
}
91+
};
92+
5893
const uischema2 = {
5994
type: 'Control',
6095
label: 'Value',
6196
scope: '#/properties/oneOrMoreThings'
6297
};
6398

99+
const uischema3 = {
100+
type: 'Control',
101+
label: 'Value',
102+
scope: '#/properties/thingOrThings'
103+
};
104+
64105
registerExamples([
65106
{
66107
name: 'issue-1253',
@@ -73,10 +114,30 @@ registerExamples([
73114

74115
registerExamples([
75116
{
76-
name: 'issue-1253-field',
77-
label: 'issue 1253 (oneOf) - missing field',
117+
name: 'issue-1253-wrong-path-binding',
118+
label: 'issue 1253 (oneOf) - wrong path binding',
119+
data,
120+
schema: schema,
121+
uischema: uischema
122+
}
123+
]);
124+
125+
registerExamples([
126+
{
127+
name: 'issue-1253-field-missing-field',
128+
label: 'issue 1253 (oneOf) - missing field renderer',
78129
data,
79130
schema: schema2,
80131
uischema: uischema2
81132
}
82133
]);
134+
135+
registerExamples([
136+
{
137+
name: 'issue-1253-add-button-empty-row',
138+
label: 'issue 1253 (oneOf) - add button does nothing',
139+
data,
140+
schema: schema3,
141+
uischema: uischema3
142+
}
143+
]);

packages/material/src/complex/MaterialOneOfRenderer.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MaterialOneOfRenderer extends React.Component<ControlProps & OneOfProps, M
6060
const { path, schema, handleChange } = this.props;
6161
handleChange(
6262
path,
63-
createDefaultValue(schema.oneOf[this.state.selectedOneOf])
63+
createDefaultValue(schema.oneOf[this.state.newOneOfIndex])
6464
);
6565
this.setState({
6666
open: false,
@@ -69,7 +69,7 @@ class MaterialOneOfRenderer extends React.Component<ControlProps & OneOfProps, M
6969
});
7070
};
7171

72-
handleChange = (_event: any, newOneOfIndex: number) => {
72+
handleTabChange = (_event: any, newOneOfIndex: number) => {
7373
this.setState({
7474
open: true,
7575
newOneOfIndex
@@ -79,7 +79,7 @@ class MaterialOneOfRenderer extends React.Component<ControlProps & OneOfProps, M
7979
render() {
8080

8181
const oneOf = 'oneOf';
82-
const { schema, path, rootSchema } = this.props;
82+
const { schema, path, rootSchema, id } = this.props;
8383
const _schema = resolveSubSchemas(schema, rootSchema, oneOf);
8484
const oneOfRenderInfos = createCombinatorRenderInfos((_schema as JsonSchema).oneOf, rootSchema, oneOf);
8585

@@ -90,7 +90,7 @@ class MaterialOneOfRenderer extends React.Component<ControlProps & OneOfProps, M
9090
combinatorKeyword={'oneOf'}
9191
path={path}
9292
/>
93-
<Tabs value={this.state.selectedOneOf} onChange={this.handleChange}>
93+
<Tabs value={this.state.selectedOneOf} onChange={this.handleTabChange}>
9494
{oneOfRenderInfos.map(oneOfRenderInfo => <Tab key={oneOfRenderInfo.label} label={oneOfRenderInfo.label}/>)}
9595
</Tabs>
9696
{
@@ -122,7 +122,7 @@ class MaterialOneOfRenderer extends React.Component<ControlProps & OneOfProps, M
122122
<Button onClick={this.cancel} color='primary'>
123123
No
124124
</Button>
125-
<Button onClick={this.confirm} color='primary' autoFocus>
125+
<Button onClick={this.confirm} color='primary' autoFocus id={`oneOf-${id}-confirm-yes`}>
126126
Yes
127127
</Button>
128128
</DialogActions>

0 commit comments

Comments
 (0)