mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 17:31:25 +08:00
8501b708ea
* 📦 samller bundlesize limit * 🗑️ remove React static PropTypes * 🗑️ remove react-lifecycles-compat * 🗑️ remove matchMedia polyfill * 🗑️ remove Transfer buggy lazy prop * 🗑️ remove enquire.js dep * 🗑️ remove Transfer lazy related code and fix ci * 🗑️ remove used dom-closest * ⚡ replace dom-scroll-into-view to scroll-into-view for bundle size * ✅ fix eslint * 🆙 upgrade browserslist * ✅ fix test cases * 🗑️ remove @ant-design/create-react-context * 🆙 upgrade @ant-design/bisheng-plugin * 🆙 upgrade rc-slider * ✅ fix ci * 🆙 upgrade rc-tabs and rc-mentions * 📦 scroll-into-view -> scroll-into-view-if-needed * remove unused devDep * docs: 📝 update instruction about IE9/10 * 📦 reduce css bundle size by drop IE9/10 support * 🆙 upgrade rc-upload * 🗑️ drop unused swing motion css * ✅ update upload snapshots * 📦 lift css bundlesize limit to 55kb
91 lines
1.9 KiB
JavaScript
91 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', () => {
|
|
jest.useFakeTimers();
|
|
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', '');
|
|
jest.useRealTimers();
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|