@@ -31,7 +31,7 @@ describe('<FormRenderer />', () => {
3131 layoutMapper = {
3232 [ layoutComponents . BUTTON_GROUP ] : ( { children } ) => < div > { children } </ div > ,
3333 [ layoutComponents . BUTTON ] : ( { label, bsStyle, ...rest } ) => < button { ...rest } > { label } </ button > ,
34- [ layoutComponents . FORM_WRAPPER ] : ( { children } ) => < form > { children } </ form > ,
34+ [ layoutComponents . FORM_WRAPPER ] : ( { children, ... props } ) => < form { ... props } > { children } </ form > ,
3535 [ layoutComponents . TITLE ] : ( { children } ) => < div > { children } </ div > ,
3636 [ layoutComponents . DESCRIPTION ] : ( { children } ) => < div > { children } </ div > ,
3737 } ;
@@ -150,5 +150,67 @@ describe('<FormRenderer />', () => {
150150 /> ) ;
151151 expect ( toJson ( wrapper ) ) . toMatchSnapshot ( ) ;
152152 } ) ;
153+
154+ describe ( 'Initial value data types' , ( ) => {
155+ it ( 'should convert string to integer' , ( ) => {
156+ const onSubmit = jest . fn ( ) ;
157+ const schema = {
158+ fields : [ {
159+ component : components . TEXT_FIELD ,
160+ name : 'initial-convert' ,
161+ initialValue : '5' ,
162+ dataType : 'integer' ,
163+ } ] ,
164+ } ;
165+ const wrapper = mount ( < FormRenderer
166+ { ...initialProps }
167+ schema = { schema }
168+ onSubmit = { values => onSubmit ( values ) }
169+ renderFormButtons = { FormControls }
170+ /> ) ;
171+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
172+ expect ( onSubmit ) . toHaveBeenCalledWith ( { 'initial-convert' : 5 } ) ;
173+ } ) ;
174+
175+ it ( 'should convert individual values in array of literals as initial value' , ( ) => {
176+ const onSubmit = jest . fn ( ) ;
177+ const schema = {
178+ fields : [ {
179+ component : components . TEXT_FIELD ,
180+ name : 'initial-convert' ,
181+ initialValue : [ '5' , 3 , '11' , '999' ] ,
182+ dataType : 'integer' ,
183+ } ] ,
184+ } ;
185+ const wrapper = mount ( < FormRenderer
186+ { ...initialProps }
187+ schema = { schema }
188+ onSubmit = { values => onSubmit ( values ) }
189+ renderFormButtons = { FormControls }
190+ /> ) ;
191+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
192+ expect ( onSubmit ) . toHaveBeenCalledWith ( { 'initial-convert' : [ 5 , 3 , 11 , 999 ] } ) ;
193+ } ) ;
194+
195+ it ( 'should convert individual values in array of objects as initial value' , ( ) => {
196+ const onSubmit = jest . fn ( ) ;
197+ const schema = {
198+ fields : [ {
199+ component : components . SELECT ,
200+ name : 'initial-convert' ,
201+ initialValue : [ { value : '5' } , { value : 3 } , { value : '11' } , { value : '999' } ] ,
202+ dataType : 'integer' ,
203+ } ] ,
204+ } ;
205+ const wrapper = mount ( < FormRenderer
206+ { ...initialProps }
207+ schema = { schema }
208+ onSubmit = { values => onSubmit ( values ) }
209+ renderFormButtons = { FormControls }
210+ /> ) ;
211+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
212+ expect ( onSubmit ) . toHaveBeenCalledWith ( { 'initial-convert' : [ { value : 5 } , { value : 3 } , { value : 11 } , { value : 999 } ] } ) ;
213+ } ) ;
214+ } ) ;
153215} ) ;
154216
0 commit comments