2019-02-20 18:18:19 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2018-03-23 19:19:29 +08:00
|
|
|
import InputNumber from '..';
|
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2018-03-23 19:19:29 +08:00
|
|
|
|
2019-02-20 18:18:19 +08:00
|
|
|
describe('InputNumber', () => {
|
2020-04-22 15:58:57 +08:00
|
|
|
focusTest(InputNumber, { refFocus: true });
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(InputNumber);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(InputNumber);
|
2019-02-20 18:18:19 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/13896
|
|
|
|
it('should return null when blur a empty input number', () => {
|
|
|
|
const onChange = jest.fn();
|
|
|
|
const wrapper = mount(<InputNumber defaultValue="1" onChange={onChange} />);
|
|
|
|
wrapper.find('input').simulate('change', { target: { value: '' } });
|
|
|
|
expect(onChange).toHaveBeenLastCalledWith(null);
|
|
|
|
});
|
2020-10-10 17:49:50 +08:00
|
|
|
|
|
|
|
it('should call onStep when press up or down button', () => {
|
|
|
|
const onStep = jest.fn();
|
|
|
|
const wrapper = mount(<InputNumber defaultValue={1} onStep={onStep} />);
|
|
|
|
wrapper.find('.ant-input-number-handler-up').simulate('mousedown');
|
|
|
|
expect(onStep).toBeCalledTimes(1);
|
|
|
|
expect(onStep).toHaveBeenLastCalledWith(2, { offset: 1, type: 'up' });
|
|
|
|
wrapper.find('.ant-input-number-handler-down').simulate('mousedown');
|
|
|
|
expect(onStep).toBeCalledTimes(2);
|
|
|
|
expect(onStep).toHaveBeenLastCalledWith(1, { offset: 1, type: 'down' });
|
|
|
|
});
|
2019-02-20 18:18:19 +08:00
|
|
|
});
|