2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2022-09-08 21:55:23 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2022-09-08 23:47:22 +08:00
|
|
|
import type { TransferListProps } from '../list';
|
2022-06-22 14:57:09 +08:00
|
|
|
import List from '../list';
|
2016-12-16 17:59:52 +08:00
|
|
|
|
2022-09-08 23:47:22 +08:00
|
|
|
const listCommonProps: TransferListProps<any> = {
|
2016-12-16 17:59:52 +08:00
|
|
|
prefixCls: 'ant-transfer-list',
|
2018-12-07 16:17:45 +08:00
|
|
|
dataSource: [
|
2022-09-08 23:47:22 +08:00
|
|
|
{ key: 'a', title: 'a' },
|
|
|
|
{ key: 'b', title: 'b' },
|
|
|
|
{ key: 'c', title: 'c', disabled: true },
|
2018-12-07 16:17:45 +08:00
|
|
|
],
|
2016-12-16 17:59:52 +08:00
|
|
|
checkedKeys: ['a'],
|
2017-03-17 15:23:25 +08:00
|
|
|
notFoundContent: 'Not Found',
|
2022-09-08 23:47:22 +08:00
|
|
|
} as TransferListProps<any>;
|
2016-12-16 17:59:52 +08:00
|
|
|
|
2019-05-07 17:10:42 +08:00
|
|
|
describe('Transfer.List', () => {
|
2016-12-16 17:59:52 +08:00
|
|
|
it('should render correctly', () => {
|
2022-09-08 21:55:23 +08:00
|
|
|
const { container } = render(<List {...listCommonProps} />);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should check top Checkbox while all available items are checked', () => {
|
2022-09-08 21:55:23 +08:00
|
|
|
const { container } = render(<List {...listCommonProps} checkedKeys={['a', 'b']} />);
|
|
|
|
expect(
|
2022-09-08 23:47:22 +08:00
|
|
|
container.querySelector<HTMLInputElement>('.ant-transfer-list-header input[type="checkbox"]')
|
|
|
|
?.checked,
|
2022-09-08 21:55:23 +08:00
|
|
|
).toBeTruthy();
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|
2019-03-04 11:19:16 +08:00
|
|
|
|
|
|
|
it('when component has been unmounted, componentWillUnmount should be called', () => {
|
2022-09-08 23:47:22 +08:00
|
|
|
const instance = React.createRef<any>();
|
|
|
|
const { unmount } = render(<List ref={instance} {...listCommonProps} />);
|
|
|
|
const willUnmount = jest.spyOn(instance.current, 'componentWillUnmount');
|
|
|
|
unmount();
|
2019-03-04 11:19:16 +08:00
|
|
|
expect(willUnmount).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when value is not exists, handleFilter should return', () => {
|
|
|
|
const handleFilter = jest.fn();
|
2022-09-08 23:47:22 +08:00
|
|
|
const instance = React.createRef<any>();
|
|
|
|
render(<List ref={instance} {...listCommonProps} handleFilter={handleFilter} />);
|
|
|
|
expect(instance.current?.handleFilter({ target: 'test' })).toBe(undefined);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handleFilter).toHaveBeenCalled();
|
2019-03-04 11:19:16 +08:00
|
|
|
});
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|