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

58 lines
1.5 KiB
JavaScript
Raw Normal View History

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,
},
],
checkedKeys: ['a'],
notFoundContent: 'Not Found',
lazy: false,
};
describe('List', () => {
it('should render correctly', () => {
const wrapper = render(<List {...listCommonProps} />);
2017-04-02 18:09:23 +08:00
expect(wrapper).toMatchSnapshot();
});
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();
});
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();
});
});