@@ -217,6 +217,66 @@ describe('<CheckboxGroupInput />', () => {
217
217
expect ( queryByText ( 'Can I help you?' ) ) . not . toBeNull ( ) ;
218
218
} ) ;
219
219
220
+ it ( 'should not parse selected values types to numbers if all choices types are non numbers' , ( ) => {
221
+ const handleSubmit = jest . fn ( ) ;
222
+ const { getByLabelText } = render (
223
+ < Form
224
+ onSubmit = { handleSubmit }
225
+ initialValues = { { notifications : [ '31' , '42' ] } }
226
+ render = { ( { handleSubmit } ) => (
227
+ < form onSubmit = { handleSubmit } >
228
+ < CheckboxGroupInput
229
+ source = "notifications"
230
+ choices = { [
231
+ { id : '12' , name : 'Ray Hakt' } ,
232
+ { id : '31' , name : 'Ann Gullar' } ,
233
+ { id : '42' , name : 'Sean Phonee' } ,
234
+ ] }
235
+ />
236
+ < button type = "submit" aria-label = "Save" />
237
+ </ form >
238
+ ) }
239
+ />
240
+ ) ;
241
+ const input = getByLabelText ( 'Ray Hakt' ) as HTMLInputElement ;
242
+ fireEvent . click ( input ) ;
243
+
244
+ fireEvent . click ( getByLabelText ( 'Save' ) ) ;
245
+ expect ( handleSubmit . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
246
+ notifications : [ '31' , '42' , '12' ] ,
247
+ } ) ;
248
+ } ) ;
249
+
250
+ it ( 'should parse selected values types to numbers if some choices are numbers' , ( ) => {
251
+ const handleSubmit = jest . fn ( ) ;
252
+ const { getByLabelText } = render (
253
+ < Form
254
+ onSubmit = { handleSubmit }
255
+ initialValues = { { notifications : [ 31 , 42 ] } }
256
+ render = { ( { handleSubmit } ) => (
257
+ < form onSubmit = { handleSubmit } >
258
+ < CheckboxGroupInput
259
+ source = "notifications"
260
+ choices = { [
261
+ { id : 12 , name : 'Ray Hakt' } ,
262
+ { id : 31 , name : 'Ann Gullar' } ,
263
+ { id : 42 , name : 'Sean Phonee' } ,
264
+ ] }
265
+ />
266
+ < button type = "submit" aria-label = "Save" />
267
+ </ form >
268
+ ) }
269
+ />
270
+ ) ;
271
+ const input = getByLabelText ( 'Ray Hakt' ) as HTMLInputElement ;
272
+ fireEvent . click ( input ) ;
273
+
274
+ fireEvent . click ( getByLabelText ( 'Save' ) ) ;
275
+ expect ( handleSubmit . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
276
+ notifications : [ 31 , 42 , 12 ] ,
277
+ } ) ;
278
+ } ) ;
279
+
220
280
describe ( 'error message' , ( ) => {
221
281
it ( 'should not be displayed if field is pristine' , ( ) => {
222
282
const { container } = render (
0 commit comments