mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
a825ed4e66
Support DirTree. close #7749
105 lines
3.1 KiB
JavaScript
105 lines
3.1 KiB
JavaScript
import React from 'react';
|
|
import { mount, render } from 'enzyme';
|
|
import Tree from '../index';
|
|
|
|
const DirectoryTree = Tree.DirectoryTree;
|
|
const TreeNode = Tree.TreeNode;
|
|
|
|
describe('Directory Tree', () => {
|
|
beforeAll(() => {
|
|
jest.useFakeTimers();
|
|
});
|
|
|
|
afterAll(() => {
|
|
jest.useRealTimers();
|
|
});
|
|
|
|
function createTree(props) {
|
|
return (
|
|
<DirectoryTree {...props}>
|
|
<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>
|
|
</DirectoryTree>
|
|
);
|
|
}
|
|
|
|
describe('expand', () => {
|
|
it('click', () => {
|
|
const wrapper = mount(createTree());
|
|
|
|
wrapper.find(TreeNode).find('.ant-tree-node-content-wrapper').at(0).simulate('click');
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
jest.runAllTimers();
|
|
wrapper.find(TreeNode).find('.ant-tree-node-content-wrapper').at(0).simulate('click');
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
});
|
|
|
|
it('double click', () => {
|
|
const wrapper = mount(createTree({ expandAction: 'doubleClick' }));
|
|
|
|
wrapper.find(TreeNode).find('.ant-tree-node-content-wrapper').at(0).simulate('doubleClick');
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
jest.runAllTimers();
|
|
wrapper.find(TreeNode).find('.ant-tree-node-content-wrapper').at(0).simulate('doubleClick');
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
it('defaultExpandAll', () => {
|
|
const wrapper = render(createTree({ defaultExpandAll: true }));
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('defaultExpandParent', () => {
|
|
const wrapper = render(createTree({ defaultExpandParent: true }));
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('expandedKeys update', () => {
|
|
const wrapper = mount(createTree());
|
|
wrapper.setProps({ expandedKeys: ['0-1'] });
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
});
|
|
|
|
it('selectedKeys update', () => {
|
|
const wrapper = mount(createTree({ defaultExpandAll: true }));
|
|
wrapper.setProps({ selectedKeys: ['0-1-0'] });
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
});
|
|
|
|
it('group select', () => {
|
|
let nativeEventProto = null;
|
|
const wrapper = mount(createTree({
|
|
defaultExpandAll: true,
|
|
expandAction: 'doubleClick',
|
|
multiple: true,
|
|
onClick: (e) => {
|
|
nativeEventProto = Object.getPrototypeOf(e.nativeEvent);
|
|
},
|
|
}));
|
|
|
|
wrapper.find(TreeNode).find('.ant-tree-node-content-wrapper').at(0).simulate('click');
|
|
|
|
// React not simulate full of NativeEvent. Hook it.
|
|
// Ref: https://github.com/facebook/react/blob/master/packages/react-dom/src/test-utils/ReactTestUtils.js#L360
|
|
nativeEventProto.ctrlKey = true;
|
|
|
|
wrapper.find(TreeNode).find('.ant-tree-node-content-wrapper').at(1).simulate('click');
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
delete nativeEventProto.ctrlKey;
|
|
nativeEventProto.shiftKey = true;
|
|
|
|
wrapper.find(TreeNode).find('.ant-tree-node-content-wrapper').at(4).simulate('click');
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
delete nativeEventProto.shiftKey;
|
|
});
|
|
});
|