import {type EnterValueOptions} from '@wix/unidriver-core'; import {Simulate} from 'react-dom/test-utils'; import {act} from '../actCompat'; import {slowType} from './slowType'; import {type JSX} from 'react'; export const enterValue = async (base: JSX.IntrinsicElements['input'], value: string, options?: EnterValueOptions) => { const shouldClear = options?.shouldClear ?? true; // Don't do anything if element is disabled or readOnly if (base.disabled || base.readOnly) { return; } const {name, type, onChange} = base; // Set native value for uncontrolled component if (!onChange && shouldClear) { base.value = value; } if (options?.delay) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument await slowType(base as any, value, options.delay); } /* eslint-disable @typescript-eslint/no-misused-promises */ await act(async () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument Simulate.change(base as any, { target: {name, type, value: shouldClear ? value : String(base.value) + value} as HTMLInputElement, }); }); };