2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2022-08-23 11:57:50 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2019-09-23 18:49:13 +08:00
|
|
|
import TreeSelect, { TreeNode } from '..';
|
2017-11-19 01:41:40 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2017-11-19 01:41:40 +08:00
|
|
|
|
|
|
|
describe('TreeSelect', () => {
|
2020-11-08 15:27:30 +08:00
|
|
|
focusTest(TreeSelect, { refFocus: true });
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(TreeSelect);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(TreeSelect);
|
2019-05-06 12:04:39 +08:00
|
|
|
|
2019-09-23 18:49:13 +08:00
|
|
|
describe('TreeSelect Custom Icons', () => {
|
|
|
|
it('should support customized icons', () => {
|
2022-08-23 11:57:50 +08:00
|
|
|
const { container } = render(
|
2019-09-23 18:49:13 +08:00
|
|
|
<TreeSelect
|
|
|
|
showSearch
|
|
|
|
clearIcon={<span>clear</span>}
|
|
|
|
removeIcon={<span>remove</span>}
|
|
|
|
value={['leaf1', 'leaf2']}
|
|
|
|
placeholder="Please select"
|
|
|
|
multiple
|
|
|
|
allowClear
|
|
|
|
treeDefaultExpandAll
|
|
|
|
>
|
|
|
|
<TreeNode value="parent 1" title="parent 1" key="0-1">
|
|
|
|
<TreeNode value="parent 1-0" title="parent 1-0" key="0-1-1">
|
|
|
|
<TreeNode value="leaf1" title="my leaf" key="random" />
|
|
|
|
<TreeNode value="leaf2" title="your leaf" key="random1" />
|
|
|
|
</TreeNode>
|
|
|
|
</TreeNode>
|
|
|
|
</TreeSelect>,
|
|
|
|
);
|
|
|
|
|
2022-08-23 11:57:50 +08:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-09-23 18:49:13 +08:00
|
|
|
});
|
2020-03-20 16:03:13 +08:00
|
|
|
|
|
|
|
it('should `treeIcon` work', () => {
|
2022-08-23 11:57:50 +08:00
|
|
|
const { container } = render(
|
2020-03-20 16:03:13 +08:00
|
|
|
<TreeSelect treeIcon open>
|
|
|
|
<TreeNode value="parent 1" title="parent 1" icon={<span>Bamboo</span>} />
|
|
|
|
</TreeSelect>,
|
|
|
|
);
|
|
|
|
|
2022-08-23 11:57:50 +08:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2020-03-20 16:03:13 +08:00
|
|
|
});
|
2019-09-23 18:49:13 +08:00
|
|
|
});
|
2020-08-26 16:42:47 +08:00
|
|
|
|
|
|
|
it('should support notFoundContent', () => {
|
2022-08-23 11:57:50 +08:00
|
|
|
const content = 'notFoundContent';
|
|
|
|
const { container } = render(<TreeSelect treeIcon open notFoundContent={content} />);
|
|
|
|
expect(container.querySelector('.ant-select-empty')?.innerHTML).toBe(content);
|
2020-08-26 16:42:47 +08:00
|
|
|
});
|
2022-08-05 11:21:07 +08:00
|
|
|
|
|
|
|
it('should show warning when use dropdownClassName', () => {
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2022-08-24 15:52:24 +08:00
|
|
|
render(<TreeSelect dropdownClassName="myCustomClassName" />);
|
2022-08-05 11:21:07 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: TreeSelect] `dropdownClassName` is deprecated which will be removed in next major version. Please use `popupClassName` instead.',
|
|
|
|
);
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
2017-11-19 01:41:40 +08:00
|
|
|
});
|