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(
clear}
removeIcon={remove}
value={['leaf1', 'leaf2']}
placeholder="Please select"
multiple
allowClear
treeDefaultExpandAll
>
,
);
expect(container.firstChild).toMatchSnapshot();
});
it('should `treeIcon` work', () => {
const { container } = render(
Bamboo} />
,
);
expect(container.firstChild).toMatchSnapshot();
});
});
it('should support notFoundContent', () => {
const content = 'notFoundContent';
const { container } = render();
expect(container.querySelector('.ant-select-empty')?.innerHTML).toBe(content);
});
it('legacy dropdownClassName', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render();
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();
expect(errSpy).toHaveBeenCalledWith(
'Warning: [antd: TreeSelect] `dropdownMatchSelectWidth` is deprecated. Please use `popupMatchSelectWidth` instead.',
);
errSpy.mockRestore();
});
it('support aria-*', async () => {
const { container } = render(
,
);
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();
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();
});
});