|
1 | 1 | /* eslint-disable react/jsx-filename-extension */
|
2 | 2 |
|
3 |
| -import { shallow, configure } from 'enzyme'; |
| 3 | +import { shallow, mount, configure } from 'enzyme'; |
4 | 4 | import React from 'react';
|
5 | 5 | import Adapter from 'enzyme-adapter-react-16';
|
6 | 6 | import ActionContainer from '../containers/ActionContainer';
|
7 |
| - |
| 7 | +import { useStoreContext } from '../store'; |
| 8 | +import { emptySnapshots } from '../actions/actions'; |
| 9 | +import Action from '../components/Action'; |
8 | 10 |
|
9 | 11 | configure({ adapter: new Adapter() });
|
10 | 12 |
|
11 |
| -const props = { |
12 |
| - snapshots: [], |
13 |
| - snapshotIndex: 1, |
14 |
| - handleChangeSnapshot: jest.fn(), |
15 |
| - handleJumpSnapshot: jest.fn(), |
16 |
| - emptySnapshot: jest.fn(), |
| 13 | +const state = { |
| 14 | + tabs: { |
| 15 | + 87: { |
| 16 | + snapshots: [1,2,3,4], |
| 17 | + sliderIndex: 0, |
| 18 | + viewIndex: -1, |
| 19 | + }, |
| 20 | + }, |
| 21 | + currentTab: 87, |
17 | 22 | };
|
18 | 23 |
|
| 24 | +const dispatch = jest.fn(); |
19 | 25 |
|
20 |
| -describe('testing the emptySnapshot button', () => { |
21 |
| - test.skip('emptySnapshot button should be called', () => { |
22 |
| - const wrapper = shallow((<ActionContainer {...props} />)); |
| 26 | +jest.mock('../store'); |
| 27 | +useStoreContext.mockImplementation(() => [state, dispatch]); |
23 | 28 |
|
24 |
| - wrapper.find('.empty-button').simulate('click'); |
| 29 | +let wrapper; |
25 | 30 |
|
26 |
| - expect(props.emptySnapshot).toHaveBeenCalled(); |
| 31 | +beforeEach(() => { |
| 32 | + wrapper = shallow(<ActionContainer />); |
| 33 | + useStoreContext.mockClear(); |
| 34 | + dispatch.mockClear(); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('testing the emptySnapshot button', () => { |
| 38 | + test('emptySnapshot button should dispatch action upon click', () => { |
| 39 | + wrapper.find('.empty-button').simulate('click'); |
| 40 | + expect(dispatch.mock.calls.length).toBe(1); |
| 41 | + }); |
| 42 | + test('emptying snapshots should send emptySnapshot action to dispatch', () => { |
| 43 | + wrapper.find('.empty-button').simulate('click'); |
| 44 | + expect(dispatch.mock.calls[0][0]).toEqual(emptySnapshots()); |
27 | 45 | });
|
28 | 46 | });
|
| 47 | + |
| 48 | +test('number of actions should reflect snapshots array', () => { |
| 49 | + expect(wrapper.find(Action).length).toBe(state.tabs[state.currentTab].snapshots.length); |
| 50 | +}); |
0 commit comments