@cainiaofe/cn-ui-m
Version:
73 lines (72 loc) • 2.57 kB
JavaScript
import { toggleChildrenState } from '../toggle-node';
describe('toggleChildrenState', function () {
it('should toggle the state of all children when checked is true', function () {
var children = [
{
label: 'Node 1',
value: 'Node 1',
pos: '1',
checked: false,
indeterminate: false,
children: [
{
label: 'Child 1',
value: 'Child 1',
checked: false,
children: [],
pos: '1-1',
indeterminate: false,
},
{
label: 'Child 2',
value: 'Child 2',
checked: false,
children: [],
pos: '1-2',
indeterminate: false,
},
],
},
];
var result = toggleChildrenState(children, true);
expect(result[0].checked).toBe(true);
expect(result[0].indeterminate).toBe(false);
expect(result[0].children[0].checked).toBe(true);
expect(result[0].children[1].checked).toBe(true);
});
it('should not toggle the state of disabled children', function () {
var children = [
{
label: 'Node 1',
value: 'Node 1',
pos: '1',
checked: false,
indeterminate: false,
children: [
{
label: 'Child 1',
value: 'Child 1',
checked: false,
children: [],
pos: '1-1',
indeterminate: false,
},
{
label: 'Child 2',
value: 'Child 2',
checked: false,
children: [],
pos: '1-2',
indeterminate: false,
disabled: true,
},
],
},
];
var result = toggleChildrenState(children, true);
expect(result[0].checked).toBe(true);
expect(result[0].indeterminate).toBe(false);
expect(result[0].children[0].checked).toBe(true);
expect(result[0].children[1].checked).toBe(false);
});
});