2016-12-16 17:59:52 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { render, mount } from 'enzyme';
|
|
|
|
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
|
|
|
lazy: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('List', () => {
|
|
|
|
it('should render correctly', () => {
|
|
|
|
const wrapper = render(<List {...listCommonProps} />);
|
2017-04-02 18:09:23 +08:00
|
|
|
expect(wrapper).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']} />);
|
2018-12-07 16:17:45 +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);
|
|
|
|
expect(handleFilter).toBeCalled();
|
|
|
|
});
|
2016-12-16 17:59:52 +08:00
|
|
|
});
|