@@ -3,24 +3,53 @@ 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 MainContainer from '../containers/MainContainer';
7
- // import Dropdown from '../components/Dropdown';
8
-
6
+ import { useStoreContext } from '../store' ;
7
+ import { moveBackward , moveForward } from '../actions/actions' ;
9
8
10
9
configure ( { adapter : new Adapter ( ) } ) ;
11
10
12
- const props = {
13
- moveBackward : jest . fn ( ) ,
14
- moveForward : jest . fn ( ) ,
15
- snapshotsLength : 5 ,
16
- handleChangeSnapshot : jest . fn ( ) ,
17
- handleJumpSnapshot : jest . fn ( ) ,
18
- snapshotIndex : 6 ,
19
- play : jest . fn ( ) ,
20
- playing : false ,
21
- pause : jest . fn ( ) ,
11
+ const state = {
12
+ tabs : {
13
+ 87 : {
14
+ snapshots : [ 1 , 2 , 3 , 4 ] ,
15
+ sliderIndex : 2 ,
16
+ playing : true ,
17
+ } ,
18
+ } ,
19
+ currentTab : 87 ,
22
20
} ;
23
21
22
+ const dispatch = jest . fn ( ) ;
23
+ jest . mock ( '../store' ) ;
24
+ useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
25
+
26
+ let wrapper ;
27
+
28
+ beforeEach ( ( ) => {
29
+ wrapper = shallow ( < TravelContainer snapshotsLength = { 2 } /> ) ;
30
+ useStoreContext . mockClear ( ) ;
31
+ dispatch . mockClear ( ) ;
32
+ } ) ;
33
+
34
+ describe ( 'testing the backward-button' , ( ) => {
35
+ test ( 'backward-button should dispatch action upon click' , ( ) => {
36
+ wrapper . find ( '.backward-button' ) . simulate ( 'click' ) ;
37
+ expect ( dispatch . mock . calls . length ) . toBe ( 1 ) ;
38
+ } ) ;
39
+
40
+ // backward-button invokes dispatch(moveBackward())
41
+ // moveBackward is an actionCreator
42
+ test ( 'backward-button should send moveBackward action to dispatch' , ( ) => {
43
+ wrapper . find ( '.backward-button' ) . simulate ( 'click' ) ;
44
+ expect ( dispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( moveBackward ( ) ) ;
45
+ } ) ;
46
+ } ) ;
47
+
48
+ // test('testing the forward-button', () => {
49
+ // wrapper.find('.forward-button').simulate('click');
50
+ // expect(dispatch.mock.calls.length).toBe(1);
51
+ // });
52
+
24
53
// These are fake props to be used during dropdown tests
25
54
26
55
// const dropdownProps = {
@@ -38,77 +67,77 @@ const props = {
38
67
// { value: 500, label: '2.0x' },
39
68
// ];
40
69
41
- describe ( 'testing the backward and forward buttons' , ( ) => {
42
- test ( 'if the backward button rewinds the playback' , ( ) => {
43
- const wrapper = shallow ( < TravelContainer { ...props } /> ) ;
70
+ // describe('testing the backward and forward buttons', () => {
71
+ // test('if the backward button rewinds the playback', () => {
72
+ // const wrapper = shallow(<TravelContainer {...props} />);
44
73
45
- wrapper . find ( '.backward-button' ) . simulate ( 'click' ) ;
74
+ // wrapper.find('.backward-button').simulate('click');
46
75
47
- expect ( props . moveBackward ) . toHaveBeenCalled ( ) ;
48
- } ) ;
76
+ // expect(props.moveBackward).toHaveBeenCalled();
77
+ // });
49
78
50
- test ( 'if the forward button forwards the playback' , ( ) => {
51
- const wrapper = shallow ( < TravelContainer { ...props } /> ) ;
79
+ // test('if the forward button forwards the playback', () => {
80
+ // const wrapper = shallow(<TravelContainer {...props} />);
52
81
53
- wrapper . find ( '.forward-button' ) . simulate ( 'click' ) ;
82
+ // wrapper.find('.forward-button').simulate('click');
54
83
55
- expect ( props . moveForward ) . toHaveBeenCalled ( ) ;
56
- } ) ;
57
- } ) ;
84
+ // expect(props.moveForward).toHaveBeenCalled();
85
+ // });
86
+ // });
58
87
59
- describe ( 'testing the play button' , ( ) => {
60
- test ( 'if the play button starts the playback' , ( ) => {
61
- const wrapper = shallow ( < TravelContainer { ...props } /> ) ;
88
+ // describe('testing the play button', () => {
89
+ // test('if the play button starts the playback', () => {
90
+ // const wrapper = shallow(<TravelContainer {...props} />);
62
91
63
- wrapper . find ( '.play-button' ) . simulate ( 'click' ) ;
92
+ // wrapper.find('.play-button').simulate('click');
64
93
65
- expect ( props . play ) . toHaveBeenCalled ( ) ;
66
- } ) ;
94
+ // expect(props.play).toHaveBeenCalled();
95
+ // });
67
96
68
- test ( "if playback is not running, the button should state 'Play'" , ( ) => {
69
- const wrapper = shallow ( < TravelContainer { ...props } /> ) ;
97
+ // test("if playback is not running, the button should state 'Play'", () => {
98
+ // const wrapper = shallow(<TravelContainer {...props} />);
70
99
71
- wrapper . find ( '.play-button' ) ;
100
+ // wrapper.find('.play-button');
72
101
73
- expect ( wrapper . find ( '.play-button' ) . text ( ) ) . toBe ( 'Play' ) ;
74
- } ) ;
102
+ // expect(wrapper.find('.play-button').text()).toBe('Play');
103
+ // });
75
104
76
- test ( "if playback is running, the button should state 'Pause'" , ( ) => {
77
- props . playing = true ;
105
+ // test("if playback is running, the button should state 'Pause'", () => {
106
+ // props.playing = true;
78
107
79
- const wrapper = shallow ( < TravelContainer { ...props } /> ) ;
108
+ // const wrapper = shallow(<TravelContainer {...props} />);
80
109
81
- wrapper . find ( '.play-button' ) ;
110
+ // wrapper.find('.play-button');
82
111
83
- expect ( wrapper . find ( '.play-button' ) . text ( ) ) . toBe ( 'Pause' ) ;
84
- } ) ;
85
- } ) ;
112
+ // expect(wrapper.find('.play-button').text()).toBe('Pause');
113
+ // });
114
+ // });
86
115
87
- describe ( 'testing the playback speed' , ( ) => {
88
- test ( 'if the playback dropdown states 0.5x the speed should be 0.5x' , ( ) => {
89
- const wrapper = shallow ( < TravelContainer { ...props } /> ) ;
116
+ // describe('testing the playback speed', () => {
117
+ // test('if the playback dropdown states 0.5x the speed should be 0.5x', () => {
118
+ // const wrapper = shallow(<TravelContainer {...props} />);
90
119
91
- wrapper . find ( 'Dropdown' ) . simulate ( 'change' , { value : [ 'val' ] } ) ;
92
- // wrapper.find('select').simulate('change', { value : 'hello'});
93
- // console.log('val',wrapper.find('Dropdown').simulate('select', { value: ['val'] }));
94
- // expect(wrapper.find('Dropdown').text()).toBe('0.5x')
95
- expect ( wrapper . find ( 'select [selected]' ) . val ( ) ) . toEqual ( 'key' ) ;
96
- } ) ;
97
- // test('if the playback dropdown states 1x the speed should be 1x', () => {
120
+ // 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')
124
+ // expect(wrapper.find('select [selected]').val()).toEqual('key');
125
+ // });
126
+ // // test('if the playback dropdown states 1x the speed should be 1x', () => {
98
127
99
- // const wrapper = shallow(<TravelContainer { ...dropdownProps } />);
128
+ // // const wrapper = shallow(<TravelContainer { ...dropdownProps } />);
100
129
101
- // expect(wrapper.find('Dropdown').label).toBe('1.0x')
130
+ // // expect(wrapper.find('Dropdown').label).toBe('1.0x')
102
131
103
- // });
132
+ // // });
104
133
105
- // test('if the playback dropdown states 2x the speed should be 2x', () => {
134
+ // // test('if the playback dropdown states 2x the speed should be 2x', () => {
106
135
107
- // const wrapper = shallow(<TravelContainer { ...dropdownProps } />);
136
+ // // const wrapper = shallow(<TravelContainer { ...dropdownProps } />);
108
137
109
- // wrapper.find('Dropdown').simulate('click');
138
+ // // wrapper.find('Dropdown').simulate('click');
110
139
111
- // expect(wrapper.find('Dropdown').label).toBe('2.0x')
140
+ // // expect(wrapper.find('Dropdown').label).toBe('2.0x')
112
141
113
- // });
114
- } ) ;
142
+ // // });
143
+ // });
0 commit comments