ant-design-vue/components/tree/__tests__/util.test.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
import { mount } from '@vue/test-utils';
import Tree from '../index';
import { calcRangeKeys } from '../util';
2018-09-28 06:35:26 +00:00
2019-01-12 03:33:27 +00:00
const TreeNode = Tree.TreeNode;
2018-09-28 06:35:26 +00:00
describe('Tree util', () => {
it('calc range keys', () => {
const wrapper = mount({
2019-01-12 03:33:27 +00:00
render() {
2018-09-28 06:35:26 +00:00
return (
<Tree>
2019-01-12 03:33:27 +00:00
<TreeNode key="0-0">
<TreeNode key="0-0-0" />
<TreeNode key="0-0-1" />
2018-09-28 06:35:26 +00:00
</TreeNode>
2019-01-12 03:33:27 +00:00
<TreeNode key="0-1">
<TreeNode key="0-1-0" />
<TreeNode key="0-1-1" />
2018-09-28 06:35:26 +00:00
</TreeNode>
2019-01-12 03:33:27 +00:00
<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" />
2018-09-28 06:35:26 +00:00
</TreeNode>
</TreeNode>
</Tree>
2019-01-12 03:33:27 +00:00
);
2018-09-28 06:35:26 +00:00
},
2019-01-12 03:33:27 +00:00
});
2018-09-28 06:35:26 +00:00
2019-01-12 03:33:27 +00:00
const treeWrapper = wrapper.find({ 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());
});
});