mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
2ea28af6ed
* init * fix firefox * add active style * adjust arrow style * update select * update icon logic * render empty * init multiple * fix ff display style * sync font size * adjust padding style * add padding * padding it * hotfix of chrome * single sm * multiple size * update option group style * update snapshot * clean up transition * rm combobox in ts define * auto complete init * fix auto option def * update demo * update demo * update uncertain demo * update demo * warning if user set `size` on AutoComplete * add debug demo * updat demo * update demo of disabled * update snapshot * rm useless test * fix pagination test * fix Table test * fix calendar test case * fix calendar test case * adjust style * add big data demo * support clean up * fix ts define * fix lint * fix demo lint * fix style lint fix * rm useless deps * update snapshot * stop mock * add space
141 lines
3.9 KiB
JavaScript
141 lines
3.9 KiB
JavaScript
import React from 'react';
|
|
import { act } from 'react-dom/test-utils';
|
|
import { mount } from 'enzyme';
|
|
import Select from '..';
|
|
import Icon from '../../icon';
|
|
import focusTest from '../../../tests/shared/focusTest';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
import { resetWarned } from '../../_util/warning';
|
|
|
|
const { Option } = Select;
|
|
|
|
describe('Select', () => {
|
|
focusTest(Select);
|
|
mountTest(Select);
|
|
|
|
function toggleOpen(wrapper) {
|
|
act(() => {
|
|
wrapper.find('.ant-select-selector').simulate('mousedown');
|
|
jest.runAllTimers();
|
|
wrapper.update();
|
|
});
|
|
}
|
|
|
|
beforeEach(() => {
|
|
jest.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.useRealTimers();
|
|
});
|
|
|
|
it('should have default notFoundContent', () => {
|
|
const wrapper = mount(<Select mode="multiple" />);
|
|
toggleOpen(wrapper);
|
|
expect(wrapper.find('.ant-select-item-option').length).toBeFalsy();
|
|
expect(wrapper.find('.ant-empty').length).toBeTruthy();
|
|
});
|
|
|
|
it('should support set notFoundContent to null', () => {
|
|
const wrapper = mount(<Select mode="multiple" notFoundContent={null} />);
|
|
toggleOpen(wrapper);
|
|
const dropdownWrapper = mount(
|
|
wrapper
|
|
.find('Trigger')
|
|
.instance()
|
|
.getComponent(),
|
|
);
|
|
expect(dropdownWrapper.find('MenuItem').length).toBe(0);
|
|
});
|
|
|
|
it('should not have default notFoundContent when mode is combobox', () => {
|
|
const wrapper = mount(<Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} />);
|
|
toggleOpen(wrapper);
|
|
const dropdownWrapper = mount(
|
|
wrapper
|
|
.find('Trigger')
|
|
.instance()
|
|
.getComponent(),
|
|
);
|
|
expect(dropdownWrapper.find('MenuItem').length).toBe(0);
|
|
});
|
|
|
|
it('should not have notFoundContent when mode is combobox and notFoundContent is set', () => {
|
|
const wrapper = mount(
|
|
<Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} notFoundContent="not at all" />,
|
|
);
|
|
toggleOpen(wrapper);
|
|
const dropdownWrapper = mount(
|
|
wrapper
|
|
.find('Trigger')
|
|
.instance()
|
|
.getComponent(),
|
|
);
|
|
expect(dropdownWrapper.find('.ant-select-item-option').length).toBeFalsy();
|
|
expect(
|
|
dropdownWrapper
|
|
.find('.ant-select-item-empty')
|
|
.at(0)
|
|
.text(),
|
|
).toBe('not at all');
|
|
});
|
|
|
|
it('should be controlled by open prop', () => {
|
|
const onDropdownVisibleChange = jest.fn();
|
|
const wrapper = mount(
|
|
<Select open onDropdownVisibleChange={onDropdownVisibleChange}>
|
|
<Option value="1">1</Option>
|
|
</Select>,
|
|
);
|
|
let dropdownWrapper = mount(
|
|
wrapper
|
|
.find('Trigger')
|
|
.instance()
|
|
.getComponent(),
|
|
);
|
|
expect(dropdownWrapper.props().visible).toBe(true);
|
|
toggleOpen(wrapper);
|
|
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(false);
|
|
expect(dropdownWrapper.props().visible).toBe(true);
|
|
|
|
wrapper.setProps({ open: false });
|
|
dropdownWrapper = mount(
|
|
wrapper
|
|
.find('Trigger')
|
|
.instance()
|
|
.getComponent(),
|
|
);
|
|
expect(dropdownWrapper.props().visible).toBe(false);
|
|
toggleOpen(wrapper);
|
|
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(true);
|
|
expect(dropdownWrapper.props().visible).toBe(false);
|
|
});
|
|
|
|
describe('Select Custom Icons', () => {
|
|
it('should support customized icons', () => {
|
|
const wrapper = mount(
|
|
<Select
|
|
removeIcon={<Icon type="close" />}
|
|
clearIcon={<Icon type="close" />}
|
|
menuItemSelectedIcon={<Icon type="close" />}
|
|
>
|
|
<Option value="1">1</Option>
|
|
</Select>,
|
|
);
|
|
wrapper.setProps({ count: 10 });
|
|
jest.runAllTimers();
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
it('not warning if user use `inputValue`', () => {
|
|
resetWarned();
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
mount(<Select inputValue="" />);
|
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
|
|
errorSpy.mockRestore();
|
|
});
|
|
});
|