You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
5 years ago
|
import { calcRangeKeys } from '../utils/dictUtil';
|
||
7 years ago
|
|
||
|
describe('Tree util', () => {
|
||
5 years ago
|
describe('calcRangeKeys', () => {
|
||
5 years ago
|
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' }] },
|
||
|
],
|
||
|
},
|
||
|
];
|
||
7 years ago
|
|
||
5 years ago
|
it('calc range keys', () => {
|
||
2 years ago
|
const rangeKeys = calcRangeKeys({
|
||
5 years ago
|
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'];
|
||
2 years ago
|
expect(rangeKeys.sort()).toEqual(target.sort());
|
||
5 years ago
|
});
|
||
|
|
||
|
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([]);
|
||
|
});
|
||
7 years ago
|
});
|
||
|
});
|