import { fireEvent } from '@testing-library/dom' ; import { setUIValue , startTrackValue , endTrackValue } from '../../document' ; import { setSelection } from '../focus/selection' ; /**
 * Change the value of an element as if it was changed as a result of a user input.
 *
 * Fires the input event.
 */ export function editInputElement ( element , { newValue , newSelection , eventOverrides , } ) { const oldValue = element . value ; setUIValue ( element , newValue ) ; setSelection ( { focusNode : newSelection . node , anchorOffset : newSelection . offset , focusOffset : newSelection . offset , } ) ; startTrackValue ( element as HTMLInputElement ) ; fireEvent . input ( element , { ... eventOverrides , } ) ; const tracked = endTrackValue ( element as HTMLInputElement ) ; if ( tracked ?. length === 2 && tracked [ 0 ] === oldValue && tracked [ 1 ] === newValue ) { setSelection ( { focusNode : newSelection . node , anchorOffset : newSelection . offset , focusOffset : newSelection . offset , } ) ; } }