@@ -183,6 +183,78 @@ describe('condition test', () => {
183183 } ) ;
184184 } ) ;
185185
186+ it ( 'should not override initial value with setter value' , async ( ) => {
187+ const schema = {
188+ fields : [
189+ {
190+ component : 'text-field' ,
191+ name : 'field-1' ,
192+ label : 'first name' ,
193+ } ,
194+ {
195+ component : 'text-field' ,
196+ name : 'field-2' ,
197+ label : 'last name' ,
198+ } ,
199+ {
200+ component : 'text-field' ,
201+ name : 'field-3' ,
202+ label : 'occupation' ,
203+ condition : {
204+ sequence : [
205+ {
206+ and : [
207+ { when : 'field-1' , is : 'james' } ,
208+ { when : 'field-2' , is : 'bond' } ,
209+ ] ,
210+ then : { set : { 'field-3' : 'SPY' } } ,
211+ else : { visible : true } ,
212+ } ,
213+ {
214+ and : [
215+ { when : 'field-1' , is : 'steve' } ,
216+ { when : 'field-2' , is : 'jobs' } ,
217+ ] ,
218+ then : { set : { 'field-3' : 'CEO' } } ,
219+ else : { visible : true } ,
220+ } ,
221+ ] ,
222+ } ,
223+ } ,
224+ ] ,
225+ } ;
226+
227+ render (
228+ < FormRenderer
229+ { ...initialProps }
230+ schema = { schema }
231+ initialValues = { {
232+ 'field-1' : 'steve' ,
233+ 'field-2' : 'jobs' ,
234+ 'field-3' : 'RETIRED' ,
235+ } }
236+ />
237+ ) ;
238+
239+ await act ( async ( ) => {
240+ jest . advanceTimersByTime ( 1 ) ;
241+ } ) ;
242+
243+ expect ( screen . getByLabelText ( 'field-3' ) ) . toBeInTheDocument ( ) ;
244+
245+ await act ( async ( ) => {
246+ jest . advanceTimersByTime ( 10 ) ;
247+ } ) ;
248+
249+ userEvent . click ( screen . getByText ( 'Submit' ) ) ;
250+
251+ expect ( onSubmit ) . toHaveBeenCalledWith ( {
252+ 'field-1' : 'steve' ,
253+ 'field-2' : 'jobs' ,
254+ 'field-3' : 'RETIRED' ,
255+ } ) ;
256+ } ) ;
257+
186258 it ( 'sets value when condition is fulfill on reset' , async ( ) => {
187259 schema = {
188260 fields : [
0 commit comments