mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 00:29:12 +08:00
851d551906
* chore: warning for dropdownMatchSelectWidth * test: update snapshot * test: update test case * fix: align context * chore: warning deprecated * chore: fix lint
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import React from 'react';
|
|
import TreeSelect, { TreeNode } from '..';
|
|
import focusTest from '../../../tests/shared/focusTest';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
import { render } from '../../../tests/utils';
|
|
import { resetWarned } from '../../_util/warning';
|
|
|
|
describe('TreeSelect', () => {
|
|
focusTest(TreeSelect, { refFocus: true });
|
|
mountTest(TreeSelect);
|
|
rtlTest(TreeSelect);
|
|
|
|
describe('TreeSelect Custom Icons', () => {
|
|
it('should support customized icons', () => {
|
|
const { container } = render(
|
|
<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>,
|
|
);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('should `treeIcon` work', () => {
|
|
const { container } = render(
|
|
<TreeSelect treeIcon open>
|
|
<TreeNode value="parent 1" title="parent 1" icon={<span>Bamboo</span>} />
|
|
</TreeSelect>,
|
|
);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
it('should support notFoundContent', () => {
|
|
const content = 'notFoundContent';
|
|
const { container } = render(<TreeSelect treeIcon open notFoundContent={content} />);
|
|
expect(container.querySelector('.ant-select-empty')?.innerHTML).toBe(content);
|
|
});
|
|
|
|
it('legacy dropdownClassName', () => {
|
|
resetWarned();
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
const { container } = render(<TreeSelect dropdownClassName="legacy" open />);
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
'Warning: [antd: TreeSelect] `dropdownClassName` is deprecated. Please use `popupClassName` instead.',
|
|
);
|
|
expect(container.querySelector('.legacy')).toBeTruthy();
|
|
|
|
errSpy.mockRestore();
|
|
});
|
|
|
|
it('warning for legacy dropdownMatchSelectWidth', () => {
|
|
resetWarned();
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
render(<TreeSelect dropdownMatchSelectWidth open />);
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
'Warning: [antd: Select] `dropdownMatchSelectWidth` is deprecated. Please use `popupMatchSelectWidth` instead.',
|
|
);
|
|
|
|
errSpy.mockRestore();
|
|
});
|
|
});
|