mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 03:14:07 +08:00
7e7c47509f
* chore(deps-dev): bump eslint-plugin-jest from 26.9.0 to 27.0.1 Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 26.9.0 to 27.0.1. - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v26.9.0...v27.0.1) --- updated-dependencies: - dependency-name: eslint-plugin-jest dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore: fix eslint errors in test files Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: afc163 <afc163@gmail.com>
73 lines
2.6 KiB
JavaScript
73 lines
2.6 KiB
JavaScript
import React from 'react';
|
|
import { ArrowDownOutlined, ArrowUpOutlined } 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';
|
|
import { fireEvent, render } from '../../../tests/utils';
|
|
|
|
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 { container } = render(<InputNumber defaultValue="1" onChange={onChange} />);
|
|
fireEvent.change(container.querySelector('input'), { target: { value: '' } });
|
|
expect(onChange).toHaveBeenLastCalledWith(null);
|
|
});
|
|
|
|
it('should call onStep when press up or down button', () => {
|
|
const onStep = jest.fn();
|
|
const { container } = render(<InputNumber defaultValue={1} onStep={onStep} />);
|
|
fireEvent.mouseDown(container.querySelector('.ant-input-number-handler-up'));
|
|
expect(onStep).toHaveBeenCalledTimes(1);
|
|
expect(onStep).toHaveBeenLastCalledWith(2, { offset: 1, type: 'up' });
|
|
|
|
fireEvent.mouseDown(container.querySelector('.ant-input-number-handler-down'));
|
|
expect(onStep).toHaveBeenCalledTimes(2);
|
|
expect(onStep).toHaveBeenLastCalledWith(1, { offset: 1, type: 'down' });
|
|
});
|
|
|
|
it('renders correctly when controls is boolean', () => {
|
|
const { asFragment } = render(<InputNumber controls={false} />);
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders correctly when controls is {}', () => {
|
|
const { asFragment } = render(<InputNumber controls={{}} />);
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders correctly when controls has custom upIcon and downIcon', () => {
|
|
const { asFragment } = render(
|
|
<InputNumber
|
|
controls={{
|
|
upIcon: <ArrowUpOutlined />,
|
|
downIcon: <ArrowDownOutlined />,
|
|
}}
|
|
/>,
|
|
);
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('should support className', () => {
|
|
const { container } = render(
|
|
<InputNumber
|
|
controls={{
|
|
upIcon: <ArrowUpOutlined className="my-class-name" />,
|
|
downIcon: <ArrowDownOutlined className="my-class-name" />,
|
|
}}
|
|
/>,
|
|
);
|
|
expect(container.querySelector('.anticon-arrow-up')?.className.includes('my-class-name')).toBe(
|
|
true,
|
|
);
|
|
expect(
|
|
container.querySelector('.anticon-arrow-down')?.className.includes('my-class-name'),
|
|
).toBe(true);
|
|
});
|
|
});
|