mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
eac30ec8e4
* feat: remove warnings for linkRender, nameRender in Breadcrumb * feat: remove warnings for onOpen, onClose in Menu * feat: remove warnings for overlay in Popover * feat: remove warnings for columnsPageRange, columnsPageSize in Table * feat: remove warnings for afterClose in Tag * feat: remove warnings for notFoundContent, searchPlaceholder, body, onSearchChange in Transfer * fix: types in Transfer * feat: update test cases in Transfer * feat: add additional test cases for removed deprecated apis
89 lines
1.9 KiB
JavaScript
89 lines
1.9 KiB
JavaScript
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
import Search from '../search';
|
|
import Transfer from '../index';
|
|
|
|
describe('Transfer.Search', () => {
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
afterEach(() => {
|
|
errorSpy.mockReset();
|
|
});
|
|
|
|
afterAll(() => {
|
|
errorSpy.mockRestore();
|
|
});
|
|
|
|
it('should show cross icon when input value exists', () => {
|
|
const wrapper = mount(<Search value="" />);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
wrapper.setProps({ value: 'a' });
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('onSearch', () => {
|
|
const dataSource = [
|
|
{
|
|
key: 'a',
|
|
title: 'a',
|
|
description: 'a',
|
|
},
|
|
{
|
|
key: 'b',
|
|
title: 'b',
|
|
description: 'b',
|
|
},
|
|
{
|
|
key: 'c',
|
|
title: 'c',
|
|
description: 'c',
|
|
},
|
|
];
|
|
|
|
const onSearch = jest.fn();
|
|
const wrapper = mount(
|
|
<Transfer
|
|
dataSource={dataSource}
|
|
selectedKeys={[]}
|
|
targetKeys={[]}
|
|
render={item => item.title}
|
|
onSearch={onSearch}
|
|
showSearch
|
|
/>,
|
|
);
|
|
|
|
wrapper
|
|
.find('.ant-input')
|
|
.at(0)
|
|
.simulate('change', { target: { value: 'a' } });
|
|
expect(onSearch).toHaveBeenCalledWith('left', 'a');
|
|
|
|
onSearch.mockReset();
|
|
|
|
wrapper
|
|
.find('.ant-transfer-list-search-action')
|
|
.at(0)
|
|
.simulate('click');
|
|
expect(onSearch).toHaveBeenCalledWith('left', '');
|
|
});
|
|
|
|
it('legacy props#onSearchChange doesnot work anymore', () => {
|
|
const onSearchChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
<Transfer render={item => item.title} onSearchChange={onSearchChange} showSearch />,
|
|
);
|
|
|
|
wrapper
|
|
.find('.ant-input')
|
|
.at(0)
|
|
.simulate('change', { target: { value: 'a' } });
|
|
|
|
expect(errorSpy.mock.calls.length).toBe(0);
|
|
expect(onSearchChange).not.toHaveBeenCalled();
|
|
});
|
|
});
|