diff --git a/components/grid/__tests__/index.test.js b/components/grid/__tests__/index.test.js
index d529ef053b..fdc8d58d54 100644
--- a/components/grid/__tests__/index.test.js
+++ b/components/grid/__tests__/index.test.js
@@ -62,4 +62,16 @@ describe('Grid', () => {
);
expect(wrapper).toMatchSnapshot();
});
+
+ it('when component has been unmounted, componentWillUnmount should be called', () => {
+ const wrapper = mount(
);
+ const willUnmount = jest.spyOn(wrapper.instance(), 'componentWillUnmount');
+ wrapper.unmount();
+ expect(willUnmount).toHaveBeenCalled();
+ });
+
+ it('when typeof getGutter is object', () => {
+ const wrapper = mount(
).instance();
+ expect(wrapper.getGutter()).toBe(8);
+ });
});
diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js
index 24bc106c0b..d60ba2a9f4 100644
--- a/components/input/__tests__/index.test.js
+++ b/components/input/__tests__/index.test.js
@@ -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();
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();
+ 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(
+ ,
+ );
+ wrapper.instance().handleKeyDown({ keyCode: 13 });
+ expect(onPressEnter).toBeCalled();
+ expect(onKeyDown).toBeCalled();
+ });
});
describe('As Form Control', () => {
diff --git a/components/input/calculateNodeHeight.tsx b/components/input/calculateNodeHeight.tsx
index 1c4fff5bb6..5ef173ddf7 100644
--- a/components/input/calculateNodeHeight.tsx
+++ b/components/input/calculateNodeHeight.tsx
@@ -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;
diff --git a/components/transfer/__tests__/list.test.js b/components/transfer/__tests__/list.test.js
index 2ae5a57a20..ca427c115a 100644
--- a/components/transfer/__tests__/list.test.js
+++ b/components/transfer/__tests__/list.test.js
@@ -40,4 +40,18 @@ describe('List', () => {
.prop('checked'),
).toBeTruthy();
});
+
+ it('when component has been unmounted, componentWillUnmount should be called', () => {
+ const wrapper = mount(
);
+ 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(
);
+ expect(wrapper.instance().handleFilter({ target: 'test' })).toBe(undefined);
+ expect(handleFilter).toBeCalled();
+ });
});