mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
543b620dd2
* clean up * refactor select all logic * omit old api to render children * add search * remove useless code * fix logic * Table demo * update demo * fixed min-height * fix normal style * style update * update snapshot * update snapshot * update version * update doc * update md desc * update test case * fix test typo * update demo * update snapshot * typescript correction * update docs * add Tree Transfer demo * default expand all * update demo
92 lines
2.0 KiB
JavaScript
92 lines
2.0 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 onSearchChange', () => {
|
|
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[0][0]).toMatch(
|
|
'Warning: [antd: Transfer] `onSearchChange` is deprecated. Please use `onSearch` instead.',
|
|
);
|
|
expect(onSearchChange.mock.calls[0][0]).toEqual('left');
|
|
expect(onSearchChange.mock.calls[0][1].target.value).toEqual('a');
|
|
});
|
|
});
|