File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,83 @@ describe('<TreeNode />', () => {
125125 } ) ;
126126 } ) ;
127127
128+ describe ( 'onCheck' , ( ) => {
129+ it ( 'should pass the current node\'s value' , ( ) => {
130+ let actual = { } ;
131+
132+ const wrapper = shallow (
133+ < TreeNode
134+ { ...baseProps }
135+ value = "jupiter"
136+ onCheck = { ( node ) => {
137+ actual = node ;
138+ } }
139+ /> ,
140+ ) ;
141+
142+ wrapper . find ( 'input[type="checkbox"]' ) . simulate ( 'change' ) ;
143+
144+ assert . equal ( 'jupiter' , actual . value ) ;
145+ } ) ;
146+
147+ it ( 'should toggle an unchecked node to checked' , ( ) => {
148+ let actual = { } ;
149+
150+ const wrapper = shallow (
151+ < TreeNode
152+ { ...baseProps }
153+ checked = { 0 }
154+ value = "jupiter"
155+ onCheck = { ( node ) => {
156+ actual = node ;
157+ } }
158+ /> ,
159+ ) ;
160+
161+ wrapper . find ( 'input[type="checkbox"]' ) . simulate ( 'change' ) ;
162+
163+ assert . isTrue ( actual . checked ) ;
164+ } ) ;
165+
166+ it ( 'should toggle a checked node to unchecked' , ( ) => {
167+ let actual = { } ;
168+
169+ const wrapper = shallow (
170+ < TreeNode
171+ { ...baseProps }
172+ checked = { 1 }
173+ value = "jupiter"
174+ onCheck = { ( node ) => {
175+ actual = node ;
176+ } }
177+ /> ,
178+ ) ;
179+
180+ wrapper . find ( 'input[type="checkbox"]' ) . simulate ( 'change' ) ;
181+
182+ assert . isFalse ( actual . checked ) ;
183+ } ) ;
184+
185+ it ( 'should toggle a partially-checked node to checked' , ( ) => {
186+ let actual = { } ;
187+
188+ const wrapper = shallow (
189+ < TreeNode
190+ { ...baseProps }
191+ checked = { 2 }
192+ value = "jupiter"
193+ onCheck = { ( node ) => {
194+ actual = node ;
195+ } }
196+ /> ,
197+ ) ;
198+
199+ wrapper . find ( 'input[type="checkbox"]' ) . simulate ( 'change' ) ;
200+
201+ assert . isTrue ( actual . checked ) ;
202+ } ) ;
203+ } ) ;
204+
128205 describe ( 'onExpand' , ( ) => {
129206 it ( 'should negate the expanded property and pass the current node\'s value' , ( ) => {
130207 let actual = { } ;
You can’t perform that action at this time.
0 commit comments