@@ -37,7 +37,7 @@ describe('Form.Preserve', () => {
37
37
38
38
await matchTest ( false , { keep : 233 , remove : 666 } ) ;
39
39
await matchTest ( true , { keep : 233 } ) ;
40
- await matchTest ( false , { keep : 233 } ) ;
40
+ await matchTest ( false , { keep : 233 , remove : 666 } ) ;
41
41
} ) ;
42
42
43
43
it ( 'form' , async ( ) => {
@@ -54,7 +54,49 @@ describe('Form.Preserve', () => {
54
54
55
55
await matchTest ( false , { keep : 233 , remove : 666 } ) ;
56
56
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' } ) ;
58
100
} ) ;
59
101
60
102
it ( 'form perishable but field !perishable' , async ( ) => {
0 commit comments