2017-01-30 20:05:47 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Input from '..';
|
|
|
|
|
|
|
|
jest.mock('../calculateNodeHeight');
|
|
|
|
const calculateNodeHeight = require('../calculateNodeHeight');
|
|
|
|
|
|
|
|
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
|
|
|
|
|
|
|
|
describe('Input', () => {
|
2017-01-31 16:03:14 +08:00
|
|
|
it('should not auto calculate height when type is text', async () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Input value="" readOnly />
|
|
|
|
);
|
|
|
|
expect(calculateNodeHeight).toHaveBeenCalledTimes(0);
|
|
|
|
wrapper.setProps({ value: '1111\n2222\n3333' });
|
|
|
|
await delay(0);
|
|
|
|
expect(calculateNodeHeight).toHaveBeenCalledTimes(0);
|
|
|
|
wrapper.setProps({ value: '1111' });
|
|
|
|
await delay(0);
|
|
|
|
expect(calculateNodeHeight).toHaveBeenCalledTimes(0);
|
|
|
|
});
|
|
|
|
|
2017-01-30 20:05:47 +08:00
|
|
|
it('should auto calculate height according to content length', async () => {
|
|
|
|
const wrapper = mount(
|
2017-01-31 16:03:14 +08:00
|
|
|
<Input value="" readOnly type="textarea" autosize />
|
2017-01-30 20:05:47 +08:00
|
|
|
);
|
|
|
|
expect(calculateNodeHeight).toHaveBeenCalledTimes(1);
|
|
|
|
wrapper.setProps({ value: '1111\n2222\n3333' });
|
|
|
|
await delay(0);
|
|
|
|
expect(calculateNodeHeight).toHaveBeenCalledTimes(2);
|
|
|
|
wrapper.setProps({ value: '1111' });
|
|
|
|
await delay(0);
|
|
|
|
expect(calculateNodeHeight).toHaveBeenCalledTimes(3);
|
|
|
|
});
|
|
|
|
});
|