@@ -4,10 +4,13 @@ import {
4
4
AddTopic ,
5
5
AddTopicFailed ,
6
6
AddTopicSuccess ,
7
+ DeleteTaskFailed ,
8
+ DeleteTaskSuccess ,
7
9
GetMatrixData ,
8
10
GetMatrixDataFailed ,
9
11
GetMatrixDataSuccess ,
10
12
MatrixAction ,
13
+ SelectTask ,
11
14
ToggleTopicVisibility ,
12
15
UpdateTask ,
13
16
UpdateTaskFailed ,
@@ -126,7 +129,7 @@ describe('MatrixReducers', () => {
126
129
beforeEach ( ( ) => {
127
130
defaultState = {
128
131
topics : [ new Topic ( 1 , 'test' , Color . orange , true , false ) ] ,
129
- tasks : [ ] ,
132
+ tasks : [ new Task ( 1 , 'Test' , 1 , 1 , 1 , 1 , 21 ) ] ,
130
133
taskHistory : [ ] ,
131
134
isLoading : true ,
132
135
errorMessage : 'test message' ,
@@ -169,6 +172,29 @@ describe('MatrixReducers', () => {
169
172
expect ( newState . isLoading ) . toEqual ( false ) ;
170
173
expect ( newState . errorMessage ) . toBeUndefined ( ) ;
171
174
} ) ;
175
+
176
+ it ( 'should set unloading on DELETE_TASK_SUCCESS' , ( ) => {
177
+ const action : MatrixAction = new DeleteTaskSuccess (
178
+ new Task (
179
+ 1 ,
180
+ 'Test' ,
181
+ 1 ,
182
+ 1 ,
183
+ 1 ,
184
+ 1 ,
185
+ 21 ,
186
+ '' ,
187
+ false ,
188
+ true ,
189
+ new Date ( ) ,
190
+ new Date ( ) ,
191
+ new Date ( ) ,
192
+ ) ,
193
+ ) ;
194
+ const newState = matrixReducer ( defaultState , action ) ;
195
+ expect ( newState . isLoading ) . toEqual ( false ) ;
196
+ expect ( newState . errorMessage ) . toBeUndefined ( ) ;
197
+ } ) ;
172
198
} ) ;
173
199
174
200
describe ( 'success states' , ( ) => {
@@ -203,12 +229,37 @@ describe('MatrixReducers', () => {
203
229
it ( 'should update task on UPDATE_TASK_SUCCESS' , ( ) => {
204
230
defaultState = {
205
231
...defaultState ,
206
- tasks : [ new Task ( 1 , 'test' , 1 , 1 , 1 , 12 , 2020 ) ] ,
232
+ tasks : [ new Task ( 1 , 'test' , 1 , 1 , 1 , 12 , 20 ) ] ,
207
233
} ;
208
- const updatedTask = new Task ( 1 , 'test' , 7 , 1 , 1 , 12 , 2020 ) ;
234
+ const updatedTask = new Task ( 1 , 'test' , 7 , 1 , 1 , 12 , 20 ) ;
209
235
const action : MatrixAction = new UpdateTaskSuccess ( updatedTask ) ;
210
236
const newState = matrixReducer ( defaultState , action ) ;
211
- expect ( newState . tasks [ 1 ] ) . toContain ( updatedTask ) ;
237
+ expect ( newState . tasks ) . toContain ( updatedTask ) ;
238
+ } ) ;
239
+
240
+ it ( 'should delete task on DELETE_TASK_SUCCESS' , ( ) => {
241
+ defaultState = {
242
+ ...defaultState ,
243
+ tasks : [ new Task ( 1 , 'test' , 1 , 1 , 1 , 1 , 21 ) ] ,
244
+ } ;
245
+ const updatedTask = new Task (
246
+ 1 ,
247
+ 'test' ,
248
+ 1 ,
249
+ 1 ,
250
+ 1 ,
251
+ 1 ,
252
+ 21 ,
253
+ '' ,
254
+ false ,
255
+ true ,
256
+ undefined ,
257
+ undefined ,
258
+ new Date ( ) ,
259
+ ) ;
260
+ const action : MatrixAction = new DeleteTaskSuccess ( updatedTask ) ;
261
+ const newState = matrixReducer ( defaultState , action ) ;
262
+ expect ( newState . tasks [ 0 ] ) . toEqual ( updatedTask ) ;
212
263
} ) ;
213
264
214
265
it ( 'should add topic on ADD_TOPIC_SUCCESS' , ( ) => {
@@ -243,9 +294,14 @@ describe('MatrixReducers', () => {
243
294
} ) ;
244
295
245
296
it ( 'should toggle visibility on TOGGLE_TOPIC_VISIBILITY' , ( ) => {
246
- const action : MatrixAction = new ToggleTopicVisibility ( 1 ) ;
247
- const newState = matrixReducer ( defaultState , action ) ;
248
- expect ( newState . topics [ 0 ] . visible ) . toEqual ( false ) ;
297
+ const action1 : MatrixAction = new ToggleTopicVisibility ( 1 ) ;
298
+ const action2 : MatrixAction = new ToggleTopicVisibility ( 2 ) ;
299
+ const newState1 = matrixReducer ( defaultState , action1 ) ;
300
+ expect ( newState1 . topics [ 0 ] . visible ) . toEqual ( false ) ;
301
+ expect ( newState1 . topics [ 1 ] . visible ) . toEqual ( false ) ;
302
+ const newState2 = matrixReducer ( newState1 , action2 ) ;
303
+ expect ( newState2 . topics [ 0 ] . visible ) . toEqual ( false ) ;
304
+ expect ( newState2 . topics [ 1 ] . visible ) . toEqual ( true ) ;
249
305
} ) ;
250
306
251
307
it ( 'should not change if topic not found on TOGGLE_TOPIC_VISIBILITY' , ( ) => {
@@ -254,4 +310,74 @@ describe('MatrixReducers', () => {
254
310
expect ( newState ) . toEqual ( defaultState ) ;
255
311
} ) ;
256
312
} ) ;
313
+
314
+ describe ( 'select task' , ( ) => {
315
+ let defaultState : MatrixState ;
316
+
317
+ beforeEach ( ( ) => {
318
+ defaultState = {
319
+ topics : [ ] ,
320
+ tasks : [
321
+ new Task ( 1 , 'test' , 1 , 1 , 1 , 1 , 21 ) ,
322
+ new Task ( 2 , 'test' , 1 , 1 , 1 , 1 , 21 ) ,
323
+ new Task ( 3 , 'test' , 1 , 1 , 1 , 1 , 21 ) ,
324
+ new Task ( 4 , 'test' , 1 , 1 , 1 , 1 , 21 ) ,
325
+ new Task ( 5 , 'test' , 1 , 1 , 1 , 1 , 21 ) ,
326
+ new Task ( 6 , 'test' , 1 , 1 , 1 , 1 , 21 ) ,
327
+ new Task ( 7 , 'test' , 1 , 1 , 1 , 1 , 21 ) ,
328
+ ] ,
329
+ taskHistory : [ ] ,
330
+ isLoading : false ,
331
+ errorMessage : undefined ,
332
+ } ;
333
+ } ) ;
334
+
335
+ it ( 'should select tasks in correct order on SELECT_TASK' , ( ) => {
336
+ const action1 : MatrixAction = new SelectTask ( 1 ) ;
337
+ const action2 : MatrixAction = new SelectTask ( 2 ) ;
338
+ const action3 : MatrixAction = new SelectTask ( 3 ) ;
339
+ const action4 : MatrixAction = new SelectTask ( 4 ) ;
340
+ let newState = matrixReducer ( defaultState , action1 ) ;
341
+ newState = matrixReducer ( newState , action2 ) ;
342
+ newState = matrixReducer ( newState , action3 ) ;
343
+ newState = matrixReducer ( newState , action4 ) ;
344
+ newState = matrixReducer ( newState , action4 ) ;
345
+ expect ( newState . taskHistory ) . toEqual ( [ 4 , 3 , 2 , 1 ] ) ;
346
+ } ) ;
347
+
348
+ it ( 'should only select task once on SELECT_TASK' , ( ) => {
349
+ const action : MatrixAction = new SelectTask ( 1 ) ;
350
+ let newState = matrixReducer ( defaultState , action ) ;
351
+ newState = matrixReducer ( newState , action ) ;
352
+ expect ( newState . taskHistory ) . toEqual ( [ 1 ] ) ;
353
+ } ) ;
354
+
355
+ it ( 'should only change taskHistory on SELECT_TASK' , ( ) => {
356
+ const action : MatrixAction = new SelectTask ( 1 ) ;
357
+ const newState = matrixReducer ( defaultState , action ) ;
358
+ expect ( newState ) . toEqual ( { ...defaultState , taskHistory : [ 1 ] } ) ;
359
+ } ) ;
360
+
361
+ it ( 'should correctly order tasks in history on SELECT_TASK' , ( ) => {
362
+ const action1 : MatrixAction = new SelectTask ( 1 ) ;
363
+ const action7 : MatrixAction = new SelectTask ( 7 ) ;
364
+ const action5 : MatrixAction = new SelectTask ( 5 ) ;
365
+ const action3 : MatrixAction = new SelectTask ( 3 ) ;
366
+ let newState = matrixReducer ( defaultState , action1 ) ;
367
+ newState = matrixReducer ( newState , action7 ) ;
368
+ newState = matrixReducer ( newState , action5 ) ;
369
+ newState = matrixReducer ( newState , action3 ) ;
370
+ newState = matrixReducer ( newState , action3 ) ;
371
+ newState = matrixReducer ( newState , action1 ) ;
372
+ expect ( newState . taskHistory ) . toEqual ( [ 1 , 3 , 5 , 7 ] ) ;
373
+ } ) ;
374
+
375
+ it ( 'should only take 6 elements in history on SELECT_TASK' , ( ) => {
376
+ let newState = matrixReducer ( defaultState , new SelectTask ( 1 ) ) ;
377
+ for ( let i = 2 ; i < 8 ; i ++ ) {
378
+ newState = matrixReducer ( newState , new SelectTask ( i ) ) ;
379
+ }
380
+ expect ( newState . taskHistory . length ) . toEqual ( 6 ) ;
381
+ } ) ;
382
+ } ) ;
257
383
} ) ;
0 commit comments