Skip to content

Commit ac730ac

Browse files
authored
Merge pull request #71 from oslabs-beta/rydang/buttons
buttons containers test rewrite
2 parents 6bfe8c3 + 83f609a commit ac730ac

File tree

3 files changed

+87
-38
lines changed

3 files changed

+87
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ package/react-time-travel-*.tgz
55
tictactoe
66
parents
77
coverage
8+
src/extension/build.zip

src/app/__tests__/ButtonsContainer.test.js

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,107 @@ import { shallow, configure } from 'enzyme';
33
import React from 'react';
44
import Adapter from 'enzyme-adapter-react-16';
55
import ButtonsContainer from '../containers/ButtonsContainer';
6-
6+
import { useStoreContext } from '../store';
7+
import { toggleMode } from '../actions/actions';
78

89
configure({ adapter: new Adapter() });
910

10-
const props = {
11-
toggleMode: jest.fn(),
12-
importSnapshots: jest.fn(),
13-
exportSnapshots: jest.fn(),
14-
mode: {
15-
paused: false,
16-
locked: false,
17-
persist: false,
11+
const state = {
12+
tabs: {
13+
87: {
14+
snapshots: [1, 2, 3, 4],
15+
sliderIndex: 0,
16+
viewIndex: -1,
17+
mode: {
18+
paused: false,
19+
locked: false,
20+
persist: false,
21+
},
22+
},
1823
},
24+
currentTab: 87,
1925
};
2026

21-
describe('testing the bottom buttons', () => {
22-
test('if pause button is invoked', () => {
23-
const wrapper = shallow(<ButtonsContainer {...props} />);
27+
const currentTab = state.tabs[state.currentTab];
2428

25-
wrapper.find('.pause-button').simulate('click');
29+
const dispatch = jest.fn();
2630

27-
expect(props.toggleMode).toHaveBeenCalled();
28-
});
31+
jest.mock('../store');
32+
useStoreContext.mockImplementation(() => [state, dispatch]);
2933

30-
test('if lock button is invoked', () => {
31-
const wrapper = shallow(<ButtonsContainer {...props} />);
34+
let wrapper;
3235

33-
wrapper.find('.lock-button').simulate('click');
34-
35-
expect(props.toggleMode).toHaveBeenCalled();
36+
describe('testing the bottom buttons', () => {
37+
beforeEach(() => {
38+
wrapper = shallow(<ButtonsContainer />);
39+
dispatch.mockClear();
40+
useStoreContext.mockClear();
41+
currentTab.mode = {
42+
locked: false,
43+
paused: false,
44+
persist: false,
45+
};
3646
});
3747

38-
test('if persist button is invoked', () => {
39-
const wrapper = shallow(<ButtonsContainer {...props} />);
40-
41-
wrapper.find('.persist-button').simulate('click');
42-
43-
expect(props.toggleMode).toHaveBeenCalled();
48+
describe('pause button testing', () => {
49+
beforeEach(() => {
50+
wrapper.find('.pause-button').simulate('click');
51+
});
52+
test('pause button dispatches upon click', () => {
53+
expect(dispatch.mock.calls.length).toBe(1);
54+
});
55+
56+
test('pause button dispatches toggleMode action', () => {
57+
expect(dispatch.mock.calls[0][0]).toEqual(toggleMode('paused'));
58+
});
59+
60+
test('pause button displays state', () => {
61+
expect(wrapper.find('.pause-button').text()).toBe('Pause');
62+
state.tabs[state.currentTab].mode.paused = true;
63+
wrapper = shallow(<ButtonsContainer />);
64+
expect(wrapper.find('.pause-button').text()).toBe('Resume');
65+
});
4466
});
4567

46-
test('if import button is invoked', () => {
47-
const wrapper = shallow(<ButtonsContainer {...props} />);
48-
49-
wrapper.find('.import-button').simulate('click');
5068

51-
expect(props.importSnapshots).toHaveBeenCalled();
69+
describe('lock button testing', () => {
70+
beforeEach(() => {
71+
wrapper.find('.lock-button').simulate('click');
72+
});
73+
test('lock button dispatches upon click', () => {
74+
expect(dispatch.mock.calls.length).toBe(1);
75+
});
76+
77+
test('lock button dispatches toggleMode action', () => {
78+
expect(dispatch.mock.calls[0][0]).toEqual(toggleMode('locked'));
79+
});
80+
81+
test('lock button displays state', () => {
82+
expect(wrapper.find('.lock-button').text()).toBe('Lock');
83+
state.tabs[state.currentTab].mode.locked = true;
84+
wrapper = shallow(<ButtonsContainer />);
85+
expect(wrapper.find('.lock-button').text()).toBe('Unlock');
86+
});
5287
});
5388

54-
test('if export button is invoked', () => {
55-
const wrapper = shallow(<ButtonsContainer {...props} />);
56-
57-
wrapper.find('.export-button').simulate('click');
58-
59-
expect(props.exportSnapshots).toHaveBeenCalled();
89+
describe('persist button testing', () => {
90+
beforeEach(() => {
91+
wrapper.find('.persist-button').simulate('click');
92+
});
93+
94+
test('persist button dispatches upon click', () => {
95+
expect(dispatch.mock.calls.length).toBe(1);
96+
});
97+
98+
test('persist button dispatches toggleMode action', () => {
99+
expect(dispatch.mock.calls[0][0]).toEqual(toggleMode('persist'));
100+
});
101+
102+
test('persist button displays state', () => {
103+
expect(wrapper.find('.persist-button').text()).toBe('Persist');
104+
state.tabs[state.currentTab].mode.persist = true;
105+
wrapper = shallow(<ButtonsContainer />);
106+
expect(wrapper.find('.persist-button').text()).toBe('Unpersist');
107+
});
60108
});
61109
});

src/app/__tests__/actionContainer.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/jsx-filename-extension */
22

3-
import { shallow, mount, configure } from 'enzyme';
3+
import { shallow, configure } from 'enzyme';
44
import React from 'react';
55
import Adapter from 'enzyme-adapter-react-16';
66
import ActionContainer from '../containers/ActionContainer';

0 commit comments

Comments
 (0)