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 Tree from '../index';
import { calcRangeKeys } from '../util';
const TreeNode = Tree.TreeNode;
import { calcRangeKeys } from '../utils/dictUtil';
describe('Tree util', () => {
it('calc range keys', () => {
const wrapper = mount({
render() {
return (
<Tree>
<TreeNode key="0-0">
<TreeNode key="0-0-0" />
<TreeNode key="0-0-1" />
</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>
);
describe('calcRangeKeys', () => {
const treeData = [
{ key: '0-0', children: [{ key: '0-0-0' }, { key: '0-0-1' }] },
{ key: '0-1', children: [{ key: '0-1-0' }, { key: '0-1-1' }] },
{
key: '0-2',
children: [
{ key: '0-2-0', children: [{ key: '0-2-0-0' }, { key: '0-2-0-1' }, { key: '0-2-0-2' }] },
],
},
];
it('calc range keys', () => {
const keys = calcRangeKeys({
treeData,
expandedKeys: ['0-0', '0-2', '0-2-0'],
startKey: '0-2-0-1',
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'];
expect(keys.sort()).toEqual(target.sort());
});
const treeWrapper = wrapper.findComponent({ name: 'ATree' });
const keys = calcRangeKeys(
treeWrapper.vm.$slots.default(),
['0-0', '0-2', '0-2-0'],
'0-2-0-1',
'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'];
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([]);
});
});
});