@@ -3,59 +3,107 @@ import { shallow, configure } from 'enzyme';
3
3
import React from 'react' ;
4
4
import Adapter from 'enzyme-adapter-react-16' ;
5
5
import ButtonsContainer from '../containers/ButtonsContainer' ;
6
-
6
+ import { useStoreContext } from '../store' ;
7
+ import { toggleMode } from '../actions/actions' ;
7
8
8
9
configure ( { adapter : new Adapter ( ) } ) ;
9
10
10
- const props = {
11
- toggleMode : jest . fn ( ) ,
12
- importSnapshots : jest . fn ( ) ,
13
- exportSnapshots : jest . fn ( ) ,
14
- mode : {
15
- paused : false ,
16
- locked : false ,
17
- persist : false ,
11
+ const state = {
12
+ tabs : {
13
+ 87 : {
14
+ snapshots : [ 1 , 2 , 3 , 4 ] ,
15
+ sliderIndex : 0 ,
16
+ viewIndex : - 1 ,
17
+ mode : {
18
+ paused : false ,
19
+ locked : false ,
20
+ persist : false ,
21
+ } ,
22
+ } ,
18
23
} ,
24
+ currentTab : 87 ,
19
25
} ;
20
26
21
- describe ( 'testing the bottom buttons' , ( ) => {
22
- test ( 'if pause button is invoked' , ( ) => {
23
- const wrapper = shallow ( < ButtonsContainer { ...props } /> ) ;
27
+ const currentTab = state . tabs [ state . currentTab ] ;
24
28
25
- wrapper . find ( '.pause-button' ) . simulate ( 'click' ) ;
29
+ const dispatch = jest . fn ( ) ;
26
30
27
- expect ( props . toggleMode ) . toHaveBeenCalled ( ) ;
28
- } ) ;
31
+ jest . mock ( '../store' ) ;
32
+ useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
29
33
30
- test ( 'if lock button is invoked' , ( ) => {
31
- const wrapper = shallow ( < ButtonsContainer { ...props } /> ) ;
34
+ let wrapper ;
32
35
33
- wrapper . find ( '.lock-button' ) . simulate ( 'click' ) ;
34
-
35
- expect ( props . toggleMode ) . toHaveBeenCalled ( ) ;
36
+ describe ( 'testing the bottom buttons' , ( ) => {
37
+ beforeEach ( ( ) => {
38
+ wrapper = shallow ( < ButtonsContainer /> ) ;
39
+ dispatch . mockClear ( ) ;
40
+ useStoreContext . mockClear ( ) ;
41
+ currentTab . mode = {
42
+ locked : false ,
43
+ paused : false ,
44
+ persist : false ,
45
+ } ;
36
46
} ) ;
37
47
38
- test ( 'if persist button is invoked' , ( ) => {
39
- const wrapper = shallow ( < ButtonsContainer { ...props } /> ) ;
40
-
41
- wrapper . find ( '.persist-button' ) . simulate ( 'click' ) ;
42
-
43
- expect ( props . toggleMode ) . toHaveBeenCalled ( ) ;
48
+ describe ( 'pause button testing' , ( ) => {
49
+ beforeEach ( ( ) => {
50
+ wrapper . find ( '.pause-button' ) . simulate ( 'click' ) ;
51
+ } ) ;
52
+ test ( 'pause button dispatches upon click' , ( ) => {
53
+ expect ( dispatch . mock . calls . length ) . toBe ( 1 ) ;
54
+ } ) ;
55
+
56
+ test ( 'pause button dispatches toggleMode action' , ( ) => {
57
+ expect ( dispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( toggleMode ( 'paused' ) ) ;
58
+ } ) ;
59
+
60
+ test ( 'pause button displays state' , ( ) => {
61
+ expect ( wrapper . find ( '.pause-button' ) . text ( ) ) . toBe ( 'Pause' ) ;
62
+ state . tabs [ state . currentTab ] . mode . paused = true ;
63
+ wrapper = shallow ( < ButtonsContainer /> ) ;
64
+ expect ( wrapper . find ( '.pause-button' ) . text ( ) ) . toBe ( 'Resume' ) ;
65
+ } ) ;
44
66
} ) ;
45
67
46
- test ( 'if import button is invoked' , ( ) => {
47
- const wrapper = shallow ( < ButtonsContainer { ...props } /> ) ;
48
-
49
- wrapper . find ( '.import-button' ) . simulate ( 'click' ) ;
50
68
51
- expect ( props . importSnapshots ) . toHaveBeenCalled ( ) ;
69
+ describe ( 'lock button testing' , ( ) => {
70
+ beforeEach ( ( ) => {
71
+ wrapper . find ( '.lock-button' ) . simulate ( 'click' ) ;
72
+ } ) ;
73
+ test ( 'lock button dispatches upon click' , ( ) => {
74
+ expect ( dispatch . mock . calls . length ) . toBe ( 1 ) ;
75
+ } ) ;
76
+
77
+ test ( 'lock button dispatches toggleMode action' , ( ) => {
78
+ expect ( dispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( toggleMode ( 'locked' ) ) ;
79
+ } ) ;
80
+
81
+ test ( 'lock button displays state' , ( ) => {
82
+ expect ( wrapper . find ( '.lock-button' ) . text ( ) ) . toBe ( 'Lock' ) ;
83
+ state . tabs [ state . currentTab ] . mode . locked = true ;
84
+ wrapper = shallow ( < ButtonsContainer /> ) ;
85
+ expect ( wrapper . find ( '.lock-button' ) . text ( ) ) . toBe ( 'Unlock' ) ;
86
+ } ) ;
52
87
} ) ;
53
88
54
- test ( 'if export button is invoked' , ( ) => {
55
- const wrapper = shallow ( < ButtonsContainer { ...props } /> ) ;
56
-
57
- wrapper . find ( '.export-button' ) . simulate ( 'click' ) ;
58
-
59
- expect ( props . exportSnapshots ) . toHaveBeenCalled ( ) ;
89
+ describe ( 'persist button testing' , ( ) => {
90
+ beforeEach ( ( ) => {
91
+ wrapper . find ( '.persist-button' ) . simulate ( 'click' ) ;
92
+ } ) ;
93
+
94
+ test ( 'persist button dispatches upon click' , ( ) => {
95
+ expect ( dispatch . mock . calls . length ) . toBe ( 1 ) ;
96
+ } ) ;
97
+
98
+ test ( 'persist button dispatches toggleMode action' , ( ) => {
99
+ expect ( dispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( toggleMode ( 'persist' ) ) ;
100
+ } ) ;
101
+
102
+ test ( 'persist button displays state' , ( ) => {
103
+ expect ( wrapper . find ( '.persist-button' ) . text ( ) ) . toBe ( 'Persist' ) ;
104
+ state . tabs [ state . currentTab ] . mode . persist = true ;
105
+ wrapper = shallow ( < ButtonsContainer /> ) ;
106
+ expect ( wrapper . find ( '.persist-button' ) . text ( ) ) . toBe ( 'Unpersist' ) ;
107
+ } ) ;
60
108
} ) ;
61
109
} ) ;
0 commit comments