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