2018-06-04 11:20:17 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Tree from '../index';
|
|
|
|
import { calcRangeKeys } from '../util';
|
|
|
|
|
2018-11-28 15:00:03 +08:00
|
|
|
const { TreeNode } = Tree;
|
2018-06-04 11:20:17 +08:00
|
|
|
|
|
|
|
describe('Tree util', () => {
|
|
|
|
it('calc range keys', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<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>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Tree>,
|
2018-06-04 11:20:17 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
const { children } = wrapper.find(Tree).props();
|
|
|
|
const keys = calcRangeKeys(children, ['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());
|
|
|
|
});
|
|
|
|
});
|