@@ -335,6 +335,38 @@ describe('LiveController data-model Tests', () => {
335
335
expect ( test . component . valueStore . getOriginalProps ( ) ) . toEqual ( { form : { check : [ 'foo' , 'bar' ] } } ) ;
336
336
} ) ;
337
337
338
+ it ( 'sends correct data for array valued checkbox fields with non-form object' , async ( ) => {
339
+ const test = await createTest ( { check : [ ] } , ( data : any ) => `
340
+ <div ${ initComponent ( data ) } >
341
+ <form data-model="*">
342
+ <label>
343
+ Checkbox 1: <input type="checkbox" name="check[]" value="foo" ${ data . check . indexOf ( 'foo' ) > - 1 ? 'checked' : '' } />
344
+ </label>
345
+
346
+ <label>
347
+ Checkbox 2: <input type="checkbox" name="check[]" value="bar" ${ data . check . indexOf ( 'bar' ) > - 1 ? 'checked' : '' } />
348
+ </label>
349
+ </form>
350
+
351
+ Checkbox 2 is ${ data . check . indexOf ( 'bar' ) > - 1 ? 'checked' : 'unchecked' }
352
+ </div>
353
+ ` ) ;
354
+
355
+ const check1Element = getByLabelText ( test . element , 'Checkbox 1:' ) ;
356
+ const check2Element = getByLabelText ( test . element , 'Checkbox 2:' ) ;
357
+
358
+ // only 1 Ajax call will be made thanks to debouncing
359
+ test . expectsAjaxCall ( )
360
+ . expectUpdatedData ( { 'check' : [ 'foo' , 'bar' ] } ) ;
361
+
362
+ await userEvent . click ( check1Element ) ;
363
+ await userEvent . click ( check2Element ) ;
364
+
365
+ await waitFor ( ( ) => expect ( test . element ) . toHaveTextContent ( 'Checkbox 2 is checked' ) ) ;
366
+
367
+ expect ( test . component . valueStore . getOriginalProps ( ) ) . toEqual ( { check : [ 'foo' , 'bar' ] } ) ;
368
+ } ) ;
369
+
338
370
it ( 'sends correct data for array valued checkbox fields with initial data' , async ( ) => {
339
371
const test = await createTest ( { form : { check : [ 'foo' ] } } , ( data : any ) => `
340
372
<div ${ initComponent ( data ) } >
@@ -367,6 +399,36 @@ describe('LiveController data-model Tests', () => {
367
399
expect ( test . component . valueStore . getOriginalProps ( ) ) . toEqual ( { form : { check : [ 'bar' ] } } ) ;
368
400
} ) ;
369
401
402
+ it ( 'sends correct data for array valued checkbox fields with non-form object and with initial data' , async ( ) => {
403
+ const test = await createTest ( { check : [ 'foo' ] } , ( data : any ) => `
404
+ <div ${ initComponent ( data ) } >
405
+ <label>
406
+ Checkbox 1: <input type="checkbox" data-model="check[]" value="foo" ${ data . check . indexOf ( 'foo' ) > - 1 ? 'checked' : '' } />
407
+ </label>
408
+
409
+ <label>
410
+ Checkbox 2: <input type="checkbox" data-model="check[]" value="bar" ${ data . check . indexOf ( 'bar' ) > - 1 ? 'checked' : '' } />
411
+ </label>
412
+
413
+ Checkbox 1 is ${ data . check . indexOf ( 'foo' ) > - 1 ? 'checked' : 'unchecked' }
414
+ </div>
415
+ ` ) ;
416
+
417
+ const check1Element = getByLabelText ( test . element , 'Checkbox 1:' ) ;
418
+ const check2Element = getByLabelText ( test . element , 'Checkbox 2:' ) ;
419
+
420
+ // only 1 Ajax call will be made thanks to debouncing
421
+ test . expectsAjaxCall ( )
422
+ . expectUpdatedData ( { 'check' : [ 'bar' ] } ) ;
423
+
424
+ await userEvent . click ( check1Element ) ;
425
+ await userEvent . click ( check2Element ) ;
426
+
427
+ await waitFor ( ( ) => expect ( test . element ) . toHaveTextContent ( 'Checkbox 1 is unchecked' ) ) ;
428
+
429
+ expect ( test . component . valueStore . getOriginalProps ( ) ) . toEqual ( { check : [ 'bar' ] } ) ;
430
+ } ) ;
431
+
370
432
it ( 'sends correct data for select multiple field' , async ( ) => {
371
433
const test = await createTest ( { form : { select : [ ] } } , ( data : any ) => `
372
434
<div ${ initComponent ( data ) } >
0 commit comments