@@ -15,6 +15,7 @@ describe('<Wizard />', () => {
1515 let getRegisteredFieldsSchemaMock ;
1616 let getRegisteredFieldsNestedSchemaMock ;
1717 let getValuesNestedSchema ;
18+ let initialValues ;
1819
1920 const nextButtonClick = ( wrapper ) => {
2021 wrapper . find ( 'button' ) . at ( 0 ) . simulate ( 'click' ) ;
@@ -36,25 +37,31 @@ describe('<Wizard />', () => {
3637 wrapper . update ( ) ;
3738 } ;
3839
40+ const cancelButtonClickWithHeader = ( wrapper ) => {
41+ wrapper . find ( 'button' ) . at ( 3 ) . simulate ( 'click' ) ;
42+ wrapper . update ( ) ;
43+ } ;
44+
3945 const changeValue = ( wrapper , value ) => {
4046 wrapper . find ( 'input' ) . instance ( ) . value = value ;
4147 wrapper . find ( 'input' ) . simulate ( 'change' ) ;
4248 wrapper . update ( ) ;
4349 } ;
4450
4551 beforeEach ( ( ) => {
52+ initialValues = {
53+ 'foo-field' : 'foo-field-value' ,
54+ 'bar-field' : 'bar-field-value' ,
55+ 'not-visited-field' : 'not-visted-field-value' ,
56+ } ;
4657 initialProps = {
4758 FieldProvider,
4859 title : 'Wizard' ,
4960 description : 'wizard description' ,
5061 formOptions : {
5162 renderForm : ( [ { name } ] ) => < div key = { name } > { name } </ div > ,
5263 getState : ( ) => ( {
53- values : {
54- 'foo-field' : 'foo-field-value' ,
55- 'bar-field' : 'bar-field-value' ,
56- 'not-visited-field' : 'not-visted-field-value' ,
57- } ,
64+ values : initialValues ,
5865 } ) ,
5966 onCancel : jest . fn ( ) ,
6067 onSubmit : jest . fn ( ) ,
@@ -194,6 +201,19 @@ describe('<Wizard />', () => {
194201 } ) ;
195202 } ) ;
196203
204+ it ( 'should pass values to cancel' , ( ) => {
205+ const onCancel = jest . fn ( ) ;
206+ const wrapper = mount ( < Wizard
207+ { ...initialProps }
208+ fields = { schema }
209+ formOptions = { { ...initialProps . formOptions , onCancel } }
210+ /> ) ;
211+
212+ cancelButtonClickWithHeader ( wrapper ) ;
213+
214+ expect ( onCancel ) . toHaveBeenCalledWith ( initialValues ) ;
215+ } ) ;
216+
197217 it ( 'should submit data when nested schema' , ( ) => {
198218 const onSubmit = jest . fn ( ) ;
199219 const wrapper = mount ( < Wizard
0 commit comments