2018-01-04 20:43:56 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2017-11-19 01:41:40 +08:00
|
|
|
import Select from '..';
|
2018-11-15 14:43:54 +08:00
|
|
|
import Icon from '../../icon';
|
2017-11-19 01:41:40 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
|
|
|
|
2018-08-25 23:41:30 +08:00
|
|
|
const { Option } = Select;
|
|
|
|
|
2017-11-19 01:41:40 +08:00
|
|
|
describe('Select', () => {
|
|
|
|
focusTest(Select);
|
2018-01-04 20:43:56 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have default notFoundContent', () => {
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<Select mode="multiple" />);
|
2018-01-04 20:43:56 +08:00
|
|
|
wrapper.find('.ant-select').simulate('click');
|
|
|
|
jest.runAllTimers();
|
2018-12-07 20:02:01 +08:00
|
|
|
const dropdownWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
2018-01-04 20:43:56 +08:00
|
|
|
expect(dropdownWrapper.find('MenuItem').length).toBe(1);
|
2018-12-07 20:02:01 +08:00
|
|
|
expect(
|
|
|
|
dropdownWrapper
|
|
|
|
.find('MenuItem')
|
|
|
|
.at(0)
|
|
|
|
.text(),
|
|
|
|
).toBe('Not Found');
|
2018-01-04 20:43:56 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should support set notFoundContent to null', () => {
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<Select mode="multiple" notFoundContent={null} />);
|
2018-01-04 20:43:56 +08:00
|
|
|
wrapper.find('.ant-select').simulate('click');
|
|
|
|
jest.runAllTimers();
|
2018-12-07 20:02:01 +08:00
|
|
|
const dropdownWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
2018-01-04 20:43:56 +08:00
|
|
|
expect(dropdownWrapper.find('MenuItem').length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not have default notFoundContent when mode is combobox', () => {
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} />);
|
2018-01-04 20:43:56 +08:00
|
|
|
wrapper.find('.ant-select').simulate('click');
|
|
|
|
jest.runAllTimers();
|
2018-12-07 20:02:01 +08:00
|
|
|
const dropdownWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
2018-01-04 20:43:56 +08:00
|
|
|
expect(dropdownWrapper.find('MenuItem').length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not have notFoundContent when mode is combobox and notFoundContent is set', () => {
|
|
|
|
const wrapper = mount(
|
2018-12-07 20:02:01 +08:00
|
|
|
<Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} notFoundContent="not at all" />,
|
2018-01-04 20:43:56 +08:00
|
|
|
);
|
|
|
|
wrapper.find('.ant-select').simulate('click');
|
|
|
|
jest.runAllTimers();
|
2018-12-07 20:02:01 +08:00
|
|
|
const dropdownWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
2018-01-04 20:43:56 +08:00
|
|
|
expect(dropdownWrapper.find('MenuItem').length).toBe(1);
|
2018-12-07 20:02:01 +08:00
|
|
|
expect(
|
|
|
|
dropdownWrapper
|
|
|
|
.find('MenuItem')
|
|
|
|
.at(0)
|
|
|
|
.text(),
|
|
|
|
).toBe('not at all');
|
2018-01-04 20:43:56 +08:00
|
|
|
});
|
2018-08-25 23:41:30 +08:00
|
|
|
|
|
|
|
it('should be controlled by open prop', () => {
|
|
|
|
const onDropdownVisibleChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Select open onDropdownVisibleChange={onDropdownVisibleChange}>
|
|
|
|
<Option value="1">1</Option>
|
2018-12-07 20:02:01 +08:00
|
|
|
</Select>,
|
|
|
|
);
|
|
|
|
let dropdownWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
2018-08-25 23:41:30 +08:00
|
|
|
);
|
|
|
|
expect(dropdownWrapper.props().visible).toBe(true);
|
|
|
|
wrapper.find('.ant-select').simulate('click');
|
|
|
|
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(false);
|
|
|
|
expect(dropdownWrapper.props().visible).toBe(true);
|
|
|
|
|
|
|
|
wrapper.setProps({ open: false });
|
2018-12-07 20:02:01 +08:00
|
|
|
dropdownWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
2018-08-25 23:41:30 +08:00
|
|
|
expect(dropdownWrapper.props().visible).toBe(false);
|
|
|
|
wrapper.find('.ant-select').simulate('click');
|
|
|
|
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(true);
|
|
|
|
expect(dropdownWrapper.props().visible).toBe(false);
|
|
|
|
});
|
2018-11-12 12:18:21 +08:00
|
|
|
|
|
|
|
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>
|
2018-12-07 20:02:01 +08:00
|
|
|
</Select>,
|
2018-11-12 12:18:21 +08:00
|
|
|
);
|
|
|
|
wrapper.setProps({ count: 10 });
|
|
|
|
jest.runAllTimers();
|
2018-11-20 17:26:08 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2018-11-12 12:18:21 +08:00
|
|
|
});
|
|
|
|
});
|
2017-11-19 01:41:40 +08:00
|
|
|
});
|