mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 01:19:45 +08:00
338ec7dad7
* pref: better code style for production * refactor `devWarning` * don't use `useEffect` only wrap `devWarning` * chore: add 'noop' to coverage * chore: add test cases for devWarning * chore: add test case * chore: update test cases for devWarning * chore: restore test script command * fix: remove 'throw new Error' * should not use `throw` for browser * chore: update test case for AutoComplete * perf: add prefix for `devWarning` * update RegExp for UMD * add prefix for ES and CJS * chore: better code style * perf: * upgrade antd-tools * remove `injectWarningCondition` * rename `devWarning` to `warning` * chore: better code style * chore: better code style * chore: restore hasValidName
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
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(
|
|
<AutoComplete dataSource={['12345', '23456', '34567']}>
|
|
<textarea />
|
|
</AutoComplete>,
|
|
);
|
|
|
|
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(
|
|
<AutoComplete
|
|
dataSource={[
|
|
{ text: 'text', value: 'value' },
|
|
{ text: 'abc', value: 'xxx' },
|
|
]}
|
|
>
|
|
<input />
|
|
</AutoComplete>,
|
|
);
|
|
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', () => {
|
|
const spy = jest.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
|
|
mount(
|
|
<AutoComplete dataSource={[() => {}]}>
|
|
<textarea />
|
|
</AutoComplete>,
|
|
);
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
});
|
|
|
|
it('legacy dataSource should accept react element option', () => {
|
|
const wrapper = mount(<AutoComplete open dataSource={[<span key="key">ReactNode</span>]} />);
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
});
|
|
|
|
it('legacy AutoComplete.Option should be compatiable', () => {
|
|
const wrapper = mount(
|
|
<AutoComplete>
|
|
<AutoComplete.Option value="111">111</AutoComplete.Option>
|
|
<AutoComplete.Option value="222">222</AutoComplete.Option>
|
|
</AutoComplete>,
|
|
);
|
|
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(<AutoComplete placeholder="input here" allowClear />);
|
|
// 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(
|
|
<AutoComplete>
|
|
<Input className="custom" />
|
|
</AutoComplete>,
|
|
);
|
|
expect(wrapper.find('input').hasClass('custom')).toBe(true);
|
|
});
|
|
});
|