2022-07-20 20:47:09 +08:00
|
|
|
import React, { forwardRef } from 'react';
|
2021-10-30 22:25:12 +08:00
|
|
|
import InputNumber from '..';
|
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2022-07-20 20:47:09 +08:00
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
2021-10-30 22:25:12 +08:00
|
|
|
|
|
|
|
describe('prefix', () => {
|
|
|
|
focusTest(
|
2022-07-20 20:47:09 +08:00
|
|
|
forwardRef((props, ref) => <InputNumber {...props} prefix="A" ref={ref} />),
|
2021-10-30 22:25:12 +08:00
|
|
|
{ refFocus: true },
|
|
|
|
);
|
|
|
|
it('should support className when has prefix', () => {
|
2022-04-15 23:33:10 +08:00
|
|
|
const { container } = render(<InputNumber prefix="suffix" className="my-class-name" />);
|
2022-09-05 19:41:32 +08:00
|
|
|
expect((container.firstChild as HTMLElement)?.className.includes('my-class-name')).toBe(true);
|
2022-04-15 23:33:10 +08:00
|
|
|
expect(container.querySelector('input')?.className.includes('my-class-name')).toBe(false);
|
2021-10-30 22:25:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger focus when prefix is clicked', () => {
|
2022-07-20 20:47:09 +08:00
|
|
|
const { container } = render(<InputNumber prefix={<i>123</i>} />);
|
2021-10-30 22:25:12 +08:00
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
const mockFocus = jest.spyOn(container.querySelector('input')!, 'focus');
|
|
|
|
fireEvent.mouseUp(container.querySelector('i')!);
|
2022-08-30 10:57:13 +08:00
|
|
|
expect(mockFocus).toHaveBeenCalled();
|
2021-10-30 22:25:12 +08:00
|
|
|
});
|
|
|
|
});
|