UNPKG

@cainiaofe/cn-ui-m

Version:
42 lines (41 loc) 1.66 kB
import { toggleNode } from '../toggle-node'; describe('toggleNode', function () { test('should toggle the node state to checked', function () { var node = { label: 'Node 1', value: 'Node 1', checked: false, indeterminate: true, children: [ { label: 'Child 1', value: 'Child 1', checked: false }, { label: 'Child 2', value: 'Child 2', checked: false }, { label: 'Child 3', value: 'Child 3', checked: false }, ], }; var result = toggleNode(node, true); expect(result.checked).toBe(true); expect(result.indeterminate).toBe(false); expect(result.children[0].checked).toBe(true); expect(result.children[1].checked).toBe(true); expect(result.children[2].checked).toBe(true); }); test('should toggle the node state to unchecked', function () { var node = { label: 'Node 1', value: 'Node 1', checked: true, indeterminate: false, children: [ { label: 'Child 1', value: 'Child 1', checked: true }, { label: 'Child 2', value: 'Child 2', checked: true }, { label: 'Child 3', value: 'Child 3', checked: true }, ], }; var result = toggleNode(node, false); expect(result.checked).toBe(false); expect(result.children[0].checked).toBe(false); expect(result.children[1].checked).toBe(false); expect(result.children[2].checked).toBe(false); expect(result.indeterminate).toBe(false); }); });