@@ -37,7 +37,7 @@ describe('Form.Preserve', () => {
3737
3838 await matchTest ( false , { keep : 233 , remove : 666 } ) ;
3939 await matchTest ( true , { keep : 233 } ) ;
40- await matchTest ( false , { keep : 233 } ) ;
40+ await matchTest ( false , { keep : 233 , remove : 666 } ) ;
4141 } ) ;
4242
4343 it ( 'form' , async ( ) => {
@@ -54,7 +54,49 @@ describe('Form.Preserve', () => {
5454
5555 await matchTest ( false , { keep : 233 , remove : 666 } ) ;
5656 await matchTest ( true , { keep : 233 } ) ;
57- await matchTest ( false , { keep : 233 } ) ;
57+ await matchTest ( false , { keep : 233 , remove : 666 } ) ;
58+ } ) ;
59+
60+ it ( 'keep preserve when other field exist the name' , async ( ) => {
61+ const formRef = React . createRef < FormInstance > ( ) ;
62+
63+ const KeepDemo = ( { onFinish, keep } : { onFinish : ( values : any ) => void ; keep : boolean } ) => {
64+ return (
65+ < Form ref = { formRef } initialValues = { { test : 'bamboo' } } onFinish = { onFinish } >
66+ < Form . Field shouldUpdate >
67+ { ( ) => {
68+ return (
69+ < >
70+ { keep && < InfoField name = "test" preserve = { false } /> }
71+ < InfoField name = "test" />
72+ </ >
73+ ) ;
74+ } }
75+ </ Form . Field >
76+ </ Form >
77+ ) ;
78+ } ;
79+
80+ const onFinish = jest . fn ( ) ;
81+ const wrapper = mount ( < KeepDemo onFinish = { onFinish } keep /> ) ;
82+
83+ // Change value
84+ wrapper
85+ . find ( 'input' )
86+ . first ( )
87+ . simulate ( 'change' , { target : { value : 'light' } } ) ;
88+
89+ formRef . current . submit ( ) ;
90+ await timeout ( ) ;
91+ expect ( onFinish ) . toHaveBeenCalledWith ( { test : 'light' } ) ;
92+ onFinish . mockReset ( ) ;
93+
94+ // Remove preserve should not change the value
95+ wrapper . setProps ( { keep : false } ) ;
96+ await timeout ( ) ;
97+ formRef . current . submit ( ) ;
98+ await timeout ( ) ;
99+ expect ( onFinish ) . toHaveBeenCalledWith ( { test : 'light' } ) ;
58100 } ) ;
59101
60102 it ( 'form perishable but field !perishable' , async ( ) => {
0 commit comments