ant-design/components/transfer/__tests__/index.test.js

596 lines
18 KiB
JavaScript
Raw Normal View History

/* eslint @typescript-eslint/no-use-before-define: "off" */
import { fireEvent, render, waitFor } from '@testing-library/react';
// import { mount } from 'enzyme';
2022-06-22 14:57:09 +08:00
import React, { useState } from 'react';
import Transfer from '..';
2019-08-26 22:53:20 +08:00
import mountTest from '../../../tests/shared/mountTest';
feat: added rtl direction to all of ant-design components (#19380) * rtl demo change en-us description * change bundlesize css limit * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * fix pagination.tsx compile error * RTL: button and button-group * RTL: Steps component * fix rtl demo style * fix input suffix icon alignment * fix select component arrow issue * RTL: form component * add pagination rtl test * fix test lint error * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * some fixes to RTL components * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * fix switch component text rtl issue * fix table grouped header text-align * add rtl support to whole demo with RTL button * Update rtl demo responsive * RTL: page-header component * RTL: typography component * RTL: Dropdown (Partial) * update config-provider doc * RTL: input component * RTL: select component * RTL: switch component * RTL: tree component * fix rtl demo lint * rtl demo change en-us description * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * RTL: button and button-group * RTL: Steps component * fix rtl demo style * fix input suffix icon alignment * RTL: form component * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * add rtl support to whole demo with RTL button * fix lost changes after rebase * fix lint errors * RTL: Transfer Component * RTL: upload component * RTL: update avatar demo * RTL: comment component * RTL: collapse component * RTL: carousel component * update snapshots * RTL: Card component * RTL: descriptions component * RTL: Empty component * RTL: list component * RTL: slider component * slider component import/order * add shared rtlTest * RTL: Statistic component * RTL: tooltip components * RTL: popover component * RTL: timeline component * RTL: tag component * RTL: alert component * RTL: drawer component * RTL: Tab component * change direction definition * RTL: progress component * input.tsx, remove duplicate after rebase * fix demo.less after rebase * fix ant-row-rtl after rebase * fix upload issues in rtl * badge rtl demo margin fix * fix: tabs with icon margin * fix: radio-wrapper margin * fix: table component after rebase * fix: centered modal text-align * update slider snapshot * RTL: popconfirm component * RTL: back-top component * RTL: spin component * RTL: result component * RTL: skeleton component * RTL: menu component * RTL: time-picker component * RTL: calendar component * RTL: date-picker component * RTL: home page * update snapshots * test: add auto-complete rtl test * test: add avatar component rtl tests * test: add badge component rtl tests * test: add breadcrumb component rtl tests * test: add button components rtl tests * test: add card component rtl tests * test: add carousel component rtl tests * test: add cascader component rtl tests * test: add checkbox component rtl tests * test: add collapse component rtl tests * test: add comment component rtl tests * test: add dropdown component rtl tests * test: add empty component rtl tests * test: add form component rtl tests * test: add grid component rtl tests * test: add input component rtl tests * test: add search component rtl tests * test: add input-number component rtl tests * test: add layout component rtl tests * test: add list component rtl tests * test: add mentions component rtl tests * test: add modal component rtl tests * test: add page-header component rtl tests * test: add pagination component rtl tests * test: add radio component rtl tests * test: add rate component rtl tests * test: add select component rtl tests * test: add slider component rtl tests * test: add steps component rtl tests * test: add switch component rtl tests * test: add table component rtl tests * test: add transfer component rtl tests * test: add tree component rtl tests * test: add tree-select component rtl tests * test: add typography component rtl tests * test: add upload component rtl tests * test: add affix component rtl tests * update calendar tests * increase css file maxSize * update snapshots * remove workflows to allow push * remove duplicate reverse prop from slider * fix: remove table demo from config-provider * fix: remove table demo from config-provider * fix lint error * Added direction property to ConfigProvider * cascader rtl tests added * update config-provider doc * RTL: grid system * RTL: input component * RTL: switch component * fix rtl demo lint * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * fix pagination.tsx compile error * RTL: button and button-group * RTL: Steps component * fix rtl demo style * RTL: form component * add pagination rtl test * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * add rtl support to whole demo with RTL button * RTL: input component * RTL: select component * RTL: switch component * RTL: tree component * fix rtl demo lint * rtl demo change en-us description * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * RTL: button and button-group * RTL: Steps component * fix rtl demo style * fix input suffix icon alignment * RTL: form component * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * add rtl support to whole demo with RTL button * input.tsx, remove duplicate after rebase * fix ant-row-rtl after rebase * update snapshots * test: add cascader component rtl tests * test: add pagination component rtl tests * update calendar tests * update snapshots * fix: remove table demo from config-provider * fix: remove table demo from config-provider * fix lint error * update direction.md icons * dropdown and cascader default placement in rtl * update snapshots * fix lint errors * remove duplicate import * update snapshots * update snapshot * update calendar snapshot * update snapshots * integrate with new rc-picker * update snapshots * fix lint errors * update snapshot * update snapshots * update snapshots * update snapshots :| * update snapshots * fix compile error. * fix typo after rebase * update snapshots * remove workflows to allow push * update snapshots * update snapshots * fix dist error * front-page css fix * update snapshots * fix lint and test issues * restore cascader index.less * update snapshots * fix logo in rtl and demo controls * ci errors * resolve steps/index.tsx conflicts * tooltip family demo remove inline style * resolve table/Table.tsx conflicts * resolve modal/Modal.tsx conflicts * resolve cascader/index.tsx conflicts * add workflows from upstream * update snapshots * revert logo to default * fix codebox demo direction of placements * resolve tooltip overlayClassName conflicts * update snapshots * update popover test * fix: cascader miss popupClassName * fix: fix select missing dropdownClassName * chore: Update snapshot * chore: Adjust menu use rtl logic * docs: Update demo line color Co-authored-by: 二货机器人 <smith3816@gmail.com>
2020-01-02 19:10:16 +08:00
import rtlTest from '../../../tests/shared/rtlTest';
2018-09-19 15:05:55 +08:00
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const listCommonProps = {
2018-12-07 16:17:45 +08:00
dataSource: [
{
key: 'a',
title: 'a',
},
{
key: 'b',
title: 'b',
},
{
key: 'c',
title: 'c',
disabled: true,
},
],
selectedKeys: ['a'],
targetKeys: ['b'],
};
const listDisabledProps = {
2018-12-07 16:17:45 +08:00
dataSource: [
{
key: 'a',
title: 'a',
disabled: true,
},
{
key: 'b',
title: 'b',
},
],
selectedKeys: ['a', 'b'],
targetKeys: [],
};
const searchTransferProps = {
dataSource: [
{
key: '0',
title: 'content1',
description: 'description of content1',
chosen: false,
},
{
key: '1',
title: 'content2',
description: 'description of content2',
chosen: false,
},
{
key: '2',
title: 'content3',
description: 'description of content3',
chosen: false,
},
{
key: '3',
title: 'content4',
description: 'description of content4',
chosen: false,
},
{
key: '4',
title: 'content5',
description: 'description of content5',
chosen: false,
},
{
key: '5',
title: 'content6',
description: 'description of content6',
chosen: false,
},
],
selectedKeys: [],
targetKeys: ['3', '4'],
};
describe('Transfer', () => {
2019-08-26 22:53:20 +08:00
mountTest(Transfer);
feat: added rtl direction to all of ant-design components (#19380) * rtl demo change en-us description * change bundlesize css limit * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * fix pagination.tsx compile error * RTL: button and button-group * RTL: Steps component * fix rtl demo style * fix input suffix icon alignment * fix select component arrow issue * RTL: form component * add pagination rtl test * fix test lint error * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * some fixes to RTL components * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * fix switch component text rtl issue * fix table grouped header text-align * add rtl support to whole demo with RTL button * Update rtl demo responsive * RTL: page-header component * RTL: typography component * RTL: Dropdown (Partial) * update config-provider doc * RTL: input component * RTL: select component * RTL: switch component * RTL: tree component * fix rtl demo lint * rtl demo change en-us description * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * RTL: button and button-group * RTL: Steps component * fix rtl demo style * fix input suffix icon alignment * RTL: form component * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * add rtl support to whole demo with RTL button * fix lost changes after rebase * fix lint errors * RTL: Transfer Component * RTL: upload component * RTL: update avatar demo * RTL: comment component * RTL: collapse component * RTL: carousel component * update snapshots * RTL: Card component * RTL: descriptions component * RTL: Empty component * RTL: list component * RTL: slider component * slider component import/order * add shared rtlTest * RTL: Statistic component * RTL: tooltip components * RTL: popover component * RTL: timeline component * RTL: tag component * RTL: alert component * RTL: drawer component * RTL: Tab component * change direction definition * RTL: progress component * input.tsx, remove duplicate after rebase * fix demo.less after rebase * fix ant-row-rtl after rebase * fix upload issues in rtl * badge rtl demo margin fix * fix: tabs with icon margin * fix: radio-wrapper margin * fix: table component after rebase * fix: centered modal text-align * update slider snapshot * RTL: popconfirm component * RTL: back-top component * RTL: spin component * RTL: result component * RTL: skeleton component * RTL: menu component * RTL: time-picker component * RTL: calendar component * RTL: date-picker component * RTL: home page * update snapshots * test: add auto-complete rtl test * test: add avatar component rtl tests * test: add badge component rtl tests * test: add breadcrumb component rtl tests * test: add button components rtl tests * test: add card component rtl tests * test: add carousel component rtl tests * test: add cascader component rtl tests * test: add checkbox component rtl tests * test: add collapse component rtl tests * test: add comment component rtl tests * test: add dropdown component rtl tests * test: add empty component rtl tests * test: add form component rtl tests * test: add grid component rtl tests * test: add input component rtl tests * test: add search component rtl tests * test: add input-number component rtl tests * test: add layout component rtl tests * test: add list component rtl tests * test: add mentions component rtl tests * test: add modal component rtl tests * test: add page-header component rtl tests * test: add pagination component rtl tests * test: add radio component rtl tests * test: add rate component rtl tests * test: add select component rtl tests * test: add slider component rtl tests * test: add steps component rtl tests * test: add switch component rtl tests * test: add table component rtl tests * test: add transfer component rtl tests * test: add tree component rtl tests * test: add tree-select component rtl tests * test: add typography component rtl tests * test: add upload component rtl tests * test: add affix component rtl tests * update calendar tests * increase css file maxSize * update snapshots * remove workflows to allow push * remove duplicate reverse prop from slider * fix: remove table demo from config-provider * fix: remove table demo from config-provider * fix lint error * Added direction property to ConfigProvider * cascader rtl tests added * update config-provider doc * RTL: grid system * RTL: input component * RTL: switch component * fix rtl demo lint * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * fix pagination.tsx compile error * RTL: button and button-group * RTL: Steps component * fix rtl demo style * RTL: form component * add pagination rtl test * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * add rtl support to whole demo with RTL button * RTL: input component * RTL: select component * RTL: switch component * RTL: tree component * fix rtl demo lint * rtl demo change en-us description * RTL: modal component (exclude confirm) * RTL: table component * RTL: pagination component * cleanup rtl demo * RTL: button and button-group * RTL: Steps component * fix rtl demo style * fix input suffix icon alignment * RTL: form component * RTL: rate component * RTL: radio and radio group components * RTL: tree-select component * RTL: badge component * fix rtl issue in inline form * fix input component rtl padding issue * add rtl support to whole demo with RTL button * input.tsx, remove duplicate after rebase * fix ant-row-rtl after rebase * update snapshots * test: add cascader component rtl tests * test: add pagination component rtl tests * update calendar tests * update snapshots * fix: remove table demo from config-provider * fix: remove table demo from config-provider * fix lint error * update direction.md icons * dropdown and cascader default placement in rtl * update snapshots * fix lint errors * remove duplicate import * update snapshots * update snapshot * update calendar snapshot * update snapshots * integrate with new rc-picker * update snapshots * fix lint errors * update snapshot * update snapshots * update snapshots * update snapshots :| * update snapshots * fix compile error. * fix typo after rebase * update snapshots * remove workflows to allow push * update snapshots * update snapshots * fix dist error * front-page css fix * update snapshots * fix lint and test issues * restore cascader index.less * update snapshots * fix logo in rtl and demo controls * ci errors * resolve steps/index.tsx conflicts * tooltip family demo remove inline style * resolve table/Table.tsx conflicts * resolve modal/Modal.tsx conflicts * resolve cascader/index.tsx conflicts * add workflows from upstream * update snapshots * revert logo to default * fix codebox demo direction of placements * resolve tooltip overlayClassName conflicts * update snapshots * update popover test * fix: cascader miss popupClassName * fix: fix select missing dropdownClassName * chore: Update snapshot * chore: Adjust menu use rtl logic * docs: Update demo line color Co-authored-by: 二货机器人 <smith3816@gmail.com>
2020-01-02 19:10:16 +08:00
rtlTest(Transfer);
2019-08-26 22:53:20 +08:00
it('should render correctly', () => {
const wrapper = render(<Transfer {...listCommonProps} />);
expect(wrapper.container.firstChild).toMatchSnapshot();
});
it('should move selected keys to corresponding list', () => {
const handleChange = jest.fn();
const { container } = render(<Transfer {...listCommonProps} onChange={handleChange} />);
fireEvent.click(container.querySelector('.ant-transfer-operation').querySelector('button')); // move selected keys to right list
expect(handleChange).toHaveBeenCalledWith(['a', 'b'], 'right', ['a']);
});
it('should move selected keys to left list', () => {
const handleChange = jest.fn();
const { container } = render(
<Transfer
{...listCommonProps}
selectedKeys={['a']}
targetKeys={['a']}
onChange={handleChange}
2019-09-26 22:28:08 +08:00
/>,
);
fireEvent.click(
container.querySelector('.ant-transfer-operation').querySelectorAll('button')[1],
); // move selected keys to left list
expect(handleChange).toHaveBeenCalledWith([], 'left', ['a']);
});
it('should move selected keys expect disabled to corresponding list', () => {
const handleChange = jest.fn();
const { container } = render(<Transfer {...listDisabledProps} onChange={handleChange} />);
fireEvent.click(container.querySelector('.ant-transfer-operation').querySelector('button')); // move selected keys to right list
expect(handleChange).toHaveBeenCalledWith(['b'], 'right', ['b']);
});
it('should uncheck checkbox when click on checked item', () => {
const handleSelectChange = jest.fn();
const { getByTitle } = render(
<Transfer
{...listCommonProps}
onSelectChange={handleSelectChange}
render={item => item.title}
/>,
);
getByTitle('a').click();
expect(handleSelectChange).toHaveBeenLastCalledWith([], []);
});
it('should check checkbox when click on unchecked item', () => {
const handleSelectChange = jest.fn();
const { getByText } = render(
<Transfer
{...listCommonProps}
onSelectChange={handleSelectChange}
render={item => item.title}
/>,
);
getByText('b').click();
expect(handleSelectChange).toHaveBeenLastCalledWith(['a'], ['b']);
});
it('should not check checkbox when component disabled', () => {
const handleSelectChange = jest.fn();
const { getByText } = render(
<Transfer
{...listCommonProps}
disabled
onSelectChange={handleSelectChange}
render={item => item.title}
/>,
);
getByText('a').click();
expect(handleSelectChange).not.toHaveBeenCalled();
});
it('should not check checkbox when click on disabled item', () => {
const handleSelectChange = jest.fn();
const { getByText } = render(
<Transfer
{...listCommonProps}
onSelectChange={handleSelectChange}
render={item => item.title}
/>,
);
getByText('c').click();
expect(handleSelectChange).not.toHaveBeenCalled();
});
it('should check all item when click on check all', () => {
const handleSelectChange = jest.fn();
const { container } = render(
<Transfer {...listCommonProps} onSelectChange={handleSelectChange} />,
);
fireEvent.click(
container
.querySelectorAll('.ant-transfer-list-header')
.item(1)
.querySelector('input[type="checkbox"]'),
);
expect(handleSelectChange).toHaveBeenCalledWith(['a'], ['b']);
});
it('should uncheck all item when click on uncheck all', () => {
const handleSelectChange = jest.fn();
const { container } = render(
<Transfer {...listCommonProps} onSelectChange={handleSelectChange} />,
);
fireEvent.click(
container
.querySelectorAll('.ant-transfer-list-header')
.item(0)
.querySelector('input[type="checkbox"]'),
);
expect(handleSelectChange).toHaveBeenCalledWith([], []);
});
it('should call `filterOption` when use input in search box', () => {
const filterOption = (inputValue, option) => inputValue === option.title;
const { container } = render(
<Transfer
{...listCommonProps}
showSearch
filterOption={filterOption}
render={item => item.title}
/>,
);
fireEvent.change(
container.querySelectorAll('.ant-transfer-list').item(0).querySelector('input[type="text"]'),
{ target: { value: 'a' } },
);
expect(
container
.querySelectorAll('.ant-transfer-list')
.item(0)
.querySelectorAll('.ant-transfer-list-content input[type="checkbox"]'),
).toHaveLength(1);
});
it('should display the correct count of items when filter by input', () => {
const filterOption = (inputValue, option) => option.description.indexOf(inputValue) > -1;
const renderFunc = item => item.title;
const { container, getByText } = render(
<Transfer
{...searchTransferProps}
showSearch
filterOption={filterOption}
render={renderFunc}
2018-12-07 16:17:45 +08:00
/>,
);
fireEvent.change(
container.querySelectorAll('.ant-transfer-list').item(0).querySelector('input[type="text"]'),
{ target: { value: 'content2' } },
);
expect(getByText('1 item')).toBeTruthy();
});
it('should display the correct locale', () => {
const emptyProps = { dataSource: [], selectedKeys: [], targetKeys: [] };
const locale = { itemUnit: 'Person', notFoundContent: 'Nothing', searchPlaceholder: 'Search' };
const { getAllByText, getAllByPlaceholderText } = render(
2018-12-07 16:17:45 +08:00
<Transfer {...listCommonProps} {...emptyProps} showSearch locale={locale} />,
2018-11-28 15:00:03 +08:00
);
expect(getAllByText('0 Person')).toHaveLength(2);
expect(getAllByPlaceholderText('Search')).toHaveLength(2);
expect(getAllByText('Nothing')).toHaveLength(2);
});
it('should display the correct locale and ignore old API', () => {
const emptyProps = { dataSource: [], selectedKeys: [], targetKeys: [] };
const locale = { notFoundContent: 'old1', searchPlaceholder: 'old2' };
const newLocalProp = { notFoundContent: 'new1', searchPlaceholder: 'new2' };
const { getAllByPlaceholderText, getAllByText } = render(
<Transfer
{...listCommonProps}
{...emptyProps}
{...locale}
locale={newLocalProp}
showSearch
/>,
);
expect(getAllByPlaceholderText('new2')).toHaveLength(2);
expect(getAllByText('new1')).toHaveLength(2);
2018-09-19 15:05:55 +08:00
expect(consoleErrorSpy).not.toHaveBeenCalledWith(
'Warning: [antd: Transfer] `notFoundContent` and `searchPlaceholder` will be removed, please use `locale` instead.',
2018-09-19 15:05:55 +08:00
);
consoleErrorSpy.mockRestore();
});
it('should display the correct items unit', () => {
const { getByText } = render(
<Transfer {...listCommonProps} locale={{ itemsUnit: 'People' }} />,
);
expect(getByText('1/2 People')).toBeTruthy();
});
it('should display the correct notFoundContent', () => {
const { getByText } = render(
<Transfer dataSource={[]} locale={{ notFoundContent: ['No Source', 'No Target'] }} />,
);
expect(getByText('No Source')).toBeTruthy();
expect(getByText('No Target')).toBeTruthy();
});
it('should just check the filtered item when click on check all after search by input', () => {
const filterOption = (inputValue, option) => option.description.indexOf(inputValue) > -1;
const renderFunc = item => item.title;
const handleSelectChange = jest.fn();
const { container, getByTitle } = render(
<Transfer
{...searchTransferProps}
showSearch
filterOption={filterOption}
render={renderFunc}
onSelectChange={handleSelectChange}
2018-12-07 16:17:45 +08:00
/>,
);
fireEvent.change(
container.querySelectorAll('.ant-transfer-list').item(0).querySelector('input[type="text"]'),
{ target: { value: 'content2' } },
);
getByTitle('content2').click();
expect(handleSelectChange).toHaveBeenCalledWith(['1'], []);
});
it('should transfer just the filtered item after search by input', () => {
const filterOption = (inputValue, option) => option.description.indexOf(inputValue) > -1;
const renderFunc = item => item.title;
const handleChange = jest.fn();
const TransferDemo = () => {
const [selectedKeys, setSelectedKeys] = useState(searchTransferProps.selectedKeys);
const handleSelectChange = (sourceSelectedKeys, targetSelectedKeys) => {
setSelectedKeys([...sourceSelectedKeys, ...targetSelectedKeys]);
};
return (
<Transfer
{...searchTransferProps}
showSearch
filterOption={filterOption}
render={renderFunc}
onSelectChange={handleSelectChange}
onChange={handleChange}
selectedKeys={selectedKeys}
/>
);
};
const { container } = render(<TransferDemo />);
fireEvent.change(container.querySelector('.ant-transfer-list-search').querySelector('input'), {
target: { value: 'content2' },
});
fireEvent.click(
container
.querySelector('.ant-transfer-list')
.querySelector('.ant-transfer-list-header input[type="checkbox"]'),
);
fireEvent.click(container.querySelector('.ant-transfer-operation').querySelector('button'));
expect(handleChange).toHaveBeenCalledWith(['1', '3', '4'], 'right', ['1']);
});
it('should check correctly when there is a search text', () => {
const newProps = { ...listCommonProps };
delete newProps.targetKeys;
delete newProps.selectedKeys;
const handleSelectChange = jest.fn();
const { container, getByText } = render(
2018-11-28 15:00:03 +08:00
<Transfer
{...newProps}
showSearch
onSelectChange={handleSelectChange}
render={item => item.title}
2018-12-07 16:17:45 +08:00
/>,
);
getByText('b').click();
expect(handleSelectChange).toHaveBeenLastCalledWith(['b'], []);
fireEvent.change(
container.querySelectorAll('.ant-transfer-list').item(0).querySelector('input[type="text"]'),
{ target: { value: 'a' } },
);
fireEvent.click(
container
.querySelectorAll('.ant-transfer-list')
.item(0)
.querySelector('.ant-transfer-list-header input[type="checkbox"]'),
);
expect(handleSelectChange).toHaveBeenLastCalledWith(['b', 'a'], []);
fireEvent.click(
container
.querySelectorAll('.ant-transfer-list')
.item(0)
.querySelector('.ant-transfer-list-header input[type="checkbox"]'),
);
expect(handleSelectChange).toHaveBeenLastCalledWith(['b'], []);
});
it('should show sorted targetKey', () => {
const sortedTargetKeyProps = {
2018-12-07 16:17:45 +08:00
dataSource: [
{
key: 'a',
title: 'a',
},
{
key: 'b',
title: 'b',
},
{
key: 'c',
title: 'c',
},
],
targetKeys: ['c', 'b'],
lazy: false,
};
const { container } = render(
<Transfer {...sortedTargetKeyProps} render={item => item.title} />,
);
expect(container.firstChild).toMatchSnapshot();
});
it('should add custom styles when their props are provided', () => {
const style = {
backgroundColor: 'red',
};
const leftStyle = {
backgroundColor: 'blue',
};
const rightStyle = {
backgroundColor: 'red',
};
const operationStyle = {
backgroundColor: 'yellow',
};
const { container } = render(
2018-11-28 15:00:03 +08:00
<Transfer
{...listCommonProps}
style={style}
listStyle={({ direction }) => (direction === 'left' ? leftStyle : rightStyle)}
2018-11-28 15:00:03 +08:00
operationStyle={operationStyle}
2018-12-07 16:17:45 +08:00
/>,
2018-11-28 15:00:03 +08:00
);
const wrapper = container.querySelector('.ant-transfer');
const listSource = container.querySelectorAll('.ant-transfer-list').item(0);
const listTarget = container.querySelectorAll('.ant-transfer-list').item(1);
const operation = container.querySelectorAll('.ant-transfer-operation').item(0);
expect(wrapper.style.backgroundColor).toEqual('red');
expect(listSource.style.backgroundColor).toEqual('blue');
expect(listTarget.style.backgroundColor).toEqual('red');
expect(operation.style.backgroundColor).toEqual('yellow');
});
it('should support onScroll', () => {
const onScroll = jest.fn();
const { container } = render(<Transfer {...listCommonProps} onScroll={onScroll} />);
fireEvent.scroll(
container
.querySelectorAll('.ant-transfer-list')
.item(0)
.querySelectorAll('.ant-transfer-list-content')
.item(0),
);
expect(onScroll).toHaveBeenLastCalledWith('left', expect.anything());
fireEvent.scroll(
container
.querySelectorAll('.ant-transfer-list')
.item(1)
.querySelectorAll('.ant-transfer-list-content')
.item(0),
);
expect(onScroll).toHaveBeenLastCalledWith('right', expect.anything());
});
it('should support rowKey is function', () => {
expect(() => {
render(<Transfer {...listCommonProps} rowKey={record => record.key} />);
}).not.toThrow();
});
it('should support render value and label in item', () => {
const { container } = render(
<Transfer
dataSource={[
{
key: 'a',
title: 'title',
},
]}
render={record => ({ value: `${record.title} value`, label: 'label' })}
/>,
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correct checkbox label when checkboxLabel is defined', () => {
const selectAllLabels = ['Checkbox Label'];
const { getByText } = render(
<Transfer {...listCommonProps} selectAllLabels={selectAllLabels} />,
);
expect(getByText('Checkbox Label')).toBeTruthy();
});
it('should render correct checkbox label when checkboxLabel is a function', () => {
const selectAllLabels = [
({ selectedCount, totalCount }) => (
<span>
{selectedCount} of {totalCount}
</span>
),
];
const { getByText } = render(
<Transfer {...listCommonProps} selectAllLabels={selectAllLabels} />,
);
expect(getByText('1 of 2')).toBeTruthy();
});
describe('pagination', () => {
it('boolean', async () => {
const { getByTitle } = render(<Transfer {...listDisabledProps} pagination />);
await waitFor(() => getByTitle('1/1'));
});
it('object', async () => {
const { container, getByTitle } = render(
<Transfer {...listDisabledProps} pagination={{ pageSize: 1 }} />,
);
expect(
container
.querySelectorAll('.ant-transfer-list')
.item(0)
.querySelectorAll('.ant-transfer-list-content-item'),
).toHaveLength(1);
await waitFor(() => getByTitle('1/2'));
});
it('not exceed max size', async () => {
const { container, getByTitle, getAllByTitle, rerender } = render(
<Transfer {...listDisabledProps} pagination={{ pageSize: 1 }} />,
);
fireEvent.click(container.querySelector('.ant-pagination-next .ant-pagination-item-link'));
await waitFor(() => getByTitle('2/2'));
rerender(
<Transfer
{...{ ...listDisabledProps, targetKeys: ['b', 'c'] }}
pagination={{ pageSize: 1 }}
/>,
);
await waitFor(() => expect(getAllByTitle('1/1')).toHaveLength(2));
});
});
it('remove by click icon', () => {
const onChange = jest.fn();
const { container } = render(<Transfer {...listCommonProps} onChange={onChange} oneWay />);
fireEvent.click(container.querySelectorAll('.ant-transfer-list-content-item-remove')[0]);
expect(onChange).toHaveBeenCalledWith([], 'left', ['b']);
});
});
chore: merge master into feature (#28751) * fix: Transfer dataSource cannot be immutable (#28675) close #28662 * docs: fix errors in example code (#28677) * ci: expand ie check (#28673) * ci: expand ie check * Update issue-open-check.yml * perf(📦): reduce @babel/runtime package size (#28678) * perf(📦): reduce @babel/runtime package size https://github.com/ant-design/antd-tools/commit/04cd73dea1206d1119847ffd7342b28b26d0babc * chore(:up:): upgrade @ant-design/react-slick to esm support version * upgrade @ant-design/tools * ci: add open condition (#28682) * fix(Slider): forcePopupAlign null when unmounted (#28699) * docs: Update overview.zh-CN.md (#28703) * docs: Update resources.en-US.md (#28701) * chore: bump rc-select to 12.1.0 (#28715) * fix: stylelint plugin (#28730) * Update package.json * perf(📦): upgrade rc-image to 5.x (#28727) * refactor: upgrade rc-image to 5.x reduce bundle size * upgrade rc-image * upgrade @ant-design/tools https://github.com/ant-design/antd-tools/pull/226 * rc-image 5.0.0 * fix image preview icon missing * refactor code * docs: example of synchronous rc-tree (#28648) * ci: fix outputs type 过程中的使用 string。奇怪啊,之前测试过的,今天点的时候发现不行了 * Update package.json * fix: site overflow cause sticky invalid (#28741) * fix: site overflow cause sticky invalid * disable auto scroll * chore: upgrade rc-dialog and rc-drawer (#28749) * chore: upgrade rc-dialog and rc-drawer (#28687) * chore: upgrade rc-dialog and rc-drawer * upgrade rc-util * update snapshots * upgrade rc-util * upgrade rc-util * update snapshots * upgrade rc-dialog * perf: remove duplicated rc-dialog Co-authored-by: 骗你是小猫咪 <darryshaw@gmail.com> Co-authored-by: bigbigbo <zxb141242@163.com> Co-authored-by: xrkffgg <xrkffgg@gmail.com> Co-authored-by: Yann Pringault <yann.pringault@gmail.com> Co-authored-by: godfather <greenday.wj@foxmail.com> Co-authored-by: Mateusz Wierzbicki <22788841+mateusz-wierzbicki@users.noreply.github.com> Co-authored-by: Kermit <kermitlx@outlook.com> Co-authored-by: AkiJoey <akijoey1010635951@gmail.com> Co-authored-by: qqabcv520 <605655316@qq.com> Co-authored-by: 骗你是小猫咪 <darryshaw@gmail.com>
2021-01-08 10:14:01 +08:00
describe('immutable data', () => {
// https://github.com/ant-design/ant-design/issues/28662
it('dataSource is frozen', () => {
const mockData = [
Object.freeze({
id: 0,
title: `title`,
description: `description`,
}),
];
const { container } = render(<Transfer rowKey={item => item.id} dataSource={mockData} />);
expect(container.firstChild).toMatchSnapshot();
chore: merge master into feature (#28751) * fix: Transfer dataSource cannot be immutable (#28675) close #28662 * docs: fix errors in example code (#28677) * ci: expand ie check (#28673) * ci: expand ie check * Update issue-open-check.yml * perf(📦): reduce @babel/runtime package size (#28678) * perf(📦): reduce @babel/runtime package size https://github.com/ant-design/antd-tools/commit/04cd73dea1206d1119847ffd7342b28b26d0babc * chore(:up:): upgrade @ant-design/react-slick to esm support version * upgrade @ant-design/tools * ci: add open condition (#28682) * fix(Slider): forcePopupAlign null when unmounted (#28699) * docs: Update overview.zh-CN.md (#28703) * docs: Update resources.en-US.md (#28701) * chore: bump rc-select to 12.1.0 (#28715) * fix: stylelint plugin (#28730) * Update package.json * perf(📦): upgrade rc-image to 5.x (#28727) * refactor: upgrade rc-image to 5.x reduce bundle size * upgrade rc-image * upgrade @ant-design/tools https://github.com/ant-design/antd-tools/pull/226 * rc-image 5.0.0 * fix image preview icon missing * refactor code * docs: example of synchronous rc-tree (#28648) * ci: fix outputs type 过程中的使用 string。奇怪啊,之前测试过的,今天点的时候发现不行了 * Update package.json * fix: site overflow cause sticky invalid (#28741) * fix: site overflow cause sticky invalid * disable auto scroll * chore: upgrade rc-dialog and rc-drawer (#28749) * chore: upgrade rc-dialog and rc-drawer (#28687) * chore: upgrade rc-dialog and rc-drawer * upgrade rc-util * update snapshots * upgrade rc-util * upgrade rc-util * update snapshots * upgrade rc-dialog * perf: remove duplicated rc-dialog Co-authored-by: 骗你是小猫咪 <darryshaw@gmail.com> Co-authored-by: bigbigbo <zxb141242@163.com> Co-authored-by: xrkffgg <xrkffgg@gmail.com> Co-authored-by: Yann Pringault <yann.pringault@gmail.com> Co-authored-by: godfather <greenday.wj@foxmail.com> Co-authored-by: Mateusz Wierzbicki <22788841+mateusz-wierzbicki@users.noreply.github.com> Co-authored-by: Kermit <kermitlx@outlook.com> Co-authored-by: AkiJoey <akijoey1010635951@gmail.com> Co-authored-by: qqabcv520 <605655316@qq.com> Co-authored-by: 骗你是小猫咪 <darryshaw@gmail.com>
2021-01-08 10:14:01 +08:00
});
});