@@ -500,6 +500,121 @@ describe('move', () => {
500
500
}
501
501
} )
502
502
} )
503
+ it ( 'should move fields with different complex not matching shapes' , ( ) => {
504
+ // implementation of changeValue taken directly from Final Form
505
+ const changeValue = ( state , name , mutate ) => {
506
+ const before = getIn ( state . formState . values , name )
507
+ const after = mutate ( before )
508
+ state . formState . values = setIn ( state . formState . values , name , after ) || { }
509
+ }
510
+ const state = {
511
+ formState : {
512
+ values : {
513
+ foo : [ { dog : 'apple dog' , cat : 'apple cat' , colors : [ { name : 'red' } , { name : 'blue' } ] , deep : { inside : { rock : 'black' } } } ,
514
+ { dog : 'banana dog' , mouse : 'mickey' , deep : { inside : { axe : 'golden' } } } ]
515
+ }
516
+ } ,
517
+ fields : {
518
+ 'foo[0].dog' : {
519
+ name : 'foo[0].dog' ,
520
+ touched : true ,
521
+ error : 'Error A Dog'
522
+ } ,
523
+ 'foo[0].cat' : {
524
+ name : 'foo[0].cat' ,
525
+ touched : false ,
526
+ error : 'Error A Cat'
527
+ } ,
528
+ 'foo[0].colors[0].name' : {
529
+ name : 'foo[0].colors[0].name' ,
530
+ touched : true ,
531
+ error : 'Error A Colors Red'
532
+ } ,
533
+ 'foo[0].colors[1].name' : {
534
+ name : 'foo[0].colors[1].name' ,
535
+ touched : true ,
536
+ error : 'Error A Colors Blue'
537
+ } ,
538
+ 'foo[0].deep.inside.rock' : {
539
+ name : 'foo[0].deep.inside.rock' ,
540
+ touched : true ,
541
+ error : 'Error A Deep Inside Rock Black'
542
+ } ,
543
+ 'foo[1].dog' : {
544
+ name : 'foo[1].dog' ,
545
+ touched : true ,
546
+ error : 'Error B Dog'
547
+ } ,
548
+ 'foo[1].mouse' : {
549
+ name : 'foo[1].mouse' ,
550
+ touched : true ,
551
+ error : 'Error B Mickey'
552
+ } ,
553
+ 'foo[1].deep.inside.axe' : {
554
+ name : 'foo[1].deep.inside.axe' ,
555
+ touched : true ,
556
+ error : 'Error B Deep Inside Axe Golden'
557
+ } ,
558
+ }
559
+ }
560
+ move ( [ 'foo' , 0 , 1 ] , state , { changeValue } )
561
+ expect ( state ) . toMatchObject ( {
562
+ formState : {
563
+ values : {
564
+ foo : [ { dog : 'banana dog' , mouse : 'mickey' , deep : { inside : { axe : 'golden' } } } ,
565
+ { dog : 'apple dog' , cat : 'apple cat' , colors : [ { name : 'red' } , { name : 'blue' } ] , deep : { inside : { rock : 'black' } } } ]
566
+ }
567
+ } ,
568
+ fields : {
569
+ 'foo[0].dog' : {
570
+ name : 'foo[0].dog' ,
571
+ touched : true ,
572
+ error : 'Error B Dog' ,
573
+ lastFieldState : undefined
574
+ } ,
575
+ 'foo[0].mouse' : {
576
+ name : 'foo[0].mouse' ,
577
+ touched : true ,
578
+ error : 'Error B Mickey' ,
579
+ lastFieldState : undefined
580
+ } ,
581
+ 'foo[0].deep.inside.axe' : {
582
+ name : 'foo[0].deep.inside.axe' ,
583
+ touched : true ,
584
+ error : 'Error B Deep Inside Axe Golden'
585
+ } ,
586
+ 'foo[1].dog' : {
587
+ name : 'foo[1].dog' ,
588
+ touched : true ,
589
+ error : 'Error A Dog' ,
590
+ lastFieldState : undefined
591
+ } ,
592
+ 'foo[1].cat' : {
593
+ name : 'foo[1].cat' ,
594
+ touched : false ,
595
+ error : 'Error A Cat' ,
596
+ lastFieldState : undefined
597
+ } ,
598
+ 'foo[1].colors[0].name' : {
599
+ name : 'foo[1].colors[0].name' ,
600
+ touched : true ,
601
+ error : 'Error A Colors Red' ,
602
+ lastFieldState : undefined
603
+ } ,
604
+ 'foo[1].colors[1].name' : {
605
+ name : 'foo[1].colors[1].name' ,
606
+ touched : true ,
607
+ error : 'Error A Colors Blue' ,
608
+ lastFieldState : undefined
609
+ } ,
610
+ 'foo[1].deep.inside.rock' : {
611
+ name : 'foo[1].deep.inside.rock' ,
612
+ touched : true ,
613
+ error : 'Error A Deep Inside Rock Black'
614
+ } ,
615
+ }
616
+ } )
617
+ } )
503
618
504
619
it ( 'should preserve functions in field state' , ( ) => {
505
620
// implementation of changeValue taken directly from Final Form
0 commit comments