Skip to content

Commit a2ae7fe

Browse files
authored
Merge pull request #75 from oslabs-beta/rydang/actiontest
rewrote action test
2 parents 8a7b9c8 + a58930d commit a2ae7fe

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/app/__tests__/action.test.jsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ import React from 'react';
22
import { configure, shallow } from 'enzyme';
33
import Adapter from 'enzyme-adapter-react-16';
44
import Action from '../components/Action';
5+
import { changeView, changeSlider } from '../actions/actions';
56

67
configure({ adapter: new Adapter() });
78

89
describe('unit testing for Action.jsx', () => {
910
let wrapper;
1011
const props = {
1112
selected: true,
12-
handleChangeSnapshot: jest.fn(),
13-
handleJumpSnapshot: jest.fn(),
13+
sliderIndex: 1,
1414
index: 1,
15+
dispatch: jest.fn(),
1516
};
1617
beforeEach(() => {
1718
wrapper = shallow(<Action {...props} />);
19+
props.dispatch.mockClear();
1820
});
1921

2022
describe('Component', () => {
@@ -32,9 +34,14 @@ describe('unit testing for Action.jsx', () => {
3234
expect(wrapper.find('.action-component-text').text()).toEqual(props.index.toString());
3335
});
3436

35-
test('should invoke changeSnapshot method when clicked', () => {
37+
test('should invoke dispatch method when clicked', () => {
3638
wrapper.find('.action-component').simulate('click');
37-
expect(props.handleChangeSnapshot).toHaveBeenCalled();
39+
expect(props.dispatch).toHaveBeenCalled();
40+
});
41+
42+
test('dispatch should send a changeView action', () => {
43+
wrapper.find('.action-component').simulate('click');
44+
expect(props.dispatch.mock.calls[0][0]).toEqual(changeView(props.index));
3845
});
3946
});
4047

@@ -48,13 +55,14 @@ describe('unit testing for Action.jsx', () => {
4855
).toHaveLength(1);
4956
});
5057

51-
test('should invoke jumpSnapshot method when clicked', () => {
52-
wrapper
53-
.find('.action-component')
54-
.children()
55-
.find('.jump-button')
56-
.simulate('click');
57-
expect(props.handleJumpSnapshot).toHaveBeenCalled();
58+
test('should invoke dispatch method when clicked', () => {
59+
wrapper.find('.jump-button').simulate('click', { stopPropagation() { } });
60+
expect(props.dispatch).toHaveBeenCalled();
61+
});
62+
63+
test('dispatch should send a changeSlider action', () => {
64+
wrapper.find('.jump-button').simulate('click', { stopPropagation() { } });
65+
expect(props.dispatch.mock.calls[0][0]).toEqual(changeSlider(props.index));
5866
});
5967
});
6068
});

0 commit comments

Comments
 (0)