import React from 'react';
import { mount } from 'enzyme';
import Tree from '../index';
const { TreeNode } = Tree;
describe('Tree', () => {
it('icon and switcherIcon of Tree with showLine should render correctly', () => {
const wrapper = mount(
,
);
expect(wrapper.render()).toMatchSnapshot();
});
it('switcherIcon in Tree should not render at leaf nodes', () => {
const wrapper = mount(
} defaultExpandAll>
,
);
expect(wrapper.find('.switcherIcon').length).toBe(1);
});
it('switcherIcon in Tree could be string', () => {
const wrapper = mount(
,
);
expect(wrapper.render()).toMatchSnapshot();
});
it('switcherIcon should be loading icon when loadData', () => {
const onLoadData = () =>
new Promise(resolve => {
setTimeout(() => {
resolve();
}, 1000);
});
const wrapper = mount(
,
);
expect(wrapper.render()).toMatchSnapshot();
});
it('switcherIcon in Tree could be render prop function', () => {
const wrapper = mount(
expanded ? :
}
defaultExpandAll
>
,
);
expect(wrapper.find('.open').length).toBe(1);
});
// https://github.com/ant-design/ant-design/issues/23261
it('showLine is object type should render correctly', () => {
const wrapper = mount(
,
);
expect(wrapper.render()).toMatchSnapshot();
});
describe('draggable', () => {
const dragTreeData = [
{
title: 'bamboo',
key: 'bamboo',
},
];
it('hide icon', () => {
const wrapper = mount();
expect(wrapper.exists('.anticon-holder')).toBeFalsy();
});
it('customize icon', () => {
const wrapper = mount(
}} />,
);
expect(wrapper.exists('.little')).toBeTruthy();
});
it('nodeDraggable', () => {
const nodeDraggable = jest.fn(() => false);
mount();
expect(nodeDraggable).toHaveBeenCalledWith(dragTreeData[0]);
});
it('nodeDraggable func', () => {
const nodeDraggable = jest.fn(() => false);
mount();
expect(nodeDraggable).toHaveBeenCalledWith(dragTreeData[0]);
});
});
});