Skip to content

Commit

Permalink
review: add oneOf test
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin-sommer committed Nov 22, 2024
1 parent 630689f commit c939d29
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/core/test/anyOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,8 @@ describe('anyOf', () => {
properties: {
foo: {
anyOf: [
{
type: 'string',
default: 'defaultfoo',
},
{
type: 'boolean',
default: true,
},
{ type: 'string', default: 'defaultfoo' },
{ type: 'boolean', default: true },
],
},
},
Expand Down
34 changes: 34 additions & 0 deletions packages/core/test/oneOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,37 @@ describe('oneOf', () => {
);
});

it('should assign a default value and set defaults on option change for scalar types schemas', () => {
const { node, onChange } = createFormComponent({
schema: {
type: 'object',
properties: {
foo: {
oneOf: [
{ type: 'string', default: 'defaultfoo' },
{ type: 'boolean', default: true },
],
},
},
},
});
sinon.assert.calledWithMatch(onChange.lastCall, {
formData: { foo: 'defaultfoo' },
});

const $select = node.querySelector('select');

act(() => {
fireEvent.change($select, {
target: { value: $select.options[1].value },
});
});

sinon.assert.calledWithMatch(onChange.lastCall, {
formData: { foo: true },
});
});

it('should render a custom widget', () => {
const schema = {
type: 'object',
Expand Down Expand Up @@ -573,6 +604,7 @@ describe('oneOf', () => {
},
};
const formContext = { root: 'root-id', root_userId: 'userId-id' };

function CustomSchemaField(props) {
const { formContext, idSchema } = props;
return (
Expand All @@ -582,6 +614,7 @@ describe('oneOf', () => {
</>
);
}

const { node } = createFormComponent({
schema,
formData: { userId: 'foobarbaz' },
Expand Down Expand Up @@ -1598,6 +1631,7 @@ describe('oneOf', () => {
},
},
};

function customValidate(formData, errors) {
errors.userId.addError('test');
return errors;
Expand Down

0 comments on commit c939d29

Please sign in to comment.