@@ -336,7 +336,7 @@ describe('<CheckboxTree />', () => {
336
336
) ;
337
337
} ) ;
338
338
339
- it ( 'should render a node with no " children" array as a leaf' , ( ) => {
339
+ it ( 'should render a node with no ` children` array as a leaf' , ( ) => {
340
340
const wrapper = shallow (
341
341
< CheckboxTree
342
342
nodes = { [
@@ -349,7 +349,7 @@ describe('<CheckboxTree />', () => {
349
349
assert . equal ( true , wrapper . find ( TreeNode ) . prop ( 'isLeaf' ) ) ;
350
350
} ) ;
351
351
352
- it ( 'should render a node with an empty " children" array as a parent' , ( ) => {
352
+ it ( 'should render a node with an empty ` children` array as a parent' , ( ) => {
353
353
const wrapper = shallow (
354
354
< CheckboxTree
355
355
nodes = { [
@@ -366,7 +366,24 @@ describe('<CheckboxTree />', () => {
366
366
assert . equal ( false , wrapper . find ( TreeNode ) . prop ( 'isLeaf' ) ) ;
367
367
} ) ;
368
368
369
- it ( 'should render a node with a non-empty "children" array as a parent' , ( ) => {
369
+ // https://github.com/jakezatecky/react-checkbox-tree/issues/258
370
+ it ( 'should render a node with an empty `children` array as unchecked by default' , ( ) => {
371
+ const wrapper = shallow (
372
+ < CheckboxTree
373
+ nodes = { [
374
+ {
375
+ value : 'jupiter' ,
376
+ label : 'Jupiter' ,
377
+ children : [ ] ,
378
+ } ,
379
+ ] }
380
+ /> ,
381
+ ) ;
382
+
383
+ assert . equal ( false , wrapper . find ( TreeNode ) . prop ( 'checked' ) ) ;
384
+ } ) ;
385
+
386
+ it ( 'should render a node with a non-empty `children` array as a parent' , ( ) => {
370
387
const wrapper = shallow (
371
388
< CheckboxTree
372
389
nodes = { [
@@ -734,6 +751,38 @@ describe('<CheckboxTree />', () => {
734
751
assert . deepEqual ( [ 'io' , 'europa' ] , actualChecked ) ;
735
752
} ) ;
736
753
754
+ // https://github.com/jakezatecky/react-checkbox-tree/issues/258
755
+ it ( 'should toggle a node with an empty `children` array' , ( ) => {
756
+ let actualChecked = { } ;
757
+ const makeEmptyParentNode = ( checked ) => (
758
+ mount (
759
+ < CheckboxTree
760
+ nodes = { [
761
+ {
762
+ value : 'jupiter' ,
763
+ label : 'Jupiter' ,
764
+ children : [ ] ,
765
+ } ,
766
+ ] }
767
+ checked = { checked }
768
+ onCheck = { ( node ) => {
769
+ actualChecked = node ;
770
+ } }
771
+ /> ,
772
+ )
773
+ ) ;
774
+
775
+ // Unchecked to checked
776
+ let wrapper = makeEmptyParentNode ( [ ] ) ;
777
+ wrapper . find ( 'TreeNode input[type="checkbox"]' ) . simulate ( 'click' ) ;
778
+ assert . deepEqual ( [ 'jupiter' ] , actualChecked ) ;
779
+
780
+ // Checked to unchecked
781
+ wrapper = makeEmptyParentNode ( [ 'jupiter' ] ) ;
782
+ wrapper . find ( 'TreeNode input[type="checkbox"]' ) . simulate ( 'click' ) ;
783
+ assert . deepEqual ( [ ] , actualChecked ) ;
784
+ } ) ;
785
+
737
786
it ( 'should not add disabled children to the checked array' , ( ) => {
738
787
let actualChecked = null ;
739
788
0 commit comments