import React from 'react';
import { mount } from 'enzyme';
import AutoComplete from '..';
import Input from '../../input';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
describe('AutoComplete', () => {
mountTest(AutoComplete);
rtlTest(AutoComplete);
it('AutoComplete with custom Input render perfectly', () => {
const wrapper = mount(
,
);
expect(wrapper.find('textarea').length).toBe(1);
wrapper.find('textarea').simulate('change', { target: { value: '123' } });
// should not filter data source defaultly
expect(wrapper.find('.ant-select-item-option').length).toBe(3);
});
it('AutoComplete should work when dataSource is object array', () => {
const wrapper = mount(
,
);
expect(wrapper.find('input').length).toBe(1);
wrapper.find('input').simulate('change', { target: { value: 'a' } });
// should not filter data source defaultly
expect(wrapper.find('.ant-select-item-option').length).toBe(2);
});
it('AutoComplete throws error when contains invalid dataSource', () => {
jest.spyOn(console, 'error').mockImplementation(() => undefined);
expect(() => {
mount(
{}]}>
,
);
}).toThrow();
// eslint-disable-next-line no-console
console.error.mockRestore();
});
it('legacy dataSource should accept react element option', () => {
const wrapper = mount(ReactNode]} />);
expect(wrapper.render()).toMatchSnapshot();
});
it('legacy AutoComplete.Option should be compatiable', () => {
const wrapper = mount(
111
222
,
);
expect(wrapper.find('input').length).toBe(1);
wrapper.find('input').simulate('change', { target: { value: '1' } });
expect(wrapper.find('.ant-select-item-option').length).toBe(2);
});
it('should not warning when getInputElement is null', () => {
jest.spyOn(console, 'warn').mockImplementation(() => undefined);
mount();
// eslint-disable-next-line no-console
expect(console.warn).not.toBeCalled();
// eslint-disable-next-line no-console
console.warn.mockRestore();
});
it('should not override custom input className', () => {
const wrapper = mount(
,
);
expect(wrapper.find('input').hasClass('custom')).toBe(true);
});
});