77 */
88
99import React from 'react' ;
10- import { fireEvent } from '@testing-library/react' ;
10+ import { fireEvent , waitFor } from '@testing-library/react' ;
1111import { render } from '../../../../test/rtl' ;
1212
1313import { EuiAbsoluteTab } from './absolute_tab' ;
1414import { LocaleSpecifier } from 'moment' ;
15+ import { userEvent } from '@storybook/test' ;
1516
1617// Mock EuiDatePicker - 3rd party datepicker lib causes render issues
1718jest . mock ( '../../date_picker' , ( ) => ( {
@@ -69,7 +70,7 @@ describe('EuiAbsoluteTab', () => {
6970 expect ( queryByText ( formatHelpText ) ) . toHaveClass ( 'euiFormErrorText' ) ;
7071 } ) ;
7172
72- it ( 'immediately parses pasted text without needing an extra click or keypress' , ( ) => {
73+ it ( 'immediately parses pasted text without needing an extra click or keypress' , async ( ) => {
7374 const { getByTestSubject, queryByText } = render (
7475 < EuiAbsoluteTab { ...props } />
7576 ) ;
@@ -80,9 +81,21 @@ describe('EuiAbsoluteTab', () => {
8081 fireEvent . paste ( input , {
8182 clipboardData : { getData : ( ) => '1970-01-01' } ,
8283 } ) ;
84+
8385 expect ( input ) . not . toBeInvalid ( ) ;
8486 expect ( input . value ) . toContain ( 'Jan 1, 1970' ) ;
8587
88+ // Additional pasting check as userEvent.paste more accurately simulates
89+ // the pasting behavior with side effects
90+ await waitFor ( ( ) => {
91+ input . focus ( ) ;
92+ userEvent . paste ( '1970-01-02' ) ;
93+ } ) ;
94+
95+ // ensure value is replaced, not appended
96+ expect ( input . value ) . not . toEqual ( 'Jan 1, 1970 @ 00:00:00.0001970-01-02' ) ;
97+ expect ( input . value ) . toEqual ( 'Jan 2, 1970 @ 00:00:00.000' ) ;
98+
8699 input . value = '' ;
87100 fireEvent . paste ( input , {
88101 clipboardData : { getData : ( ) => 'not a date' } ,
0 commit comments