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

541 lines
16 KiB
JavaScript
Raw Normal View History

/* eslint no-use-before-define: "off" */
import React from 'react';
import { render, mount } from 'enzyme';
import Transfer from '..';
import TransferList from '../list';
import TransferOperation from '../operation';
import TransferSearch from '../search';
import TransferItem from '../ListItem';
import Button from '../../button';
import Checkbox from '../../checkbox';
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} />);
2017-04-02 18:09:23 +08:00
expect(wrapper).toMatchSnapshot();
});
it('should move selected keys to corresponding list', () => {
const handleChange = jest.fn();
const wrapper = mount(<Transfer {...listCommonProps} onChange={handleChange} />);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferOperation)
.find(Button)
.at(0)
.simulate('click'); // 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 wrapper = mount(
<Transfer
{...listCommonProps}
selectedKeys={['a']}
targetKeys={['a']}
onChange={handleChange}
2019-09-26 22:28:08 +08:00
/>,
);
wrapper
.find(TransferOperation)
.find(Button)
.at(1)
.simulate('click'); // 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 wrapper = mount(<Transfer {...listDisabledProps} onChange={handleChange} />);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferOperation)
.find(Button)
.at(0)
.simulate('click'); // 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 wrapper = mount(<Transfer {...listCommonProps} onSelectChange={handleSelectChange} />);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferItem)
.filterWhere(n => n.prop('item').key === 'a')
.simulate('click');
expect(handleSelectChange).toHaveBeenLastCalledWith([], []);
});
it('should check checkbox when click on unchecked item', () => {
const handleSelectChange = jest.fn();
const wrapper = mount(<Transfer {...listCommonProps} onSelectChange={handleSelectChange} />);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferItem)
.filterWhere(n => n.prop('item').key === 'b')
.simulate('click');
expect(handleSelectChange).toHaveBeenLastCalledWith(['a'], ['b']);
});
it('should not check checkbox when component disabled', () => {
const handleSelectChange = jest.fn();
const wrapper = mount(
<Transfer {...listCommonProps} disabled onSelectChange={handleSelectChange} />,
);
wrapper
.find(TransferItem)
.filterWhere(n => n.prop('item').key === 'a')
.simulate('click');
expect(handleSelectChange).not.toHaveBeenCalled();
});
it('should not check checkbox when click on disabled item', () => {
const handleSelectChange = jest.fn();
const wrapper = mount(<Transfer {...listCommonProps} onSelectChange={handleSelectChange} />);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferItem)
.filterWhere(n => n.prop('item').key === 'c')
.simulate('click');
expect(handleSelectChange).not.toHaveBeenCalled();
});
it('should check all item when click on check all', () => {
const handleSelectChange = jest.fn();
const wrapper = mount(<Transfer {...listCommonProps} onSelectChange={handleSelectChange} />);
2018-12-07 16:17:45 +08:00
wrapper
.find('.ant-transfer-list-header input[type="checkbox"]')
.filterWhere(n => !n.prop('checked'))
.simulate('change');
expect(handleSelectChange).toHaveBeenCalledWith(['a'], ['b']);
});
it('should uncheck all item when click on uncheck all', () => {
const handleSelectChange = jest.fn();
const wrapper = mount(<Transfer {...listCommonProps} onSelectChange={handleSelectChange} />);
2018-12-07 16:17:45 +08:00
wrapper
.find('.ant-transfer-list-header input[type="checkbox"]')
.filterWhere(n => n.prop('checked'))
.simulate('change');
expect(handleSelectChange).toHaveBeenCalledWith([], []);
});
it('should call `filterOption` when use input in search box', () => {
const filterOption = (inputValue, option) => inputValue === option.title;
const wrapper = mount(<Transfer {...listCommonProps} showSearch filterOption={filterOption} />);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferSearch)
.at(0)
.find('input')
.simulate('change', { target: { value: 'a' } });
expect(
wrapper
.find(TransferList)
.at(0)
.find(TransferItem)
.find(Checkbox),
).toHaveLength(1);
});
2018-12-07 16:17:45 +08:00
const headerText = wrapper =>
wrapper
.find(TransferList)
.at(0)
.find('.ant-transfer-list-header-selected > span')
.at(0)
.first()
.text()
.trim();
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 wrapper = mount(
<Transfer
{...searchTransferProps}
showSearch
filterOption={filterOption}
render={renderFunc}
2018-12-07 16:17:45 +08:00
/>,
);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferSearch)
.at(0)
.find('input')
.simulate('change', { target: { value: 'content2' } });
expect(headerText(wrapper)).toEqual('1 item');
});
it('should display the correct locale', () => {
const emptyProps = { dataSource: [], selectedKeys: [], targetKeys: [] };
const locale = { itemUnit: 'Person', notFoundContent: 'Nothing', searchPlaceholder: 'Search' };
2018-11-28 15:00:03 +08:00
const wrapper = mount(
2018-12-07 16:17:45 +08:00
<Transfer {...listCommonProps} {...emptyProps} showSearch locale={locale} />,
2018-11-28 15:00:03 +08:00
);
expect(headerText(wrapper)).toEqual('0 Person');
expect(
wrapper
2018-12-07 16:17:45 +08:00
.find(TransferList)
.at(0)
.find('.ant-transfer-list-search')
.at(0)
.prop('placeholder'),
).toEqual('Search');
expect(
wrapper
2018-12-07 16:17:45 +08:00
.find(TransferList)
.at(0)
.find('.ant-transfer-list-body-not-found')
.at(0)
.text(),
).toEqual('Nothing');
});
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 wrapper = mount(
<Transfer
{...listCommonProps}
{...emptyProps}
{...locale}
locale={newLocalProp}
showSearch
/>,
);
expect(
wrapper
2018-12-07 16:17:45 +08:00
.find(TransferList)
.at(0)
.find('.ant-transfer-list-search')
.at(0)
.prop('placeholder'),
).toEqual('new2');
expect(
wrapper
2018-12-07 16:17:45 +08:00
.find(TransferList)
.at(0)
.find('.ant-transfer-list-body-not-found')
.at(0)
.text(),
).toEqual('new1');
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 wrapper = mount(<Transfer {...listCommonProps} locale={{ itemsUnit: 'People' }} />);
expect(headerText(wrapper)).toEqual('1/2 People');
});
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 wrapper = mount(
<Transfer
{...searchTransferProps}
showSearch
filterOption={filterOption}
render={renderFunc}
onSelectChange={handleSelectChange}
2018-12-07 16:17:45 +08:00
/>,
);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferSearch)
.at(0)
.find('input')
.simulate('change', { target: { value: 'content2' } });
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferList)
.at(0)
.find('.ant-transfer-list-header input[type="checkbox"]')
.filterWhere(n => !n.prop('checked'))
.simulate('change');
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 handleSelectChange = (sourceSelectedKeys, targetSelectedKeys) => {
wrapper.setProps({
selectedKeys: [...sourceSelectedKeys, ...targetSelectedKeys],
});
};
const wrapper = mount(
<Transfer
{...searchTransferProps}
showSearch
filterOption={filterOption}
render={renderFunc}
onSelectChange={handleSelectChange}
onChange={handleChange}
2018-12-07 16:17:45 +08:00
/>,
);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferSearch)
.at(0)
.find('input')
.simulate('change', { target: { value: 'content2' } });
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferList)
.at(0)
.find('.ant-transfer-list-header input[type="checkbox"]')
.filterWhere(n => !n.prop('checked'))
.simulate('change');
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferOperation)
.find(Button)
.at(0)
.simulate('click');
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 wrapper = mount(
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
/>,
);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferItem)
.filterWhere(n => n.prop('item').key === 'b')
.simulate('click');
expect(handleSelectChange).toHaveBeenLastCalledWith(['b'], []);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferSearch)
.at(0)
.find('input')
.simulate('change', { target: { value: 'a' } });
wrapper
.find(TransferList)
.at(0)
.find('.ant-transfer-list-header input[type="checkbox"]')
.simulate('change');
expect(handleSelectChange).toHaveBeenLastCalledWith(['b', 'a'], []);
2018-12-07 16:17:45 +08:00
wrapper
.find(TransferList)
.at(0)
.find('.ant-transfer-list-header input[type="checkbox"]')
.simulate('change');
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 wrapper = render(<Transfer {...sortedTargetKeyProps} render={item => item.title} />);
expect(wrapper).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',
};
2018-11-28 15:00:03 +08:00
const component = mount(
<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 = component.find('.ant-transfer');
const listSource = component.find('.ant-transfer-list').first();
const listTarget = component.find('.ant-transfer-list').last();
const operation = component.find('.ant-transfer-operation').first();
expect(wrapper.prop('style')).toHaveProperty('backgroundColor', 'red');
expect(listSource.prop('style')).toHaveProperty('backgroundColor', 'blue');
expect(listTarget.prop('style')).toHaveProperty('backgroundColor', 'red');
expect(operation.prop('style')).toHaveProperty('backgroundColor', 'yellow');
});
it('should support onScroll', () => {
const onScroll = jest.fn();
2019-09-26 22:28:08 +08:00
const component = mount(<Transfer {...listCommonProps} onScroll={onScroll} />);
component
.find('.ant-transfer-list')
.at(0)
.find('.ant-transfer-list-content')
.at(0)
.simulate('scroll');
expect(onScroll).toHaveBeenLastCalledWith('left', expect.anything());
2019-09-26 22:28:08 +08:00
component
.find('.ant-transfer-list')
.at(1)
.find('.ant-transfer-list-content')
.at(0)
.simulate('scroll');
expect(onScroll).toHaveBeenLastCalledWith('right', expect.anything());
});
it('should support rowKey is function', () => {
expect(() => {
2019-09-26 22:28:08 +08:00
mount(<Transfer {...listCommonProps} rowKey={record => record.key} />);
}).not.toThrow();
});
it('should support render value and label in item', () => {
const component = mount(
<Transfer
dataSource={[
{
key: 'a',
title: 'title',
},
]}
render={record => ({ value: `${record.title} value`, label: 'label' })}
/>,
);
expect(component).toMatchSnapshot();
});
it('should render correct checkbox label when checkboxLabel is defined', () => {
const selectAllLabels = ['Checkbox Label'];
const wrapper = mount(<Transfer {...listCommonProps} selectAllLabels={selectAllLabels} />);
expect(headerText(wrapper)).toEqual('Checkbox Label');
});
it('should render correct checkbox label when checkboxLabel is a function', () => {
const selectAllLabels = [
({ selectedCount, totalCount }) => (
<span>
{selectedCount} of {totalCount}
</span>
),
];
const wrapper = mount(<Transfer {...listCommonProps} selectAllLabels={selectAllLabels} />);
expect(headerText(wrapper)).toEqual('1 of 2');
});
});