2022-07-20 20:47:09 +08:00
|
|
|
import React, { forwardRef } from 'react';
|
2023-07-18 12:18:51 +08:00
|
|
|
import type { InputNumberProps } from '..';
|
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(
|
2023-07-18 12:18:51 +08:00
|
|
|
forwardRef<HTMLInputElement, InputNumberProps>((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
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
const mockFocus = jest.spyOn(container.querySelector('input')!, 'focus');
|
2023-06-14 11:28:40 +08:00
|
|
|
fireEvent.click(container.querySelector('i')!);
|
2022-08-30 10:57:13 +08:00
|
|
|
expect(mockFocus).toHaveBeenCalled();
|
2021-10-30 22:25:12 +08:00
|
|
|
});
|
|
|
|
});
|