mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-29 05:29:37 +08:00
Merge pull request #15153 from zy410419243/issue-14775
pref: lift up coverage rate
This commit is contained in:
commit
53a35adbd5
@ -62,4 +62,16 @@ describe('Grid', () => {
|
||||
);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('when component has been unmounted, componentWillUnmount should be called', () => {
|
||||
const wrapper = mount(<Row />);
|
||||
const willUnmount = jest.spyOn(wrapper.instance(), 'componentWillUnmount');
|
||||
wrapper.unmount();
|
||||
expect(willUnmount).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('when typeof getGutter is object', () => {
|
||||
const wrapper = mount(<Row gutter={{ xs: 8, sm: 16, md: 24 }} />).instance();
|
||||
expect(wrapper.getGutter()).toBe(8);
|
||||
});
|
||||
});
|
||||
|
@ -1,10 +1,10 @@
|
||||
import React from 'react';
|
||||
|
||||
import { mount } from 'enzyme';
|
||||
|
||||
/* eslint-disable import/no-unresolved */
|
||||
import Form from '../../form';
|
||||
import Input from '..';
|
||||
import focusTest from '../../../tests/shared/focusTest';
|
||||
import calculateNodeHeight, { calculateNodeStyling } from '../calculateNodeHeight';
|
||||
|
||||
const { TextArea } = Input;
|
||||
|
||||
@ -70,6 +70,70 @@ describe('TextArea', () => {
|
||||
const wrapper = mount(<TextArea maxLength={10} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('calculateNodeStyling works correctly', () => {
|
||||
const wrapper = document.createElement('textarea');
|
||||
wrapper.id = 'test';
|
||||
wrapper.wrap = 'wrap';
|
||||
calculateNodeStyling(wrapper, true);
|
||||
const value = calculateNodeStyling(wrapper, true);
|
||||
expect(value).toEqual({
|
||||
borderSize: 2,
|
||||
boxSizing: '',
|
||||
paddingSize: 4,
|
||||
sizingStyle:
|
||||
'letter-spacing:normal;line-height:normal;padding-top:2px;padding-bottom:2px;font-family:-webkit-small-control;font-weight:;font-size:;font-variant:;text-rendering:auto;text-transform:none;width:;text-indent:0;padding-left:2px;padding-right:2px;border-width:1px;box-sizing:',
|
||||
});
|
||||
});
|
||||
|
||||
it('boxSizing === "border-box"', () => {
|
||||
const wrapper = document.createElement('textarea');
|
||||
wrapper.style.boxSizing = 'border-box';
|
||||
const { height } = calculateNodeHeight(wrapper);
|
||||
expect(height).toBe(2);
|
||||
});
|
||||
|
||||
it('boxSizing === "content-box"', () => {
|
||||
const wrapper = document.createElement('textarea');
|
||||
wrapper.style.boxSizing = 'content-box';
|
||||
const { height } = calculateNodeHeight(wrapper);
|
||||
expect(height).toBe(-4);
|
||||
});
|
||||
|
||||
it('minRows or maxRows is not null', () => {
|
||||
const wrapper = document.createElement('textarea');
|
||||
expect(calculateNodeHeight(wrapper, 1, 1)).toEqual({
|
||||
height: 0,
|
||||
maxHeight: 9007199254740991,
|
||||
minHeight: -4,
|
||||
overflowY: undefined,
|
||||
});
|
||||
wrapper.style.boxSizing = 'content-box';
|
||||
expect(calculateNodeHeight(wrapper, 1, 1)).toEqual({
|
||||
height: -4,
|
||||
maxHeight: 9007199254740991,
|
||||
minHeight: -4,
|
||||
overflowY: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('when prop value not in this.props, resizeTextarea should be called', () => {
|
||||
const wrapper = mount(<TextArea aria-label="textarea" />);
|
||||
const resizeTextarea = jest.spyOn(wrapper.instance(), 'resizeTextarea');
|
||||
wrapper.find('textarea').simulate('change', 'test');
|
||||
expect(resizeTextarea).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handleKeyDown', () => {
|
||||
const onPressEnter = jest.fn();
|
||||
const onKeyDown = jest.fn();
|
||||
const wrapper = mount(
|
||||
<TextArea onPressEnter={onPressEnter} onKeyDown={onKeyDown} aria-label="textarea" />,
|
||||
);
|
||||
wrapper.instance().handleKeyDown({ keyCode: 13 });
|
||||
expect(onPressEnter).toBeCalled();
|
||||
expect(onKeyDown).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('As Form Control', () => {
|
||||
|
@ -45,7 +45,7 @@ export interface NodeType {
|
||||
const computedStyleCache: { [key: string]: NodeType } = {};
|
||||
let hiddenTextarea: HTMLTextAreaElement;
|
||||
|
||||
function calculateNodeStyling(node: HTMLElement, useCache = false) {
|
||||
export function calculateNodeStyling(node: HTMLElement, useCache = false) {
|
||||
const nodeRef = (node.getAttribute('id') ||
|
||||
node.getAttribute('data-reactid') ||
|
||||
node.getAttribute('name')) as string;
|
||||
|
@ -40,4 +40,18 @@ describe('List', () => {
|
||||
.prop('checked'),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user