Skip to content

Commit e8b507d

Browse files
committed
Add TreeNode.props.onCheck tests
1 parent b12c38c commit e8b507d

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

test/TreeNode.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff 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 = {};

0 commit comments

Comments
 (0)