improve transfer test case

This commit is contained in:
zombiej 2020-05-23 16:47:49 +08:00
parent c54255a703
commit 973f55babb

View File

@ -72,39 +72,58 @@ describe('Transfer.Dropdown', () => {
jest.useRealTimers(); jest.useRealTimers();
}); });
it('select invert', () => { describe('select invert', () => {
jest.useFakeTimers(); [
{ name: 'with pagination', props: listProps, index: 2, keys: ['c', 'd'] },
{
name: 'without pagination',
props: { ...listProps, pagination: null },
index: 1,
keys: ['c', 'd', 'e'],
},
].forEach(({ name, props, index, keys }) => {
it(name, () => {
jest.useFakeTimers();
const onSelectChange = jest.fn(); const onSelectChange = jest.fn();
const wrapper = mount(<Transfer {...listProps} onSelectChange={onSelectChange} />); const wrapper = mount(<Transfer {...props} onSelectChange={onSelectChange} />);
wrapper.find('.ant-transfer-list-header-dropdown').first().simulate('mouseenter'); wrapper.find('.ant-transfer-list-header-dropdown').first().simulate('mouseenter');
act(() => { act(() => {
jest.runAllTimers(); jest.runAllTimers();
});
wrapper.update();
clickItem(wrapper.find('.ant-dropdown-menu').first(), index);
expect(onSelectChange).toHaveBeenCalledWith(keys, []);
jest.useRealTimers();
});
}); });
wrapper.update();
clickItem(wrapper.find('.ant-dropdown-menu').first(), 2);
expect(onSelectChange).toHaveBeenCalledWith(['c', 'd'], []);
jest.useRealTimers();
}); });
it('oneWay to remove', () => { describe('oneWay to remove', () => {
jest.useFakeTimers(); [
{ name: 'with pagination', props: listProps },
{ name: 'without pagination', props: { ...listProps, pagination: null } },
].forEach(({ name, props }) => {
it(name, () => {
jest.useFakeTimers();
const onChange = jest.fn(); const onChange = jest.fn();
const wrapper = mount( const wrapper = mount(
<Transfer {...listProps} targetKeys={['b', 'c']} oneWay onChange={onChange} />, <Transfer {...props} targetKeys={['b', 'c']} oneWay onChange={onChange} />,
); );
wrapper.find('.ant-transfer-list-header-dropdown').last().simulate('mouseenter'); wrapper.find('.ant-transfer-list-header-dropdown').last().simulate('mouseenter');
act(() => { act(() => {
jest.runAllTimers(); jest.runAllTimers();
});
wrapper.update();
clickItem(wrapper.find('.ant-dropdown-menu').first(), 0);
expect(onChange).toHaveBeenCalledWith([], 'left', ['b', 'c']);
jest.useRealTimers();
});
}); });
wrapper.update();
clickItem(wrapper.find('.ant-dropdown-menu').first(), 0);
expect(onChange).toHaveBeenCalledWith([], 'left', ['b', 'c']);
jest.useRealTimers();
}); });
}); });