test: update tree test

pull/4577/head
tangjinzhou 2021-08-25 21:36:37 +08:00
parent e8b1f68899
commit 18295ea0d7
1 changed files with 38 additions and 36 deletions

View File

@ -1,43 +1,45 @@
import { mount } from '@vue/test-utils'; import { calcRangeKeys } from '../utils/dictUtil';
import Tree from '../index';
import { calcRangeKeys } from '../util';
const TreeNode = Tree.TreeNode;
describe('Tree util', () => { describe('Tree util', () => {
it('calc range keys', () => { describe('calcRangeKeys', () => {
const wrapper = mount({ const treeData = [
render() { { key: '0-0', children: [{ key: '0-0-0' }, { key: '0-0-1' }] },
return ( { key: '0-1', children: [{ key: '0-1-0' }, { key: '0-1-1' }] },
<Tree> {
<TreeNode key="0-0"> key: '0-2',
<TreeNode key="0-0-0" /> children: [
<TreeNode key="0-0-1" /> { key: '0-2-0', children: [{ key: '0-2-0-0' }, { key: '0-2-0-1' }, { key: '0-2-0-2' }] },
</TreeNode> ],
<TreeNode key="0-1">
<TreeNode key="0-1-0" />
<TreeNode key="0-1-1" />
</TreeNode>
<TreeNode key="0-2">
<TreeNode key="0-2-0">
<TreeNode key="0-2-0-0" />
<TreeNode key="0-2-0-1" />
<TreeNode key="0-2-0-2" />
</TreeNode>
</TreeNode>
</Tree>
);
}, },
}); ];
const treeWrapper = wrapper.findComponent({ name: 'ATree' }); it('calc range keys', () => {
const keys = calcRangeKeys( const keys = calcRangeKeys({
treeWrapper.vm.$slots.default(), treeData,
['0-0', '0-2', '0-2-0'], expandedKeys: ['0-0', '0-2', '0-2-0'],
'0-2-0-1', startKey: '0-2-0-1',
'0-0-0', endKey: '0-0-0',
); });
const target = ['0-0-0', '0-0-1', '0-1', '0-2', '0-2-0', '0-2-0-0', '0-2-0-1']; const target = ['0-0-0', '0-0-1', '0-1', '0-2', '0-2-0', '0-2-0-0', '0-2-0-1'];
expect(keys.sort()).toEqual(target.sort()); expect(keys.sort()).toEqual(target.sort());
}); });
it('return startKey when startKey === endKey', () => {
const keys = calcRangeKeys({
treeData,
expandedKeys: ['0-0', '0-2', '0-2-0'],
startKey: '0-0-0',
endKey: '0-0-0',
});
expect(keys).toEqual(['0-0-0']);
});
it('return empty array without startKey and endKey', () => {
const keys = calcRangeKeys({
treeData,
expandedKeys: ['0-0', '0-2', '0-2-0'],
});
expect(keys).toEqual([]);
});
});
}); });