@@ -325,12 +325,14 @@ Object.keys(testContexts).forEach((testKey) => {
325
325
assert . equal (
326
326
get ( store . getState ( ) . test , 'single' ) ,
327
327
false , 'false' ) ;
328
+ assert . equal ( checkbox . checked , false ) ;
328
329
329
330
TestUtils . Simulate . change ( checkbox ) ;
330
331
331
332
assert . equal (
332
333
get ( store . getState ( ) . test , 'single' ) ,
333
334
true , 'true' ) ;
335
+ assert . equal ( checkbox . checked , true ) ;
334
336
} ) ;
335
337
336
338
it ( 'should check/uncheck the checkbox when model is externally changed' , ( ) => {
@@ -350,6 +352,114 @@ Object.keys(testContexts).forEach((testKey) => {
350
352
} ) ;
351
353
} ) ;
352
354
355
+ describe ( 'with <Control.checkbox /> (single toggle, dynamic form, defaultChecked)' , ( ) => {
356
+ const initialState = getInitialState ( { single : true } ) ;
357
+ const store = testCreateStore ( {
358
+ testForm : formReducer ( 'test' ) ,
359
+ test : modelReducer ( 'test' , initialState ) ,
360
+ } ) ;
361
+
362
+ const field = TestUtils . renderIntoDocument (
363
+ < Provider store = { store } >
364
+ < Control . checkbox model = "test.other" defaultChecked />
365
+ </ Provider >
366
+ ) ;
367
+
368
+ const checkbox = TestUtils . findRenderedDOMComponentWithTag ( field , 'input' ) ;
369
+
370
+ it ( 'should initially set the checkbox to checked when defaultChecked is true' , ( ) => {
371
+ assert . equal ( checkbox . checked , true ) ;
372
+ } ) ;
373
+
374
+ it ( 'should give each radio input a name attribute of the model' , ( ) => {
375
+ assert . equal ( checkbox . name , 'test.other' ) ;
376
+ } ) ;
377
+
378
+ it ( 'should dispatch a change event when changed' , ( ) => {
379
+ TestUtils . Simulate . change ( checkbox ) ;
380
+
381
+ assert . equal (
382
+ get ( store . getState ( ) . test , 'other' ) ,
383
+ false , 'false' ) ;
384
+ assert . equal ( checkbox . checked , false ) ;
385
+
386
+ TestUtils . Simulate . change ( checkbox ) ;
387
+
388
+ assert . equal (
389
+ get ( store . getState ( ) . test , 'other' ) ,
390
+ true , 'true' ) ;
391
+ assert . equal ( checkbox . checked , true ) ;
392
+ } ) ;
393
+
394
+ it ( 'should check/uncheck the checkbox when model is externally changed' , ( ) => {
395
+ store . dispatch ( actions . change ( 'test.other' , true ) ) ;
396
+ assert . equal ( checkbox . checked , true ) ;
397
+
398
+ store . dispatch ( actions . change ( 'test.other' , false ) ) ;
399
+ assert . equal ( checkbox . checked , false ) ;
400
+ } ) ;
401
+
402
+ it ( 'should uncheck the checkbox for any falsey value' , ( ) => {
403
+ store . dispatch ( actions . change ( 'test.other' , '' ) ) ;
404
+
405
+ assert . equal ( checkbox . checked , false ) ;
406
+ } ) ;
407
+ } ) ;
408
+
409
+ describe ( 'with <Control.checkbox /> (single toggle, dynamic form, !defaultChecked)' , ( ) => {
410
+ const initialState = getInitialState ( { single : true } ) ;
411
+ const store = testCreateStore ( {
412
+ testForm : formReducer ( 'test' ) ,
413
+ test : modelReducer ( 'test' , initialState ) ,
414
+ } ) ;
415
+
416
+ const field = TestUtils . renderIntoDocument (
417
+ < Provider store = { store } >
418
+ < Control . checkbox model = "test.other" defaultChecked = { false } />
419
+ </ Provider >
420
+ ) ;
421
+
422
+ const checkbox = TestUtils . findRenderedDOMComponentWithTag ( field , 'input' ) ;
423
+
424
+ it ( 'should initially set the checkbox to unchecked when defaultChecked is false' , ( ) => {
425
+ assert . equal ( checkbox . checked , false ) ;
426
+ } ) ;
427
+
428
+ it ( 'should give each radio input a name attribute of the model' , ( ) => {
429
+ assert . equal ( checkbox . name , 'test.other' ) ;
430
+ } ) ;
431
+
432
+ it ( 'should dispatch a change event when changed' , ( ) => {
433
+ TestUtils . Simulate . change ( checkbox ) ;
434
+
435
+ assert . equal (
436
+ get ( store . getState ( ) . test , 'other' ) ,
437
+ true , 'true' ) ;
438
+
439
+ TestUtils . Simulate . change ( checkbox ) ;
440
+
441
+ assert . equal (
442
+ get ( store . getState ( ) . test , 'other' ) ,
443
+ false , 'false' ) ;
444
+ } ) ;
445
+
446
+ it ( 'should check/uncheck the checkbox when model is externally changed' , ( ) => {
447
+ store . dispatch ( actions . change ( 'test.other' , false ) ) ;
448
+
449
+ assert . equal ( checkbox . checked , false ) ;
450
+
451
+ store . dispatch ( actions . change ( 'test.other' , true ) ) ;
452
+
453
+ assert . equal ( checkbox . checked , true ) ;
454
+ } ) ;
455
+
456
+ it ( 'should uncheck the checkbox for any falsey value' , ( ) => {
457
+ store . dispatch ( actions . change ( 'test.other' , '' ) ) ;
458
+
459
+ assert . equal ( checkbox . checked , false ) ;
460
+ } ) ;
461
+ } ) ;
462
+
353
463
describe ( 'with <Control.checkbox /> (multi toggle)' , ( ) => {
354
464
const initialState = getInitialState ( { foo : [ 1 ] } ) ;
355
465
const store = testCreateStore ( {
0 commit comments