ant-design-vue/components/input/__tests__/Search.test.js

135 lines
4.5 KiB
JavaScript
Raw Normal View History

2019-01-12 11:33:27 +08:00
import { mount } from '@vue/test-utils';
import { asyncExpect } from '@/tests/utils';
import Input from '../index';
import Button from '../../button';
import focusTest from '../../../tests/shared/focusTest';
2019-01-12 11:33:27 +08:00
const { Search } = Input;
describe('Input.Search', () => {
2019-01-12 11:33:27 +08:00
focusTest(Search);
it('should support custom button', async () => {
2019-01-12 11:33:27 +08:00
const wrapper = mount(
{
render() {
return <Search enterButton={<button type="button">ok</button>} />;
},
},
2019-01-12 11:33:27 +08:00
{ sync: false },
);
await asyncExpect(() => {
2019-01-12 11:33:27 +08:00
expect(wrapper.html()).toMatchSnapshot();
});
});
it('should support custom Button', async () => {
2019-01-12 11:33:27 +08:00
const wrapper = mount(
{
render() {
return <Search enterButton={<Button>ok</Button>} />;
},
},
2019-01-12 11:33:27 +08:00
{ sync: false },
);
await asyncExpect(() => {
2019-01-12 11:33:27 +08:00
expect(wrapper.html()).toMatchSnapshot();
});
});
2018-12-13 21:26:21 +08:00
it('should support ReactNode suffix without error', () => {
const fn = () => {
mount({
2019-01-12 11:33:27 +08:00
render() {
return <Search suffix={<div>ok</div>} />;
2018-12-13 21:26:21 +08:00
},
2019-01-12 11:33:27 +08:00
});
};
expect(fn).not.toThrow();
});
2018-12-09 11:43:27 +08:00
it('should disable enter button when disabled prop is true', () => {
const wrapper = mount({
2019-01-12 11:33:27 +08:00
render() {
return <Search placeholder="input search text" enterButton disabled />;
2018-12-09 11:43:27 +08:00
},
2019-01-12 11:33:27 +08:00
});
expect(wrapper.findAll('.ant-btn-primary[disabled]')).toHaveLength(1);
});
2018-12-09 11:43:27 +08:00
// it('should trigger onSearch when click search icon', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" onSearch={onSearch} />
// );
// wrapper.find('.anticon-search').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button with text', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton="button text" onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button with customize button', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton={<Button>antd button</Button>} onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button of native', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton={<button type="button">antd button</button>} onSearch={onSearch} />
// );
// wrapper.find('button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when press enter', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" onSearch={onSearch} />
// );
// wrapper.find('input').simulate('keydown', { key: 'Enter', keyCode: 13 });
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'keydown',
// preventDefault: expect.any(Function),
// }));
// });
2019-01-12 11:33:27 +08:00
});