@@ -81,7 +81,7 @@ describe('getFormFieldValue', () => {
8181 expect ( value ) . toBe ( undefined ) ;
8282 } ) ;
8383
84- it ( 'gets the value at the right level ' , ( ) => {
84+ it ( 'gets the value at the right level from an array of objects ' , ( ) => {
8585 const complexValues = {
8686 company : {
8787 name : 'John Deer' ,
@@ -114,4 +114,55 @@ describe('getFormFieldValue', () => {
114114 const value2 = getFormFieldValue ( 'licenses' , complexValues , field2 ) ;
115115 expect ( value2 ) . toEqual ( [ 'C' ] ) ;
116116 } ) ;
117+
118+ it ( 'gets the value at the right level from an array item' , ( ) => {
119+ const complexValues = {
120+ company : {
121+ name : 'John Deer' ,
122+ age : 30 ,
123+ contactIds : [ '123' , '456' ] ,
124+ } ,
125+ age : 666 ,
126+ } ;
127+
128+ const firstListElementField = getPydanticFormFieldDummy ( {
129+ id : 'company.contactIds.0' ,
130+ } ) ;
131+ const valueFromFirstListElement = getFormFieldValue (
132+ 'age' ,
133+ complexValues ,
134+ firstListElementField ,
135+ ) ;
136+ expect ( valueFromFirstListElement ) . toEqual ( 30 ) ;
137+
138+ const secondListElementField = getPydanticFormFieldDummy ( {
139+ id : 'company.contactIds.1' ,
140+ } ) ;
141+ const valueFromSecondListElement = getFormFieldValue (
142+ 'age' ,
143+ complexValues ,
144+ secondListElementField ,
145+ ) ;
146+ expect ( valueFromSecondListElement ) . toEqual ( 30 ) ;
147+
148+ const nameElementField = getPydanticFormFieldDummy ( {
149+ id : 'company.name' ,
150+ } ) ;
151+ const valueFromNameElement = getFormFieldValue (
152+ 'age' ,
153+ complexValues ,
154+ nameElementField ,
155+ ) ;
156+ expect ( valueFromNameElement ) . toEqual ( 30 ) ;
157+
158+ const contactIdsElementField = getPydanticFormFieldDummy ( {
159+ id : 'company.contactIds' ,
160+ } ) ;
161+ const ownValue = getFormFieldValue (
162+ 'contactIds' ,
163+ complexValues ,
164+ contactIdsElementField ,
165+ ) ;
166+ expect ( ownValue ) . toEqual ( [ '123' , '456' ] ) ;
167+ } ) ;
117168} ) ;
0 commit comments