Created
December 27, 2017 15:34
-
-
Save kis/8f8d5caf543ff2a67c21b9bb854448a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { createMockStore } from 'redux-test-utils'; | |
import { shallowWithStore } from 'enzyme-redux'; | |
import { mount, shallow, configure } from 'enzyme'; | |
import Adapter from 'enzyme-adapter-react-16'; | |
import TravellersScreen from './index'; | |
import Counter from '../../../../components/Counter'; | |
configure({ adapter: new Adapter() }); | |
const testState = { | |
activeTrip: { | |
travellers: [{dateOfBirth: ''}], | |
roamInsurance: { | |
totalPrice: 2 | |
} | |
}, | |
user: { | |
config: { | |
accountRn: '123123', | |
apiAccessToken: 'qwe', | |
identityToken: 'asd' | |
} | |
} | |
}; | |
const store = createMockStore(testState); | |
describe('<TravellersScreen />', () => { | |
let wrapper; | |
let wrapperDived; | |
let inst; | |
beforeAll(() => { | |
wrapper = shallowWithStore(<TravellersScreen />, store); | |
wrapperDived = wrapper.dive(); | |
inst = wrapperDived.instance(); | |
}); | |
it('<TravellersScreen /> component contains <Counter />', () => { | |
expect(wrapperDived.find('Counter').exists()).toBeTruthy(); | |
}); | |
it('<TravellersScreen /> component could add traveller', () => { | |
inst.addTravellers(''); | |
expect(wrapperDived.state().travellers).toHaveLength(2); | |
}); | |
it('<TravellersScreen /> component could remove traveller', () => { | |
inst.removeTraveller(1); | |
expect(wrapperDived.state().travellers).toHaveLength(1); | |
}); | |
it("<TravellersScreen /> component couldn't remove if single traveller exists", () => { | |
inst.removeTraveller(0); | |
expect(wrapperDived.state().travellers).toHaveLength(1); | |
}); | |
it("<TravellersScreen /> can't contain more then 8 travellers", () => { | |
const initialTravellers = new Array(7).fill({dateOfBirth: ''}, 0, 7); | |
initialTravellers.forEach(t => inst.addTravellers(t.dateOfBirth)); | |
expect(wrapperDived.state().travellers).toHaveLength(8); | |
const counterInstance = wrapperDived.find('Counter').dive().instance(); | |
counterInstance.onIncrement(); | |
counterInstance.setState({ count: 8 }, () => { | |
counterInstance.onIncrement(); | |
expect(wrapperDived.state().travellers).toHaveLength(8); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment