@@ -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