2019-02-20 18:18:19 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2022-02-09 18:06:36 +08:00
|
|
|
import { ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons';
|
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' });
|
|
|
|
});
|
2022-02-09 18:06:36 +08:00
|
|
|
|
|
|
|
it('renders correctly when controls is boolean', () => {
|
|
|
|
expect(mount(<InputNumber controls={false} />).render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly when controls is {}', () => {
|
|
|
|
expect(mount(<InputNumber controls={{}} />).render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly when controls has custom upIcon and downIcon', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<InputNumber
|
|
|
|
controls={{
|
|
|
|
upIcon: <ArrowUpOutlined />,
|
|
|
|
downIcon: <ArrowDownOutlined />,
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support className', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<InputNumber
|
|
|
|
controls={{
|
|
|
|
upIcon: <ArrowUpOutlined className="my-class-name" />,
|
|
|
|
downIcon: <ArrowDownOutlined className="my-class-name" />,
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('.anticon-arrow-up').getDOMNode().className.includes('my-class-name')).toBe(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
wrapper.find('.anticon-arrow-down').getDOMNode().className.includes('my-class-name'),
|
|
|
|
).toBe(true);
|
|
|
|
});
|
2019-02-20 18:18:19 +08:00
|
|
|
});
|