|
| 1 | +/* eslint-disable react/jsx-filename-extension */ |
| 2 | + |
| 3 | +import { shallow, configure } from 'enzyme'; |
| 4 | +import React from 'react'; |
| 5 | +import Adapter from 'enzyme-adapter-react-16'; |
| 6 | +import MainContainer from '../containers/MainContainer'; |
| 7 | +import { useStoreContext } from '../store'; |
| 8 | +import { |
| 9 | + addNewSnapshots, initialConnect, setPort |
| 10 | +} from '../actions/actions'; |
| 11 | +import HeadContainer from '../containers/HeadContainer'; |
| 12 | +import ActionContainer from '../containers/ActionContainer'; |
| 13 | +import StateContainer from '../containers/StateContainer'; |
| 14 | +import TravelContainer from '../containers/TravelContainer'; |
| 15 | +import ButtonsContainer from '../containers/ButtonsContainer'; |
| 16 | +import Action from '../components/Action'; |
| 17 | + |
| 18 | +configure({ adapter: new Adapter() }); |
| 19 | + |
| 20 | +const state = { |
| 21 | + tabs: { |
| 22 | + 87: { |
| 23 | + snapshots: [1, 2, 3, 4], |
| 24 | + sliderIndex: 0, |
| 25 | + viewIndex: -1, |
| 26 | + }, |
| 27 | + }, |
| 28 | + currentTab: 87, |
| 29 | +}; |
| 30 | + |
| 31 | +const dispatch = jest.fn(); |
| 32 | + |
| 33 | +jest.mock('../store'); |
| 34 | +useStoreContext.mockImplementation(() => [state, dispatch]); |
| 35 | + |
| 36 | +let wrapper; |
| 37 | + |
| 38 | +beforeEach(() => { |
| 39 | + wrapper = shallow(<MainContainer />); |
| 40 | + useStoreContext.mockClear(); |
| 41 | + dispatch.mockClear(); |
| 42 | +}); |
| 43 | + |
| 44 | +describe('MainContainer rendering', () => { |
| 45 | + test('With no connection, shouldn not render any containers', () => { |
| 46 | + expect(wrapper.find(HeadContainer).length).toBe(0); |
| 47 | + expect(wrapper.find(ActionContainer).length).toBe(0); |
| 48 | + expect(wrapper.find(StateContainer).length).toBe(0); |
| 49 | + expect(wrapper.find(TravelContainer).length).toBe(0); |
| 50 | + expect(wrapper.find(ButtonsContainer).length).toBe(0); |
| 51 | + }); |
| 52 | + test('With connection established, should render All containers', () => { |
| 53 | + expect(wrapper.find(HeadContainer).length).toBe(1); |
| 54 | + expect(wrapper.find(ActionContainer).length).toBe(1); |
| 55 | + expect(wrapper.find(StateContainer).length).toBe(1); |
| 56 | + expect(wrapper.find(TravelContainer).length).toBe(1); |
| 57 | + expect(wrapper.find(ButtonsContainer).length).toBe(1); |
| 58 | + }); |
| 59 | +}); |
0 commit comments