2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2022-04-18 21:02:11 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2022-10-22 18:43:36 +08:00
|
|
|
import type { TransferProps } from '../index';
|
2019-05-07 17:10:42 +08:00
|
|
|
import Transfer from '../index';
|
|
|
|
|
|
|
|
describe('Transfer.Customize', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2019-05-07 17:10:42 +08:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
errorSpy.mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
|
|
|
|
2020-05-13 19:15:40 +08:00
|
|
|
it('props#body does not work anymore', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const body = jest.fn();
|
2022-10-22 18:43:36 +08:00
|
|
|
const props = { body } as TransferProps<any>;
|
2022-09-08 23:47:22 +08:00
|
|
|
render(<Transfer {...props} />);
|
2022-04-06 11:07:15 +08:00
|
|
|
expect(errorSpy).not.toHaveBeenCalled();
|
2019-07-09 11:46:21 +08:00
|
|
|
expect(body).not.toHaveBeenCalled();
|
2019-05-07 17:10:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('deprecated function', () => {
|
2022-09-08 23:47:22 +08:00
|
|
|
const dataSource: Record<'key', string>[] = [];
|
2019-05-07 17:10:42 +08:00
|
|
|
for (let i = 0; i < 10; i += 1) {
|
2022-09-08 23:47:22 +08:00
|
|
|
dataSource.push({ key: i.toString() });
|
2019-05-07 17:10:42 +08:00
|
|
|
}
|
|
|
|
const commonProps = {
|
|
|
|
dataSource,
|
|
|
|
selectedKeys: ['1'],
|
|
|
|
targetKeys: ['2'],
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should not exist in render props', () => {
|
2022-09-08 21:55:23 +08:00
|
|
|
render(
|
2019-05-07 17:10:42 +08:00
|
|
|
<Transfer {...commonProps}>
|
2022-11-19 13:47:33 +08:00
|
|
|
{(props) => {
|
2019-05-07 17:10:42 +08:00
|
|
|
expect('handleFilter' in props).toBeFalsy();
|
|
|
|
expect('handleSelect' in props).toBeFalsy();
|
|
|
|
expect('handleSelectAll' in props).toBeFalsy();
|
|
|
|
expect('handleClear' in props).toBeFalsy();
|
|
|
|
expect('body' in props).toBeFalsy();
|
|
|
|
expect('checkedKeys' in props).toBeFalsy();
|
2022-09-08 23:47:22 +08:00
|
|
|
return null;
|
2019-05-07 17:10:42 +08:00
|
|
|
}}
|
|
|
|
</Transfer>,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-05-13 19:15:40 +08:00
|
|
|
|
|
|
|
it('warning if use `pagination`', () => {
|
2022-09-08 21:55:23 +08:00
|
|
|
render(
|
2020-05-13 19:15:40 +08:00
|
|
|
<Transfer dataSource={[]} pagination>
|
|
|
|
{() => null}
|
|
|
|
</Transfer>,
|
|
|
|
);
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: Transfer] `pagination` not support customize render list.',
|
|
|
|
);
|
|
|
|
});
|
2019-05-07 17:10:42 +08:00
|
|
|
});
|