ant-design/components/transfer/__tests__/search.test.js
afc163 9c17f94cab
feat: Table filterMode and filterSearch functions (#31809)
* feat: Table supports filterMode="tree-select"

* add tree component

* fix detail

* use tree

* add @table-filter-dropdown-max-height

* feat: add check all to filter tree

* feat: add search

* feat: use filterTreeNode

* fix code style

* fix style

* style: tree node selected bg

* fix demo

* feat: add filterSearch

* fix: clear search value after close filter dropdown

* update snapshot

* code style

* fix test case

* chore: new FilterDropdown.tsx file

* chore: searchValueMatched function

* add test case

* test: add test cases

* feat: reset only works on dropdown state now

* chore: add table locales

* fix search input width

* tweak style

* style: update transfer search input style

* perf: improve table perf

* fix: filterMuiltiple={false}

* test: add test for selecting

* chore: fix table filter selection

* fix lint

* remove unused code

* fix: style dependencies

* test: turn off bail config for duplidated-package-plugin in feature branch

* Update components/table/hooks/useFilter/FilterSearch.tsx

Co-authored-by: Peach <scdzwyxst@gmail.com>

* fix locale link

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Peach <scdzwyxst@gmail.com>
2021-09-01 10:49:52 +08:00

93 lines
2.3 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(() => {});
const dataSource = [
{
key: 'a',
title: 'a',
description: 'a',
},
{
key: 'b',
title: 'b',
description: 'b',
},
{
key: 'c',
title: 'c',
description: 'c',
},
];
afterEach(() => {
errorSpy.mockReset();
});
afterAll(() => {
errorSpy.mockRestore();
});
it('should show cross icon when input value exists', () => {
const wrapper = mount(<Search value="" />);
expect(wrapper).toMatchRenderedSnapshot();
wrapper.setProps({ value: 'a' });
expect(wrapper).toMatchRenderedSnapshot();
});
it('onSearch', () => {
jest.useFakeTimers();
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-input-clear-icon').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();
});
// https://github.com/ant-design/ant-design/issues/26208
it('typing space should trigger filterOption', () => {
const filterOption = jest.fn();
const wrapper = mount(
<Transfer filterOption={filterOption} dataSource={dataSource} showSearch />,
);
wrapper
.find('.ant-input')
.at(0)
.simulate('change', { target: { value: ' ' } });
expect(filterOption).toHaveBeenCalledTimes(dataSource.length);
});
});