2019-09-28 11:31:28 +08:00
|
|
|
import { calcRangeKeys } from '../utils/dictUtil';
|
2018-06-04 11:20:17 +08:00
|
|
|
|
|
|
|
describe('Tree util', () => {
|
|
|
|
it('calc range keys', () => {
|
2019-08-12 13:22:36 +08:00
|
|
|
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-06-04 11:20:17 +08:00
|
|
|
|
2019-08-12 13:22:36 +08:00
|
|
|
const keys = calcRangeKeys(treeData, ['0-0', '0-2', '0-2-0'], '0-2-0-1', '0-0-0');
|
2018-06-04 11:20:17 +08:00
|
|
|
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());
|
|
|
|
});
|
|
|
|
});
|