@cainiaofe/cn-ui-m
Version:
116 lines (115 loc) • 3.42 kB
JavaScript
import { updateNodeState } from '../update-node-state';
describe('updateNodeState', function () {
test('should return the same node if it has no children', function () {
var node = {
id: 1,
label: 'Node 1',
value: 'Node 1',
children: [],
checked: false,
indeterminate: false,
};
var result = updateNodeState(node);
expect(result).toEqual(node);
});
test('should update the node state correctly if all children are checked', function () {
var node = {
id: 1,
label: 'Node 1',
value: 'Node 1',
children: [
{
id: 2,
label: 'Child 1',
value: 'Child 1',
checked: true,
indeterminate: false,
},
{
id: 3,
label: 'Child 2',
value: 'Child 2',
checked: true,
indeterminate: false,
},
],
checked: false,
indeterminate: false,
};
var expected = {
id: 1,
label: 'Node 1',
value: 'Node 1',
children: [
{
id: 2,
label: 'Child 1',
value: 'Child 1',
checked: true,
indeterminate: false,
},
{
id: 3,
label: 'Child 2',
value: 'Child 2',
checked: true,
indeterminate: false,
},
],
checked: true,
indeterminate: false,
};
var result = updateNodeState(node);
expect(result).toEqual(expected);
});
test('should update the node state correctly if some children are checked', function () {
var node = {
id: 1,
label: 'Node 1',
value: 'Node 1',
children: [
{
id: 2,
label: 'Child 1',
value: 'Child 1',
checked: true,
indeterminate: false,
},
{
id: 3,
label: 'Child 2',
value: 'Child 2',
checked: false,
indeterminate: false,
},
],
checked: false,
indeterminate: false,
};
var expected = {
id: 1,
label: 'Node 1',
value: 'Node 1',
children: [
{
id: 2,
label: 'Child 1',
value: 'Child 1',
checked: true,
indeterminate: false,
},
{
id: 3,
label: 'Child 2',
value: 'Child 2',
checked: false,
indeterminate: false,
},
],
checked: false,
indeterminate: true,
};
var result = updateNodeState(node);
expect(result).toEqual(expected);
});
});