2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2023-01-05 10:37:35 +08:00
|
|
|
import type { KeyWiseTransferItem } from '..';
|
2022-09-08 23:47:22 +08:00
|
|
|
import type { TransferListProps } from '../list';
|
2023-01-05 10:37:35 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2022-06-22 14:57:09 +08:00
|
|
|
import List from '../list';
|
2016-12-16 17:59:52 +08:00
|
|
|
|
2023-01-05 10:37:35 +08:00
|
|
|
const listCommonProps: TransferListProps<KeyWiseTransferItem> = {
|
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',
|
2023-01-05 10:37:35 +08:00
|
|
|
} as TransferListProps<KeyWiseTransferItem>;
|
2016-12-16 17:59:52 +08:00
|
|
|
|
2023-01-05 10:37:35 +08:00
|
|
|
const listProps: TransferListProps<KeyWiseTransferItem> = {
|
2022-10-22 15:00:26 +08:00
|
|
|
...listCommonProps,
|
2023-01-05 10:37:35 +08:00
|
|
|
dataSource: undefined as unknown as KeyWiseTransferItem[],
|
2022-10-22 15:00:26 +08:00
|
|
|
};
|
|
|
|
|
2023-01-08 15:35:28 +08:00
|
|
|
const emptyListProps: TransferListProps<KeyWiseTransferItem> = {
|
|
|
|
...listCommonProps,
|
|
|
|
dataSource: [],
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2022-10-22 15:00:26 +08:00
|
|
|
it('should render correctly when dataSource is not exists', () => {
|
|
|
|
expect(() => {
|
|
|
|
render(<List {...listProps} />);
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
2023-01-08 15:35:28 +08:00
|
|
|
|
|
|
|
it('Checkbox should disabled when dataSource is empty', () => {
|
|
|
|
const { container } = render(<List {...emptyListProps} />);
|
|
|
|
expect(container.querySelector<HTMLLabelElement>('label.ant-checkbox-wrapper')).toHaveClass(
|
|
|
|
'ant-checkbox-wrapper-disabled',
|
|
|
|
);
|
|
|
|
expect(container.querySelector<HTMLSpanElement>('span.ant-checkbox')).toHaveClass(
|
|
|
|
'ant-checkbox-disabled',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Checkbox should not disabled when dataSource not is empty', () => {
|
|
|
|
const { container } = render(<List {...listCommonProps} />);
|
|
|
|
expect(container.querySelector<HTMLLabelElement>('label.ant-checkbox-wrapper')).not.toHaveClass(
|
|
|
|
'ant-checkbox-wrapper-disabled',
|
|
|
|
);
|
|
|
|
expect(container.querySelector<HTMLSpanElement>('span.ant-checkbox')).not.toHaveClass(
|
|
|
|
'ant-checkbox-disabled',
|
|
|
|
);
|
|
|
|
});
|
2023-07-25 14:05:52 +08:00
|
|
|
|
|
|
|
it('support custom dropdown Icon', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<List
|
|
|
|
{...listCommonProps}
|
|
|
|
selectionsIcon={<span className="test-dropdown-icon">test</span>}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
container?.querySelector<HTMLSpanElement>(
|
|
|
|
'.ant-transfer-list .ant-transfer-list-header .test-dropdown-icon',
|
|
|
|
),
|
|
|
|
).toBeTruthy();
|
|
|
|
});
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|