Skip to content

Commit eeff2d4

Browse files
committed
rewrote actioncontainer tests
1 parent 4734e25 commit eeff2d4

File tree

5 files changed

+174
-59
lines changed

5 files changed

+174
-59
lines changed

babel.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module.exports = {
88
},
99
},
1010
],
11-
['@babel/preset-react'],
11+
'@babel/preset-react',
1212
],
13-
plugins: [
14-
["@babel/plugin-proposal-decorators", { legacy: true }]
15-
]
13+
// plugins: [
14+
// ['@babel/plugin-proposal-decorators', { legacy: true }],
15+
// ],
1616
};

package-lock.json

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
"jest": "^24.8.0",
4343
"jest-cli": "^24.8.0",
4444
"node-sass": "^4.12.0",
45+
"proxyquire": "^2.1.2",
4546
"sass": "^1.22.9",
4647
"sass-loader": "^7.2.0",
48+
"sinon": "^7.4.1",
4749
"style-loader": "^0.23.1",
4850
"webpack": "^4.39.1",
4951
"webpack-chrome-extension-reloader": "^1.3.0",

src/app/__tests__/StateContainer.test.js

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
11
/* eslint-disable react/jsx-filename-extension */
22

3-
import { shallow, configure } from 'enzyme';
3+
import { shallow, mount, configure } from 'enzyme';
44
import React from 'react';
55
import Adapter from 'enzyme-adapter-react-16';
66
import ActionContainer from '../containers/ActionContainer';
7-
7+
import { useStoreContext } from '../store';
8+
import { emptySnapshots } from '../actions/actions';
9+
import Action from '../components/Action';
810

911
configure({ adapter: new Adapter() });
1012

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,
1722
};
1823

24+
const dispatch = jest.fn();
1925

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]);
2328

24-
wrapper.find('.empty-button').simulate('click');
29+
let wrapper;
2530

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());
2745
});
2846
});
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

Comments
 (0)