@@ -23,7 +23,7 @@ describe('remove', () => {
23
23
}
24
24
}
25
25
}
26
- const result = remove ( [ 'foo' , 0 ] , state , { changeValue } )
26
+ const result = remove ( [ 'foo' , 0 ] , state , { changeValue, getIn , setIn } )
27
27
expect ( result ) . toBeUndefined ( )
28
28
expect ( changeValue ) . toHaveBeenCalled ( )
29
29
expect ( changeValue ) . toHaveBeenCalledTimes ( 1 )
@@ -42,7 +42,7 @@ describe('remove', () => {
42
42
} ,
43
43
fields : { }
44
44
}
45
- const returnValue = remove ( [ 'foo' , 1 ] , state , { changeValue } )
45
+ const returnValue = remove ( [ 'foo' , 1 ] , state , { changeValue, getIn , setIn } )
46
46
expect ( returnValue ) . toBeUndefined ( )
47
47
const op = changeValue . mock . calls [ 0 ] [ 2 ]
48
48
const result = op ( undefined )
@@ -116,7 +116,7 @@ describe('remove', () => {
116
116
}
117
117
}
118
118
}
119
- const returnValue = remove ( [ 'foo' , 1 ] , state , { changeValue } )
119
+ const returnValue = remove ( [ 'foo' , 1 ] , state , { changeValue, getIn , setIn } )
120
120
expect ( returnValue ) . toBe ( 'b' )
121
121
expect ( state . formState . values . foo ) . not . toBe ( array ) // copied
122
122
expect ( state ) . toEqual ( {
@@ -160,7 +160,6 @@ describe('remove', () => {
160
160
}
161
161
} )
162
162
} )
163
-
164
163
165
164
it ( 'should remove value from the specified index, and return it (nested arrays)' , ( ) => {
166
165
const array = [ 'a' , 'b' , 'c' , 'd' ]
@@ -228,7 +227,11 @@ describe('remove', () => {
228
227
}
229
228
}
230
229
}
231
- const returnValue = remove ( [ 'foo[0]' , 1 ] , state , { changeValue } )
230
+ const returnValue = remove ( [ 'foo[0]' , 1 ] , state , {
231
+ changeValue,
232
+ getIn,
233
+ setIn
234
+ } )
232
235
expect ( returnValue ) . toBe ( 'b' )
233
236
expect ( state . formState . values . foo ) . not . toBe ( array ) // copied
234
237
expect ( state ) . toEqual ( {
@@ -271,7 +274,7 @@ describe('remove', () => {
271
274
}
272
275
}
273
276
} )
274
- } )
277
+ } )
275
278
276
279
it ( 'should remove value from the specified index, and handle new fields' , ( ) => {
277
280
const array = [ 'a' , { key : 'val' } ]
@@ -324,11 +327,175 @@ describe('remove', () => {
324
327
}
325
328
}
326
329
}
327
- const returnValue = remove ( [ 'foo' , 0 ] , state , { renameField, changeValue } )
330
+ const returnValue = remove ( [ 'foo' , 0 ] , state , {
331
+ renameField,
332
+ changeValue,
333
+ getIn,
334
+ setIn
335
+ } )
328
336
expect ( returnValue ) . toBeUndefined ( )
329
337
expect ( renameField ) . toHaveBeenCalledTimes ( 1 )
330
338
expect ( renameField . mock . calls [ 0 ] [ 0 ] ) . toEqual ( state )
331
339
expect ( renameField . mock . calls [ 0 ] [ 1 ] ) . toEqual ( 'foo[1].key' )
332
340
expect ( renameField . mock . calls [ 0 ] [ 2 ] ) . toEqual ( 'foo[0].key' )
333
341
} )
342
+
343
+ it ( 'should remove value from the specified index with submitError if one error in array' , ( ) => {
344
+ const array = [ 'a' , { key : 'val' } ]
345
+ const changeValue = jest . fn ( )
346
+ const renameField = jest . fn ( )
347
+ function blur0 ( ) { }
348
+ function change0 ( ) { }
349
+ function focus0 ( ) { }
350
+ function blur1 ( ) { }
351
+ function change1 ( ) { }
352
+ function focus1 ( ) { }
353
+ function blur2 ( ) { }
354
+ function change2 ( ) { }
355
+ function focus2 ( ) { }
356
+ const state = {
357
+ formState : {
358
+ values : {
359
+ foo : array ,
360
+ anotherField : 42
361
+ } ,
362
+ submitErrors : {
363
+ foo : [
364
+ {
365
+ key : 'A Submit Error'
366
+ }
367
+ ]
368
+ }
369
+ } ,
370
+ fields : {
371
+ 'foo[0]' : {
372
+ name : 'foo[0]' ,
373
+ blur : blur0 ,
374
+ change : change0 ,
375
+ focus : focus0 ,
376
+ touched : true ,
377
+ error : 'A Error'
378
+ } ,
379
+ 'foo[0].key' : {
380
+ name : 'foo[0].key' ,
381
+ blur : blur2 ,
382
+ change : change2 ,
383
+ focus : focus2 ,
384
+ touched : false ,
385
+ error : 'A Error'
386
+ } ,
387
+ 'foo[1]' : {
388
+ name : 'foo[1]' ,
389
+ blur : blur1 ,
390
+ change : change1 ,
391
+ focus : focus1 ,
392
+ touched : false ,
393
+ error : 'B Error'
394
+ } ,
395
+ 'foo[1].key' : {
396
+ name : 'foo[1].key' ,
397
+ blur : blur2 ,
398
+ change : change2 ,
399
+ focus : focus2 ,
400
+ touched : false ,
401
+ error : 'B Error'
402
+ } ,
403
+ anotherField : {
404
+ name : 'anotherField' ,
405
+ touched : false
406
+ }
407
+ }
408
+ }
409
+
410
+ const returnValue = remove ( [ 'foo' , 0 ] , state , {
411
+ renameField,
412
+ changeValue,
413
+ getIn,
414
+ setIn
415
+ } )
416
+ expect ( returnValue ) . toBeUndefined ( )
417
+ expect ( getIn ( state , 'formState.submitErrors' ) ) . toEqual ( { foo : [ ] } )
418
+ } )
419
+
420
+ it ( 'should remove value from the specified index with submitError if two errors in array' , ( ) => {
421
+ const array = [ 'a' , { key : 'val' } ]
422
+ const changeValue = jest . fn ( )
423
+ const renameField = jest . fn ( )
424
+ function blur0 ( ) { }
425
+ function change0 ( ) { }
426
+ function focus0 ( ) { }
427
+ function blur1 ( ) { }
428
+ function change1 ( ) { }
429
+ function focus1 ( ) { }
430
+ function blur2 ( ) { }
431
+ function change2 ( ) { }
432
+ function focus2 ( ) { }
433
+ const state = {
434
+ formState : {
435
+ values : {
436
+ foo : array ,
437
+ anotherField : 42
438
+ } ,
439
+ submitErrors : {
440
+ foo : [
441
+ {
442
+ key : 'A Submit Error'
443
+ } ,
444
+ {
445
+ key : 'B Submit Error'
446
+ }
447
+ ]
448
+ }
449
+ } ,
450
+ fields : {
451
+ 'foo[0]' : {
452
+ name : 'foo[0]' ,
453
+ blur : blur0 ,
454
+ change : change0 ,
455
+ focus : focus0 ,
456
+ touched : true ,
457
+ error : 'A Error'
458
+ } ,
459
+ 'foo[0].key' : {
460
+ name : 'foo[0].key' ,
461
+ blur : blur2 ,
462
+ change : change2 ,
463
+ focus : focus2 ,
464
+ touched : false ,
465
+ error : 'A Error'
466
+ } ,
467
+ 'foo[1]' : {
468
+ name : 'foo[1]' ,
469
+ blur : blur1 ,
470
+ change : change1 ,
471
+ focus : focus1 ,
472
+ touched : false ,
473
+ error : 'B Error'
474
+ } ,
475
+ 'foo[1].key' : {
476
+ name : 'foo[1].key' ,
477
+ blur : blur2 ,
478
+ change : change2 ,
479
+ focus : focus2 ,
480
+ touched : false ,
481
+ error : 'B Error'
482
+ } ,
483
+ anotherField : {
484
+ name : 'anotherField' ,
485
+ touched : false
486
+ }
487
+ }
488
+ }
489
+
490
+ const returnValue = remove ( [ 'foo' , 0 ] , state , {
491
+ renameField,
492
+ changeValue,
493
+ getIn,
494
+ setIn
495
+ } )
496
+ expect ( returnValue ) . toBeUndefined ( )
497
+ expect ( getIn ( state , 'formState.submitErrors' ) ) . toEqual ( {
498
+ foo : [ { key : 'B Submit Error' } ]
499
+ } )
500
+ } )
334
501
} )
0 commit comments