mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-30 12:28:33 +08:00
491a20ff58
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run
Co-authored-by: 二货机器人 <smith3816@gmail.com>
107 lines
3.6 KiB
TypeScript
107 lines
3.6 KiB
TypeScript
import React from 'react';
|
|
|
|
import TreeSelect, { TreeNode } from '..';
|
|
import { resetWarned } from '../../_util/warning';
|
|
import focusTest from '../../../tests/shared/focusTest';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
import { render } from '../../../tests/utils';
|
|
|
|
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 className="bamboo" />} />
|
|
</TreeSelect>,
|
|
);
|
|
|
|
expect(container.querySelector('.ant-select-tree-treenode .bamboo')).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
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: TreeSelect] `dropdownMatchSelectWidth` is deprecated. Please use `popupMatchSelectWidth` instead.',
|
|
);
|
|
|
|
errSpy.mockRestore();
|
|
});
|
|
|
|
it('support aria-*', async () => {
|
|
const { container } = render(
|
|
<TreeSelect
|
|
open
|
|
treeData={[{ value: 'parent 1', title: 'parnet 1', 'aria-label': 'label' }]}
|
|
/>,
|
|
);
|
|
expect(
|
|
container.querySelector('.ant-select-tree-treenode-leaf-last')?.getAttribute('aria-label'),
|
|
).toBe('label');
|
|
});
|
|
|
|
it('deprecate showArrow', () => {
|
|
resetWarned();
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
const { container } = render(<TreeSelect showArrow />);
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
'Warning: [antd: TreeSelect] `showArrow` is deprecated which will be removed in next major version. It will be a default behavior, you can hide it by setting `suffixIcon` to null.',
|
|
);
|
|
expect(container.querySelector('.ant-select-show-arrow')).toBeTruthy();
|
|
|
|
errSpy.mockRestore();
|
|
});
|
|
});
|