@@ -4,6 +4,7 @@ import { getIn, setIn } from 'final-form'
44describe ( 'insert' , ( ) => {
55 const getOp = ( index , value ) => {
66 const changeValue = jest . fn ( )
7+ const resetFieldState = jest . fn ( )
78 const state = {
89 formState : {
910 values : {
@@ -23,12 +24,13 @@ describe('insert', () => {
2324 }
2425 }
2526 }
26- insert ( [ 'foo' , index , value ] , state , { changeValue } )
27+ insert ( [ 'foo' , index , value ] , state , { changeValue, resetFieldState } )
2728 return changeValue . mock . calls [ 0 ] [ 2 ]
2829 }
2930
3031 it ( 'should call changeValue once' , ( ) => {
3132 const changeValue = jest . fn ( )
33+ const resetFieldState = jest . fn ( )
3234 const state = {
3335 formState : {
3436 values : {
@@ -52,7 +54,10 @@ describe('insert', () => {
5254 }
5355 }
5456 }
55- const result = insert ( [ 'foo' , 0 , 'bar' ] , state , { changeValue } )
57+ const result = insert ( [ 'foo' , 0 , 'bar' ] , state , {
58+ changeValue,
59+ resetFieldState
60+ } )
5661 expect ( result ) . toBeUndefined ( )
5762 expect ( changeValue ) . toHaveBeenCalled ( )
5863 expect ( changeValue ) . toHaveBeenCalledTimes ( 1 )
@@ -86,6 +91,9 @@ describe('insert', () => {
8691 const after = mutate ( before )
8792 state . formState . values = setIn ( state . formState . values , name , after ) || { }
8893 }
94+ const resetFieldState = name => {
95+ state . fields [ name ] . touched = false
96+ }
8997 const state = {
9098 formState : {
9199 values : {
@@ -100,7 +108,7 @@ describe('insert', () => {
100108 } ,
101109 'foo[1]' : {
102110 name : 'foo[1]' ,
103- touched : false ,
111+ touched : true ,
104112 error : 'B Error'
105113 } ,
106114 'foo[2]' : {
@@ -115,7 +123,10 @@ describe('insert', () => {
115123 }
116124 }
117125 }
118- const returnValue = insert ( [ 'foo' , 1 , 'NEWVALUE' ] , state , { changeValue } )
126+ const returnValue = insert ( [ 'foo' , 1 , 'NEWVALUE' ] , state , {
127+ changeValue,
128+ resetFieldState
129+ } )
119130 expect ( returnValue ) . toBeUndefined ( )
120131 expect ( state . formState . values . foo ) . not . toBe ( array ) // copied
121132 expect ( state ) . toEqual ( {
@@ -130,23 +141,29 @@ describe('insert', () => {
130141 touched : true ,
131142 error : 'A Error'
132143 } ,
144+ 'foo[1]' : {
145+ name : 'foo[1]' ,
146+ touched : false ,
147+ error : 'B Error' ,
148+ lastFieldState : undefined
149+ } ,
133150 'foo[2]' : {
134151 name : 'foo[2]' ,
135- touched : false ,
152+ touched : true ,
136153 error : 'B Error' ,
137- forceUpdate : true
154+ lastFieldState : undefined
138155 } ,
139156 'foo[3]' : {
140157 name : 'foo[3]' ,
141158 touched : true ,
142159 error : 'C Error' ,
143- forceUpdate : true
160+ lastFieldState : undefined
144161 } ,
145162 'foo[4]' : {
146163 name : 'foo[4]' ,
147164 touched : false ,
148165 error : 'D Error' ,
149- forceUpdate : true
166+ lastFieldState : undefined
150167 }
151168 }
152169 } )
0 commit comments