2016-12-16 17:59:52 +08:00
|
|
|
import React from 'react';
|
2019-05-07 17:10:42 +08:00
|
|
|
import { mount } from 'enzyme';
|
2016-12-16 17:59:52 +08:00
|
|
|
import List from '../list';
|
|
|
|
import Checkbox from '../../checkbox';
|
|
|
|
|
|
|
|
const listCommonProps = {
|
|
|
|
prefixCls: 'ant-transfer-list',
|
2018-12-07 16:17:45 +08:00
|
|
|
dataSource: [
|
|
|
|
{
|
|
|
|
key: 'a',
|
|
|
|
title: 'a',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'b',
|
|
|
|
title: 'b',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'c',
|
|
|
|
title: 'c',
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
],
|
2016-12-16 17:59:52 +08:00
|
|
|
checkedKeys: ['a'],
|
2017-03-17 15:23:25 +08:00
|
|
|
notFoundContent: 'Not Found',
|
2016-12-16 17:59:52 +08:00
|
|
|
};
|
|
|
|
|
2019-05-07 17:10:42 +08:00
|
|
|
describe('Transfer.List', () => {
|
2016-12-16 17:59:52 +08:00
|
|
|
it('should render correctly', () => {
|
2019-05-07 17:10:42 +08:00
|
|
|
const wrapper = mount(<List {...listCommonProps} />);
|
|
|
|
wrapper.update();
|
2021-12-04 17:06:36 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should check top Checkbox while all available items are checked', () => {
|
|
|
|
const wrapper = mount(<List {...listCommonProps} checkedKeys={['a', 'b']} />);
|
2020-10-21 10:35:06 +08:00
|
|
|
expect(wrapper.find('.ant-transfer-list-header').find(Checkbox).prop('checked')).toBeTruthy();
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|
2019-03-04 11:19:16 +08:00
|
|
|
|
|
|
|
it('when component has been unmounted, componentWillUnmount should be called', () => {
|
|
|
|
const wrapper = mount(<List {...listCommonProps} />);
|
|
|
|
const willUnmount = jest.spyOn(wrapper.instance(), 'componentWillUnmount');
|
|
|
|
wrapper.unmount();
|
|
|
|
expect(willUnmount).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when value is not exists, handleFilter should return', () => {
|
|
|
|
const handleFilter = jest.fn();
|
|
|
|
const wrapper = mount(<List {...listCommonProps} handleFilter={handleFilter} />);
|
|
|
|
expect(wrapper.instance().handleFilter({ target: 'test' })).toBe(undefined);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handleFilter).toHaveBeenCalled();
|
2019-03-04 11:19:16 +08:00
|
|
|
});
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|