Merge pull request #15293 from zy410419243/issue-14775

pref: lift up coverage rate
This commit is contained in:
偏右 2019-03-25 22:24:15 +08:00 committed by GitHub
commit cfa6e2654b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 253 additions and 4 deletions

View File

@ -1,8 +1,11 @@
import raf from 'raf';
import React from 'react';
import { mount } from 'enzyme';
import delayRaf from '../raf';
import throttleByAnimationFrame from '../throttleByAnimationFrame';
import getDataOrAriaProps from '../getDataOrAriaProps';
import triggerEvent from '../triggerEvent';
import Wave from '../wave';
describe('Test utils function', () => {
beforeAll(() => {
@ -128,4 +131,33 @@ describe('Test utils function', () => {
triggerEvent(button, 'click');
expect(button.style.width).toBe('100px');
});
describe('wave', () => {
it('bindAnimationEvent should return when node is null', () => {
const wrapper = mount(
<Wave>
<button type="button" disabled />
</Wave>,
).instance();
expect(wrapper.bindAnimationEvent()).toBe(undefined);
});
it('bindAnimationEvent.onClick should return when children is hidden', () => {
const wrapper = mount(
<Wave>
<button type="button" style={{ display: 'none' }} />
</Wave>,
).instance();
expect(wrapper.bindAnimationEvent()).toBe(undefined);
});
it('bindAnimationEvent.onClick should return when children is input', () => {
const wrapper = mount(
<Wave>
<input />
</Wave>,
).instance();
expect(wrapper.bindAnimationEvent()).toBe(undefined);
});
});
});

View File

@ -127,4 +127,14 @@ describe('Affix Render', () => {
jest.runAllTimers();
expect(wrapper.instance().affix.state.affixStyle.top).toBe(10);
});
it('updatePosition when target changed', () => {
const container = '<div id="mounter" />';
const getTarget = () => container;
wrapper = mount(<Affix target={getTarget} />);
wrapper.setProps({ target: null });
expect(wrapper.instance().state.status).toBe(0);
expect(wrapper.instance().state.affixStyle).toBe(undefined);
expect(wrapper.instance().state.placeholderStyle).toBe(undefined);
});
});

View File

@ -147,7 +147,7 @@ export default class Header extends React.Component<HeaderProps, any> {
type === 'month'
? this.getMonthSelectElement(prefixCls, value.month(), this.getMonthsLocale(value))
: null;
const size = (fullscreen ? 'default' : 'small') as any;
const size = fullscreen ? 'default' : 'small';
const typeSwitch = (
<Group onChange={this.onTypeChange} value={type} size={size}>
<Button value="month">{locale.month}</Button>

View File

@ -3,6 +3,7 @@ import Moment from 'moment';
import { mount } from 'enzyme';
import MockDate from 'mockdate';
import Calendar from '..';
import Header from '../Header';
describe('Calendar', () => {
it('Calendar should be selectable', () => {
@ -175,4 +176,84 @@ describe('Calendar', () => {
expect(onPanelChange).toBeCalled();
expect(onPanelChange.mock.calls[0][1]).toEqual('year');
});
const createWrapper = (start, end, value, onValueChange) => {
const wrapper = mount(
<Header
onValueChange={onValueChange}
value={value}
validRange={[start, end]}
locale={{ year: '年' }}
/>,
);
wrapper
.find('.ant-fullcalendar-year-select')
.hostNodes()
.simulate('click');
wrapper
.find('.ant-select-dropdown-menu-item')
.at(0)
.simulate('click');
};
it('if value.month > end.month, set value.month to end.month', () => {
const value = new Moment('1990-01-03');
const start = new Moment('2019-04-01');
const end = new Moment('2019-11-01');
const onValueChange = jest.fn();
createWrapper(start, end, value, onValueChange);
expect(onValueChange).toHaveBeenCalledWith(value.year('2019').month('3'));
});
it('if start.month > value.month, set value.month to start.month ', () => {
const value = new Moment('1990-01-03');
const start = new Moment('2019-11-01');
const end = new Moment('2019-03-01');
const onValueChange = jest.fn();
createWrapper(start, end, value, onValueChange);
expect(onValueChange).toHaveBeenCalledWith(value.year('2019').month('10'));
});
it('onMonthChange should work correctly', () => {
const start = new Moment('2018-11-01');
const end = new Moment('2019-03-01');
const value = new Moment('2018-12-03');
const onValueChange = jest.fn();
const wrapper = mount(
<Header
onValueChange={onValueChange}
value={value}
validRange={[start, end]}
locale={{ year: '年' }}
type="month"
/>,
);
wrapper
.find('.ant-fullcalendar-month-select')
.hostNodes()
.simulate('click');
wrapper
.find('.ant-select-dropdown-menu-item')
.at(0)
.simulate('click');
expect(onValueChange).toHaveBeenCalledWith(value.month(10));
});
it('onTypeChange should work correctly', () => {
const onTypeChange = jest.fn();
const value = new Moment('2018-12-03');
const wrapper = mount(
<Header
onTypeChange={onTypeChange}
locale={{ year: '年', month: '月' }}
value={value}
type="date"
/>,
);
wrapper
.find('input')
.at(1)
.simulate('change');
expect(onTypeChange).toBeCalledWith('year');
});
});

View File

@ -55,4 +55,62 @@ describe('Card', () => {
);
expect(wrapper.render()).toMatchSnapshot();
});
it('warning', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
mount(<Card noHovering>xxx</Card>);
expect(warnSpy).toBeCalledWith(
'Warning: [antd: Card] `noHovering` is deprecated, you can remove it safely or use `hoverable` instead.',
);
mount(<Card noHovering={false}>xxx</Card>);
expect(warnSpy).toBeCalledWith(
'Warning: [antd: Card] `noHovering={false}` is deprecated, use `hoverable` instead.',
);
warnSpy.mockRestore();
});
it('unmount', () => {
const wrapper = mount(<Card>xxx</Card>);
const removeResizeEventSpy = jest.spyOn(wrapper.instance().resizeEvent, 'remove');
wrapper.unmount();
expect(removeResizeEventSpy).toHaveBeenCalled();
});
it('onTabChange should work', () => {
const tabList = [
{
key: 'tab1',
tab: 'tab1',
},
{
key: 'tab2',
tab: 'tab2',
},
];
const onTabChange = jest.fn();
const wrapper = mount(
<Card onTabChange={onTabChange} tabList={tabList}>
xxx
</Card>,
);
wrapper
.find('.ant-tabs-tab')
.at(1)
.simulate('click');
expect(onTabChange).toBeCalledWith('tab2');
});
it('getCompatibleHoverable should work', () => {
const wrapper = mount(<Card noHovering={false}>xxx</Card>);
expect(wrapper.find('.ant-card-hoverable').length).toBe(1);
});
it('should not render when actions is number', () => {
const wrapper = mount(
<Card title="Card title" actions={11}>
<p>Card content</p>
</Card>,
);
expect(wrapper.find('.ant-card-actions').length).toBe(0);
});
});

View File

@ -129,9 +129,6 @@ export default class Card extends React.Component<CardProps, CardState> {
}
getAction(actions: React.ReactNode[]) {
if (!actions || !actions.length) {
return null;
}
const actionList = actions.map((action, index) => (
<li style={{ width: `${100 / actions.length}%` }} key={`action-${index}`}>
<span>{action}</span>

View File

@ -113,4 +113,18 @@ describe('Mention', () => {
expect(items.length).toBe(1);
expect(items.at(0).props().children).toBe('bamboo');
});
it('check filteredSuggestions', () => {
if (process.env.REACT === '15') {
return;
}
const wrapper = mount(<Mention defaultSuggestions={[<Mention.Nav value="light" />]} />);
wrapper.find('DraftEditorContents').simulate('focus');
const ed = wrapper.find('.public-DraftEditor-content');
ed.simulate('beforeInput', { data: '@l' });
jest.runAllTimers();
const items = wrapper.find('div.ant-mention-dropdown-item');
expect(items.length).toBe(1);
expect(items.at(0).props().value).toBe('light');
});
});

View File

@ -538,6 +538,28 @@ describe('Menu', () => {
expect(wrapper.find('.ant-menu-submenu-popup').length).toBe(0);
});
it('onMouseEnter should work', () => {
const onMouseEnter = jest.fn();
const wrapper = mount(
<Menu onMouseEnter={onMouseEnter} defaultSelectedKeys={['test1']}>
<Menu.Item key="test1">Navigation One</Menu.Item>
<Menu.Item key="test2">Navigation Two</Menu.Item>
</Menu>,
);
wrapper
.find('Menu')
.at(1)
.simulate('mouseenter');
expect(onMouseEnter).toHaveBeenCalled();
});
it('get correct animation type when switched from inline', () => {
const wrapper = mount(<Menu mode="inline" />);
wrapper.setProps({ mode: 'horizontal' });
expect(wrapper.instance().getMenuOpenAnimation('')).toBe('');
expect(wrapper.instance().switchingModeFromInline).toBe(false);
});
it('Menu should not shake when collapsed changed', () => {
const wrapper = mount(
<Menu

View File

@ -370,4 +370,39 @@ describe('Upload', () => {
);
expect(typeof wrapper.instance().upload.abort).toBe('function');
});
it('unmount', () => {
const wrapper = mount(
<Upload>
<button type="button">upload</button>
</Upload>,
);
const clearIntervalSpy = jest.spyOn(global, 'clearInterval');
expect(clearIntervalSpy).not.toHaveBeenCalled();
wrapper.unmount();
expect(clearIntervalSpy).toHaveBeenCalled();
clearIntervalSpy.mockRestore();
});
it('corrent dragCls when type is drag', () => {
const fileList = [{ status: 'uploading', uid: 'file' }];
const wrapper = mount(
<Upload type="drag" fileList={fileList}>
<button type="button">upload</button>
</Upload>,
);
expect(wrapper.find('.ant-upload-drag-uploading').length).toBe(1);
});
it('return when targetItem is null', () => {
const fileList = [{ uid: 'file' }];
const wrapper = mount(
<Upload type="drag" fileList={fileList}>
<button type="button">upload</button>
</Upload>,
).instance();
expect(wrapper.onSuccess('', { uid: 'fileItem' })).toBe(undefined);
expect(wrapper.onProgress('', { uid: 'fileItem' })).toBe(undefined);
expect(wrapper.onError('', '', { uid: 'fileItem' })).toBe(undefined);
});
});