Skip to content

Commit aad287a

Browse files
committed
travelcontainer testing
1 parent 4f1cee9 commit aad287a

File tree

2 files changed

+55
-88
lines changed

2 files changed

+55
-88
lines changed

src/app/__tests__/TravelContainer.test.js

Lines changed: 50 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { shallow, configure } from 'enzyme';
33
import React from 'react';
44
import Adapter from 'enzyme-adapter-react-16';
55
import TravelContainer from '../containers/TravelContainer';
6+
import MainSlider from '../components/MainSlider';
7+
import Dropdown from '../components/Dropdown';
68
import { useStoreContext } from '../store';
79
import { moveBackward, moveForward } from '../actions/actions';
810

@@ -31,113 +33,73 @@ beforeEach(() => {
3133
dispatch.mockClear();
3234
});
3335

36+
describe('<TravelContainer /> rendering', () => {
37+
test('should render three buttons', () => {
38+
expect(wrapper.find('button')).toHaveLength(3);
39+
});
40+
test('should render one MainSlider', () => {
41+
expect(wrapper.find(MainSlider)).toHaveLength(1);
42+
});
43+
test('should render one Dropdown', () => {
44+
expect(wrapper.find(Dropdown)).toHaveLength(1);
45+
});
46+
});
47+
3448
describe('testing the backward-button', () => {
35-
test('backward-button should dispatch action upon click', () => {
49+
test('should dispatch action upon click', () => {
3650
wrapper.find('.backward-button').simulate('click');
3751
expect(dispatch.mock.calls.length).toBe(1);
3852
});
3953

40-
// backward-button invokes dispatch(moveBackward())
41-
// moveBackward is an actionCreator
42-
test('backward-button should send moveBackward action to dispatch', () => {
54+
test('should send moveBackward action to dispatch', () => {
4355
wrapper.find('.backward-button').simulate('click');
4456
expect(dispatch.mock.calls[0][0]).toEqual(moveBackward());
4557
});
4658
});
4759

48-
// test('testing the forward-button', () => {
49-
// wrapper.find('.forward-button').simulate('click');
50-
// expect(dispatch.mock.calls.length).toBe(1);
51-
// });
52-
53-
// These are fake props to be used during dropdown tests
54-
55-
// const dropdownProps = {
56-
// selectedOption: {
57-
// value: 1,
58-
// label: 'label',
59-
// },
60-
// options: [0.5, 1, 2],
61-
// onChange: jest.fn(),
62-
// };
63-
64-
// const options = [
65-
// { value: 2000, label: '0.5x' },
66-
// { value: 1000, label: '1.0x' },
67-
// { value: 500, label: '2.0x' },
68-
// ];
69-
70-
// describe('testing the backward and forward buttons', () => {
71-
// test('if the backward button rewinds the playback', () => {
72-
// const wrapper = shallow(<TravelContainer {...props} />);
73-
74-
// wrapper.find('.backward-button').simulate('click');
75-
76-
// expect(props.moveBackward).toHaveBeenCalled();
77-
// });
78-
79-
// test('if the forward button forwards the playback', () => {
80-
// const wrapper = shallow(<TravelContainer {...props} />);
81-
82-
// wrapper.find('.forward-button').simulate('click');
83-
84-
// expect(props.moveForward).toHaveBeenCalled();
85-
// });
86-
// });
87-
88-
// describe('testing the play button', () => {
89-
// test('if the play button starts the playback', () => {
90-
// const wrapper = shallow(<TravelContainer {...props} />);
91-
92-
// wrapper.find('.play-button').simulate('click');
93-
94-
// expect(props.play).toHaveBeenCalled();
95-
// });
96-
97-
// test("if playback is not running, the button should state 'Play'", () => {
98-
// const wrapper = shallow(<TravelContainer {...props} />);
99-
100-
// wrapper.find('.play-button');
101-
102-
// expect(wrapper.find('.play-button').text()).toBe('Play');
103-
// });
104-
105-
// test("if playback is running, the button should state 'Pause'", () => {
106-
// props.playing = true;
60+
describe('testing the forward-button', () => {
61+
test('should dispatch action upon click', () => {
62+
wrapper.find('.forward-button').simulate('click');
63+
expect(dispatch.mock.calls.length).toBe(1);
64+
});
10765

108-
// const wrapper = shallow(<TravelContainer {...props} />);
66+
test('should send moveforward action to dispatch', () => {
67+
wrapper.find('.forward-button').simulate('click');
68+
expect(dispatch.mock.calls[0][0]).toEqual(moveForward());
69+
});
70+
});
10971

110-
// wrapper.find('.play-button');
72+
describe('testing the play-button', () => {
73+
test("should display 'pause' if playing is true", () => {
74+
state.tabs[87].playing = true;
75+
wrapper = shallow(<TravelContainer snapshotsLength={2} />);
76+
expect(wrapper.find('.play-button').text()).toBe('Pause');
77+
});
11178

112-
// expect(wrapper.find('.play-button').text()).toBe('Pause');
113-
// });
114-
// });
79+
test('should display play if playing is false', () => {
80+
state.tabs[87].playing = false;
81+
wrapper = shallow(<TravelContainer snapshotsLength={2} />);
82+
expect(wrapper.find('.play-button').text()).toBe('Play');
83+
});
84+
});
11585

11686
// describe('testing the playback speed', () => {
11787
// test('if the playback dropdown states 0.5x the speed should be 0.5x', () => {
11888
// const wrapper = shallow(<TravelContainer {...props} />);
119-
12089
// wrapper.find('Dropdown').simulate('change', { value: ['val'] });
121-
// // wrapper.find('select').simulate('change', { value : 'hello'});
122-
// // console.log('val',wrapper.find('Dropdown').simulate('select', { value: ['val'] }));
123-
// // expect(wrapper.find('Dropdown').text()).toBe('0.5x')
90+
// wrapper.find('select').simulate('change', { value: 'hello' });
91+
// console.log('val', wrapper.find('Dropdown').simulate('select', { value: ['val'] }));
92+
// expect(wrapper.find('Dropdown').text()).toBe('0.5x');
12493
// expect(wrapper.find('select [selected]').val()).toEqual('key');
12594
// });
126-
// // test('if the playback dropdown states 1x the speed should be 1x', () => {
127-
128-
// // const wrapper = shallow(<TravelContainer { ...dropdownProps } />);
129-
130-
// // expect(wrapper.find('Dropdown').label).toBe('1.0x')
131-
132-
// // });
95+
// test('if the playback dropdown states 1x the speed should be 1x', () => {
96+
// const wrapper = shallow(<TravelContainer {...dropdownProps} />);
13397

134-
// // test('if the playback dropdown states 2x the speed should be 2x', () => {
135-
136-
// // const wrapper = shallow(<TravelContainer { ...dropdownProps } />);
137-
138-
// // wrapper.find('Dropdown').simulate('click');
139-
140-
// // expect(wrapper.find('Dropdown').label).toBe('2.0x')
141-
142-
// // });
98+
// expect(wrapper.find('Dropdown').label).toBe('1.0x');
99+
// });
100+
// test('if the playback dropdown states 2x the speed should be 2x', () => {
101+
// const wrapper = shallow(<TravelContainer {...dropdownProps} />);
102+
// wrapper.find('Dropdown').simulate('click');
103+
// expect(wrapper.find('Dropdown').label).toBe('2.0x');
104+
// });
143105
// });
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[` 1`] = `undefined`;
4+
5+
exports[`<TravelContainer /> rendering should render three buttons 1`] = `ShallowWrapper {}`;

0 commit comments

Comments
 (0)