@@ -52,13 +52,27 @@ describe('mainReducer testing', () => {
52
52
expect ( mainReducer ( state , moveBackward ( ) ) . tabs [ currentTab ] . sliderIndex ) . toEqual ( 1 ) ;
53
53
expect ( mainReducer ( state , moveBackward ( ) ) . tabs [ currentTab ] . playing ) . toEqual ( false ) ;
54
54
} ) ;
55
+ it ( 'should not decrement if sliderIndex is zero' , ( ) => {
56
+ state . tabs [ currentTab ] . sliderIndex = 0 ;
57
+ const { sliderIndex } = mainReducer ( state , moveBackward ( ) ) . tabs [ currentTab ] ;
58
+ expect ( sliderIndex ) . toBe ( 0 ) ;
59
+ } ) ;
55
60
} ) ;
56
61
57
62
describe ( 'moveForward' , ( ) => {
58
63
it ( 'should increment sliderIndex by 1' , ( ) => {
59
64
expect ( mainReducer ( state , moveForward ( ) ) . tabs [ currentTab ] . sliderIndex ) . toEqual ( 3 ) ;
60
65
expect ( mainReducer ( state , moveForward ( ) ) . tabs [ currentTab ] . playing ) . toEqual ( false ) ;
61
66
} ) ;
67
+ it ( 'should not increment if sliderIndex at end' , ( ) => {
68
+ state . tabs [ currentTab ] . sliderIndex = 3 ;
69
+ const { sliderIndex } = mainReducer ( state , moveForward ( ) ) . tabs [ currentTab ] ;
70
+ expect ( sliderIndex ) . toBe ( 3 ) ;
71
+ } ) ;
72
+ it ( 'should not change playing if not coming from user' , ( ) => {
73
+ const { playing } = mainReducer ( state , playForward ( ) ) . tabs [ currentTab ] ;
74
+ expect ( playing ) . toBe ( true ) ;
75
+ } ) ;
62
76
} ) ;
63
77
64
78
describe ( 'changeView' , ( ) => {
@@ -118,6 +132,12 @@ describe('mainReducer testing', () => {
118
132
expect ( mode . locked ) . toBe ( false ) ;
119
133
expect ( mode . persist ) . toBe ( true ) ;
120
134
} ) ;
135
+ it ( 'undefined payload does nothing' , ( ) => {
136
+ const { mode } = mainReducer ( state , toggleMode ( 'undefined' ) ) . tabs [ currentTab ] ;
137
+ expect ( mode . paused ) . toBe ( false ) ;
138
+ expect ( mode . locked ) . toBe ( false ) ;
139
+ expect ( mode . persist ) . toBe ( false ) ;
140
+ } ) ;
121
141
} ) ;
122
142
123
143
describe ( 'slider pause' , ( ) => {
@@ -153,7 +173,7 @@ describe('mainReducer testing', () => {
153
173
} ;
154
174
it ( 'should add new tab' , ( ) => {
155
175
const addedTab = mainReducer ( state , initialConnect ( newTab ) ) . tabs [ 104 ] ;
156
- expect ( addedTab ) . not . toBe ( undefined ) ;
176
+ expect ( addedTab ) . not . toBe ( undefined ) ;
157
177
} ) ;
158
178
it ( 'should force some values to default' , ( ) => {
159
179
const addedTab = mainReducer ( state , initialConnect ( newTab ) ) . tabs [ 104 ] ;
@@ -166,9 +186,75 @@ describe('mainReducer testing', () => {
166
186
const addedTab = mainReducer ( state , initialConnect ( newTab ) ) . tabs [ 104 ] ;
167
187
expect ( addedTab . snapshots ) . toEqual ( newTab [ 104 ] . snapshots ) ;
168
188
} ) ;
189
+ it ( 'if currentTab undefined currentTab becomes firstTab' , ( ) => {
190
+ state . currentTab = undefined ;
191
+ const addedTab = mainReducer ( state , initialConnect ( newTab ) ) ;
192
+ expect ( addedTab . currentTab ) . toBe ( 104 ) ;
193
+ } ) ;
169
194
} ) ;
170
195
171
196
describe ( 'new snapshots' , ( ) => {
197
+ const newSnapshots = {
198
+ 87 : {
199
+ snapshots : [ 1 , 2 , 3 , 4 , 5 ] ,
200
+ sliderIndex : 2 ,
201
+ viewIndex : - 1 ,
202
+ mode : {
203
+ paused : false ,
204
+ locked : false ,
205
+ persist : false ,
206
+ } ,
207
+ intervalId : 87 ,
208
+ playing : true ,
209
+ } ,
210
+ } ;
211
+ it ( 'update snapshots of corresponding tabId' , ( ) => {
212
+ const updated = mainReducer ( state , addNewSnapshots ( newSnapshots ) ) ;
213
+ expect ( updated . tabs [ 87 ] . snapshots ) . toEqual ( newSnapshots [ 87 ] . snapshots ) ;
214
+ } ) ;
215
+ it ( 'should delete tabs that are deleted from background script' , ( ) => {
216
+ const updated = mainReducer ( state , addNewSnapshots ( newSnapshots ) ) ;
217
+ expect ( updated . tabs [ 75 ] ) . toBe ( undefined ) ;
218
+ } ) ;
219
+ it ( 'if currentTab undefined currentTab becomes first Tab' , ( ) => {
220
+ state . currentTab = undefined ;
221
+ const updated = mainReducer ( state , addNewSnapshots ( newSnapshots ) ) ;
222
+ expect ( updated . currentTab ) . toBe ( 87 ) ;
223
+ } ) ;
224
+ } ) ;
172
225
226
+ describe ( 'set_tab' , ( ) => {
227
+ it ( 'should set tab to payload' , ( ) => {
228
+ const newCurrentTab = mainReducer ( state , setTab ( 75 ) ) . currentTab ;
229
+ expect ( newCurrentTab ) . toBe ( 75 ) ;
230
+ } ) ;
231
+ } ) ;
232
+
233
+ describe ( 'delete_tab' , ( ) => {
234
+ it ( 'should delete only payload tab from state' , ( ) => {
235
+ const afterDelete = mainReducer ( state , deleteTab ( 75 ) ) ;
236
+ expect ( afterDelete . tabs [ 75 ] ) . toBe ( undefined ) ;
237
+ expect ( afterDelete . tabs [ 87 ] ) . not . toBe ( undefined ) ;
238
+ } ) ;
239
+ it ( 'should change current tab if deleted tab matches current tab' , ( ) => {
240
+ const afterDelete = mainReducer ( state , deleteTab ( 87 ) ) ;
241
+ expect ( afterDelete . tabs [ 87 ] ) . toBe ( undefined ) ;
242
+ expect ( afterDelete . tabs [ 75 ] ) . not . toBe ( undefined ) ;
243
+ expect ( afterDelete . currentTab ) . toBe ( 75 ) ;
244
+ } ) ;
245
+ } ) ;
246
+
247
+ describe ( 'default' , ( ) => {
248
+ const action = {
249
+ type : 'doesNotExist' ,
250
+ payload : 'trigger' ,
251
+ } ;
252
+ it ( 'if there are no match of action types, throw error' , ( ) => {
253
+ try {
254
+ mainReducer ( state , action ) ;
255
+ } catch ( err ) {
256
+ expect ( err ) . toBeInstanceOf ( Error ) ;
257
+ }
258
+ } ) ;
173
259
} ) ;
174
260
} ) ;
0 commit comments