Skip to content

Commit 41b3d1e

Browse files
review: add oneOf test
1 parent 0576943 commit 41b3d1e

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

packages/core/test/anyOf.test.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,8 @@ describe('anyOf', () => {
172172
properties: {
173173
foo: {
174174
anyOf: [
175-
{
176-
type: 'string',
177-
default: 'defaultfoo',
178-
},
179-
{
180-
type: 'boolean',
181-
default: true,
182-
},
175+
{ type: 'string', default: 'defaultfoo' },
176+
{ type: 'boolean', default: true },
183177
],
184178
},
185179
},

packages/core/test/oneOf.test.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,37 @@ describe('oneOf', () => {
222222
);
223223
});
224224

225+
it('should assign a default value and set defaults on option change for scalar types schemas', () => {
226+
const { node, onChange } = createFormComponent({
227+
schema: {
228+
type: 'object',
229+
properties: {
230+
foo: {
231+
oneOf: [
232+
{ type: 'string', default: 'defaultfoo' },
233+
{ type: 'boolean', default: true },
234+
],
235+
},
236+
},
237+
},
238+
});
239+
sinon.assert.calledWithMatch(onChange.lastCall, {
240+
formData: { foo: 'defaultfoo' },
241+
});
242+
243+
const $select = node.querySelector('select');
244+
245+
act(() => {
246+
fireEvent.change($select, {
247+
target: { value: $select.options[1].value },
248+
});
249+
});
250+
251+
sinon.assert.calledWithMatch(onChange.lastCall, {
252+
formData: { foo: true },
253+
});
254+
});
255+
225256
it('should render a custom widget', () => {
226257
const schema = {
227258
type: 'object',
@@ -573,6 +604,7 @@ describe('oneOf', () => {
573604
},
574605
};
575606
const formContext = { root: 'root-id', root_userId: 'userId-id' };
607+
576608
function CustomSchemaField(props) {
577609
const { formContext, idSchema } = props;
578610
return (
@@ -582,6 +614,7 @@ describe('oneOf', () => {
582614
</>
583615
);
584616
}
617+
585618
const { node } = createFormComponent({
586619
schema,
587620
formData: { userId: 'foobarbaz' },
@@ -1598,6 +1631,7 @@ describe('oneOf', () => {
15981631
},
15991632
},
16001633
};
1634+
16011635
function customValidate(formData, errors) {
16021636
errors.userId.addError('test');
16031637
return errors;

0 commit comments

Comments
 (0)