@@ -20,6 +20,125 @@ describe('<CheckboxTree />', () => {
2020 } ) ;
2121 } ) ;
2222
23+ describe ( 'checkModel' , ( ) => {
24+ describe ( 'all' , ( ) => {
25+ it ( 'should record checked parent and leaf nodes' , ( ) => {
26+ let actual = null ;
27+
28+ const wrapper = mount (
29+ < CheckboxTree
30+ checkModel = "all"
31+ nodes = { [
32+ {
33+ value : 'jupiter' ,
34+ label : 'Jupiter' ,
35+ children : [
36+ { value : 'io' , label : 'Io' } ,
37+ { value : 'europa' , label : 'Europa' } ,
38+ ] ,
39+ } ,
40+ ] }
41+ onCheck = { ( checked ) => {
42+ actual = checked ;
43+ } }
44+ /> ,
45+ ) ;
46+
47+ wrapper . find ( 'TreeNode input[type="checkbox"]' ) . simulate ( 'click' ) ;
48+ assert . deepEqual ( [ 'jupiter' , 'io' , 'europa' ] , actual ) ;
49+ } ) ;
50+
51+ it ( 'should percolate `checked` to all parents and grandparents if all leaves are checked' , ( ) => {
52+ let actual = null ;
53+
54+ const wrapper = mount (
55+ < CheckboxTree
56+ checkModel = "all"
57+ checked = { [ 'mercury' , 'io' ] }
58+ expanded = { [ 'sol' , 'jupiter' ] }
59+ nodes = { [
60+ {
61+ value : 'sol' ,
62+ label : 'Sol System' ,
63+ children : [
64+ { value : 'mercury' , label : 'Mercury' } ,
65+ {
66+ value : 'jupiter' ,
67+ label : 'Jupiter' ,
68+ children : [
69+ { value : 'io' , label : 'Io' } ,
70+ { value : 'europa' , label : 'Europa' } ,
71+ ] ,
72+ } ,
73+ ] ,
74+ } ,
75+ ] }
76+ onCheck = { ( checked ) => {
77+ actual = checked ;
78+ } }
79+ /> ,
80+ ) ;
81+
82+ wrapper . find ( 'TreeNode[value="europa"] input[type="checkbox"]' ) . simulate ( 'click' ) ;
83+ assert . deepEqual ( [ 'sol' , 'mercury' , 'jupiter' , 'io' , 'europa' ] , actual ) ;
84+ } ) ;
85+
86+ it ( 'should NOT percolate `checked` to the parent if not all leaves are checked' , ( ) => {
87+ let actual = null ;
88+
89+ const wrapper = mount (
90+ < CheckboxTree
91+ checkModel = "all"
92+ expanded = { [ 'jupiter' ] }
93+ nodes = { [
94+ {
95+ value : 'jupiter' ,
96+ label : 'Jupiter' ,
97+ children : [
98+ { value : 'io' , label : 'Io' } ,
99+ { value : 'europa' , label : 'Europa' } ,
100+ ] ,
101+ } ,
102+ ] }
103+ onCheck = { ( checked ) => {
104+ actual = checked ;
105+ } }
106+ /> ,
107+ ) ;
108+
109+ wrapper . find ( 'TreeNode[value="europa"] input[type="checkbox"]' ) . simulate ( 'click' ) ;
110+ assert . deepEqual ( [ 'europa' ] , actual ) ;
111+ } ) ;
112+ } ) ;
113+
114+ describe ( 'leaf' , ( ) => {
115+ it ( 'should only record leaf nodes in the checked array' , ( ) => {
116+ let actual = null ;
117+
118+ const wrapper = mount (
119+ < CheckboxTree
120+ nodes = { [
121+ {
122+ value : 'jupiter' ,
123+ label : 'Jupiter' ,
124+ children : [
125+ { value : 'io' , label : 'Io' } ,
126+ { value : 'europa' , label : 'Europa' } ,
127+ ] ,
128+ } ,
129+ ] }
130+ onCheck = { ( checked ) => {
131+ actual = checked ;
132+ } }
133+ /> ,
134+ ) ;
135+
136+ wrapper . find ( 'TreeNode input[type="checkbox"]' ) . simulate ( 'click' ) ;
137+ assert . deepEqual ( [ 'io' , 'europa' ] , actual ) ;
138+ } ) ;
139+ } ) ;
140+ } ) ;
141+
23142 describe ( 'checked' , ( ) => {
24143 it ( 'should not throw an exception if it contains values that are not in the `nodes` property' , ( ) => {
25144 const wrapper = shallow (
@@ -337,7 +456,7 @@ describe('<CheckboxTree />', () => {
337456 } ) ;
338457
339458 describe ( 'onlyLeafCheckboxes' , ( ) => {
340- it ( 'should only render show checkboxes for leaf nodes' , ( ) => {
459+ it ( 'should only render checkboxes for leaf nodes' , ( ) => {
341460 const wrapper = mount (
342461 < CheckboxTree
343462 expanded = { [ 'jupiter' ] }
0 commit comments