mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-04 17:09:46 +08:00
ee17f7185d
* feat: inputNumber controls support customize upIcon/downIcon * feat: 修改代码格式问题 * feat: 更新snapshot,修改代码开启prettier * feat: 更新snapshot,order 属性修改 * feat: upIcon/downIcon写法调整 * feat: 更新snapshot
70 lines
2.4 KiB
JavaScript
70 lines
2.4 KiB
JavaScript
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
import { ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons';
|
|
import InputNumber from '..';
|
|
import focusTest from '../../../tests/shared/focusTest';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
|
|
|
describe('InputNumber', () => {
|
|
focusTest(InputNumber, { refFocus: true });
|
|
mountTest(InputNumber);
|
|
rtlTest(InputNumber);
|
|
|
|
// 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);
|
|
});
|
|
|
|
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' });
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|