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

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-08-25 13:36:37 +00:00
import { calcRangeKeys } from '../utils/dictUtil';
2018-09-28 06:35:26 +00:00
describe('Tree util', () => {
2021-08-25 13:36:37 +00:00
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' }] },
],
2018-09-28 06:35:26 +00:00
},
2021-08-25 13:36:37 +00:00
];
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());
2019-01-12 03:33:27 +00:00
});
2018-09-28 06:35:26 +00:00
2021-08-25 13:36:37 +00:00
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([]);
});
2019-01-12 03:33:27 +00:00
});
});