ant-design/components/transfer/__tests__/list.test.tsx

47 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-06-22 14:57:09 +08:00
import React from 'react';
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';
2022-09-08 23:47:22 +08:00
const listCommonProps: TransferListProps<any> = {
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
],
checkedKeys: ['a'],
notFoundContent: 'Not Found',
2022-09-08 23:47:22 +08:00
} as TransferListProps<any>;
describe('Transfer.List', () => {
it('should render correctly', () => {
const { container } = render(<List {...listCommonProps} />);
expect(container.firstChild).toMatchSnapshot();
});
it('should check top Checkbox while all available items are checked', () => {
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,
).toBeTruthy();
});
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);
expect(handleFilter).toHaveBeenCalled();
2019-03-04 11:19:16 +08:00
});
});