import React from 'react'; import {mount} from 'enzyme'; import {Provider} from 'react-redux'; import {createStore, applyMiddleware, combineReducers} from 'redux'; import ReduxThunkTester from 'redux-thunk-tester'; import Field from '../../field'; import InitialValuesWizard from './initial-values-wizard'; import {reducer} from '../../index'; interface IValuesForm1 { firstName?: string; lastName?: string; } interface IValuesForm2 { phone?: string; email?: string; } interface IValuesForm3 { dob?: string; hobby?: string; } const renderComponent = (onSubmit?) => { const reduxThunkTester = new ReduxThunkTester(); const store = createStore( combineReducers({reduxForm: reducer}), applyMiddleware(reduxThunkTester.createReduxThunkHistoryMiddleware()), ); const component = mount( , ); return { reduxThunkTester, getStep1: (): IReduxFormState => store.getState().reduxForm.step1 as IReduxFormState, getStep2: (): IReduxFormState => store.getState().reduxForm.step2 as IReduxFormState, getStep3: (): IReduxFormState => store.getState().reduxForm.step3 as IReduxFormState, getWizardExample: (): IReduxFormWizard => store.getState().reduxForm.wizardExample as IReduxFormWizard, component, }; }; describe('', () => { test('Render inputs form 1', () => { const {component} = renderComponent(); expect(component.find('input')).toMatchSnapshot(); }); test('Render InitialValuesWizard: store of wizard', () => { const {getWizardExample} = renderComponent(); expect(getWizardExample()).toMatchSnapshot(); }); test('submit on page 1: store of wizard', () => { const {getWizardExample, component} = renderComponent(); component.find('form').simulate('submit'); expect(getWizardExample()).toMatchSnapshot(); }); test('submit on page 1, change step 2, reset step 2 (inputs)', () => { const {component} = renderComponent(); component.find('form').simulate('submit'); component.find('input').at(0).simulate('change', {target: {value: 'some number'}}); component.find('input').at(1).simulate('change', {target: {value: 'some email'}}); component.find('#resetButton').simulate('click'); expect(component.find('input')).toMatchSnapshot(); }); test('submit on page 1, change step 2, reset step 2 (wizard store)', () => { const {getWizardExample, component} = renderComponent(); component.find('form').simulate('submit'); component.find('input').at(0).simulate('change', {target: {value: 'some number'}}); component.find('input').at(1).simulate('change', {target: {value: 'some email'}}); component.find('#resetButton').simulate('click'); expect(getWizardExample()).toMatchSnapshot(); }); });