@@ -333,6 +333,64 @@ function axeNoViolations(container) {
333333 expect ( results ) . toHaveNoViolations ( ) ;
334334 } ) ;
335335
336+ it ( 'gives preference to pasting text over files' , async ( ) => {
337+ const doImageUploadRequest = mockUploadApi ( ) ;
338+ const doFileUploadRequest = mockUploadApi ( ) ;
339+ const pastedString = 'pasted string' ;
340+ const { container } = await renderComponent ( {
341+ messageInputProps : {
342+ doFileUploadRequest,
343+ doImageUploadRequest,
344+ } ,
345+ } ) ;
346+
347+ const file = getFile ( ) ;
348+ const image = getImage ( ) ;
349+
350+ const clipboardEvent = new Event ( 'paste' , {
351+ bubbles : true ,
352+ } ) ;
353+ // set `clipboardData`. Mock DataTransfer object
354+ clipboardEvent . clipboardData = {
355+ items : [
356+ {
357+ getAsFile : ( ) => file ,
358+ kind : 'file' ,
359+ } ,
360+ {
361+ getAsFile : ( ) => image ,
362+ kind : 'file' ,
363+ } ,
364+ {
365+ getAsString : ( cb ) => cb ( pastedString ) ,
366+ kind : 'string' ,
367+ type : 'text/plain' ,
368+ } ,
369+ ] ,
370+ } ;
371+ const formElement = screen . getByPlaceholderText ( inputPlaceholder ) ;
372+ await act ( async ( ) => {
373+ await formElement . dispatchEvent ( clipboardEvent ) ;
374+ } ) ;
375+
376+ await waitFor ( ( ) => {
377+ expect ( doFileUploadRequest ) . not . toHaveBeenCalled ( ) ;
378+ expect ( doImageUploadRequest ) . not . toHaveBeenCalled ( ) ;
379+ expect ( screen . queryByTestId ( IMAGE_PREVIEW_TEST_ID ) ) . not . toBeInTheDocument ( ) ;
380+ expect ( screen . queryByTestId ( FILE_PREVIEW_TEST_ID ) ) . not . toBeInTheDocument ( ) ;
381+ expect ( screen . queryByText ( filename ) ) . not . toBeInTheDocument ( ) ;
382+ expect ( screen . queryByTestId ( ATTACHMENT_PREVIEW_LIST_TEST_ID ) ) . not . toBeInTheDocument ( ) ;
383+ if ( componentName === 'EditMessageForm' ) {
384+ expect ( formElement . value . startsWith ( pastedString ) ) . toBeTruthy ( ) ;
385+ } else {
386+ expect ( formElement ) . toHaveValue ( pastedString ) ;
387+ }
388+ } ) ;
389+
390+ const results = await axe ( container ) ;
391+ expect ( results ) . toHaveNoViolations ( ) ;
392+ } ) ;
393+
336394 it ( 'Should upload an image when it is dropped on the dropzone' , async ( ) => {
337395 const doImageUploadRequest = mockUploadApi ( ) ;
338396 const { container } = await renderComponent ( {
0 commit comments