File tree Expand file tree Collapse file tree 1 file changed +92
-0
lines changed Expand file tree Collapse file tree 1 file changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -510,6 +510,98 @@ describe('Form.vue', () => {
510510 } )
511511 } )
512512
513+ it ( 'should get fields model when submit - dynamic cases' , ( done ) => {
514+ const submitHandler = sinon . spy ( )
515+
516+ let args = null
517+ vm = createForm ( {
518+ action : '/' ,
519+ model : {
520+ inputValue : '1' ,
521+ inputValue2 : ''
522+ } ,
523+ schema : {
524+ fields : [
525+ {
526+ type : 'input' ,
527+ modelKey : 'inputValue' ,
528+ label : 'Input' ,
529+ props : {
530+ placeholder : 'Please input'
531+ } ,
532+ rules : {
533+ required : true
534+ }
535+ } ,
536+ {
537+ type : 'submit' ,
538+ label : 'Submit'
539+ }
540+ ]
541+ }
542+ } , {
543+ submit : function ( e ) {
544+ e . preventDefault ( )
545+ args = arguments
546+ submitHandler . apply ( this , args )
547+ }
548+ } )
549+ setTimeout ( ( ) => {
550+ // submit
551+ vm . $el . querySelector ( '.cube-btn' ) . click ( )
552+ expect ( submitHandler )
553+ . to . be . calledOnce
554+ expect ( args [ 1 ] . inputValue )
555+ . to . equal ( '1' )
556+ expect ( args [ 1 ] . inputValue2 )
557+ . to . equal ( '' )
558+ expect ( args [ 2 ] . inputValue2 )
559+ . to . be . undefined
560+ // dynamic add field
561+ vm . schema . fields = [
562+ {
563+ type : 'input' ,
564+ modelKey : 'inputValue' ,
565+ label : 'Input' ,
566+ props : {
567+ placeholder : 'Please input'
568+ } ,
569+ rules : {
570+ required : true
571+ }
572+ } ,
573+ {
574+ type : 'input' ,
575+ modelKey : 'inputValue2' ,
576+ label : 'Input2' ,
577+ rules : {
578+ required : true
579+ }
580+ } ,
581+ {
582+ type : 'submit' ,
583+ label : 'Submit'
584+ }
585+ ]
586+ setTimeout ( ( ) => {
587+ vm . model . inputValue2 = '2'
588+ setTimeout ( ( ) => {
589+ // submit again
590+ vm . $el . querySelector ( '.cube-btn' ) . click ( )
591+ expect ( submitHandler )
592+ . to . be . calledTwice
593+ expect ( args [ 1 ] . inputValue )
594+ . to . equal ( '1' )
595+ expect ( args [ 1 ] . inputValue2 )
596+ . to . equal ( '2' )
597+ expect ( args [ 2 ] . inputValue2 )
598+ . to . equal ( '2' )
599+ done ( )
600+ } )
601+ } )
602+ } )
603+ } )
604+
513605 function createForm ( props = { } , events = { } ) {
514606 return createVue ( {
515607 template : '<cube-form v-bind="props" v-on="events" />' ,
You can’t perform that action at this time.
0 commit comments