@@ -3,6 +3,8 @@ import { shallow, configure } from 'enzyme';
3
3
import React from 'react' ;
4
4
import Adapter from 'enzyme-adapter-react-16' ;
5
5
import TravelContainer from '../containers/TravelContainer' ;
6
+ import MainSlider from '../components/MainSlider' ;
7
+ import Dropdown from '../components/Dropdown' ;
6
8
import { useStoreContext } from '../store' ;
7
9
import { moveBackward , moveForward } from '../actions/actions' ;
8
10
@@ -31,113 +33,73 @@ beforeEach(() => {
31
33
dispatch . mockClear ( ) ;
32
34
} ) ;
33
35
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
+
34
48
describe ( 'testing the backward-button' , ( ) => {
35
- test ( 'backward-button should dispatch action upon click' , ( ) => {
49
+ test ( 'should dispatch action upon click' , ( ) => {
36
50
wrapper . find ( '.backward-button' ) . simulate ( 'click' ) ;
37
51
expect ( dispatch . mock . calls . length ) . toBe ( 1 ) ;
38
52
} ) ;
39
53
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' , ( ) => {
43
55
wrapper . find ( '.backward-button' ) . simulate ( 'click' ) ;
44
56
expect ( dispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( moveBackward ( ) ) ;
45
57
} ) ;
46
58
} ) ;
47
59
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
+ } ) ;
107
65
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
+ } ) ;
109
71
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
+ } ) ;
111
78
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
+ } ) ;
115
85
116
86
// describe('testing the playback speed', () => {
117
87
// test('if the playback dropdown states 0.5x the speed should be 0.5x', () => {
118
88
// const wrapper = shallow(<TravelContainer {...props} />);
119
-
120
89
// 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');
124
93
// expect(wrapper.find('select [selected]').val()).toEqual('key');
125
94
// });
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} />);
133
97
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
+ // });
143
105
// });
0 commit comments