@@ -216,6 +216,41 @@ describe('LiveController data-model Tests', () => {
216
216
fetchMock . done ( ) ;
217
217
} ) ;
218
218
219
+ it ( 'sends correct data for checkbox fields' , async ( ) => {
220
+ const checkboxTemplate = ( data ) => `
221
+ <div
222
+ ${ initLiveComponent ( '/_components/my_component' , data ) }
223
+ data-action="change->live#update"
224
+ >
225
+ <label>
226
+ Checkbox 1: <input type="checkbox" name="form[check1]" value="1" ${ data . form . check1 ? 'checked' : '' } />
227
+ </label>
228
+
229
+ <label>
230
+ Checkbox 2: <input type="checkbox" name="form[check2]" value="1" ${ data . form . check2 ? 'checked' : '' } />
231
+ </label>
232
+ </div>
233
+ ` ;
234
+ const data = { form : { } } ;
235
+ const { element, controller } = await startStimulus ( checkboxTemplate ( data ) ) ;
236
+
237
+ mockRerender ( { form : { check1 : '1' } } , checkboxTemplate ) ;
238
+
239
+ const check1Element = getByLabelText ( element , 'Checkbox 1:' ) ;
240
+ const check2Element = getByLabelText ( element , 'Checkbox 2:' ) ;
241
+
242
+ await userEvent . click ( check1Element ) ;
243
+ await waitFor ( ( ) => expect ( check1Element ) . toBeChecked ( ) ) ;
244
+
245
+ await userEvent . click ( check2Element ) ;
246
+ await waitFor ( ( ) => expect ( check2Element ) . toBeChecked ( ) ) ;
247
+
248
+ expect ( controller . dataValue ) . toEqual ( { form : { check1 : '1' , check2 : '1' } } ) ;
249
+
250
+ // assert all calls were done the correct number of times
251
+ fetchMock . done ( ) ;
252
+ } ) ;
253
+
219
254
it ( 'updates correctly when live#update is on a parent element' , async ( ) => {
220
255
const parentUpdateTemplate = ( data ) => `
221
256
<div
0 commit comments