@@ -91,6 +91,27 @@ const fileUploadUrl = 'http://www.getstream.io'; // real url, because ImageAttac
9191const getImage = ( ) => new File ( [ 'content' ] , filename , { type : 'image/png' } ) ;
9292const getFile = ( name = filename ) => new File ( [ 'content' ] , name , { type : 'text/plain' } ) ;
9393
94+ /** Matches Channel.sendFile / sendImage (uri, name?, contentType?, user?, axiosRequestConfig?). */
95+ const expectChannelUploadSendFile = ( spy , file ) => {
96+ expect ( spy ) . toHaveBeenCalledWith (
97+ file ,
98+ undefined ,
99+ undefined ,
100+ undefined ,
101+ expect . objectContaining ( { onUploadProgress : expect . any ( Function ) } ) ,
102+ ) ;
103+ } ;
104+
105+ const expectChannelUploadSendImage = ( spy , image ) => {
106+ expect ( spy ) . toHaveBeenCalledWith (
107+ image ,
108+ undefined ,
109+ undefined ,
110+ undefined ,
111+ expect . objectContaining ( { onUploadProgress : expect . any ( Function ) } ) ,
112+ ) ;
113+ } ;
114+
94115const sendMessageMock = jest . fn ( ) ;
95116const editMock = jest . fn ( ) ;
96117const mockAddNotification = jest . fn ( ) ;
@@ -440,8 +461,8 @@ describe(`EditMessageForm`, () => {
440461 } ) ;
441462 const filenameTexts = await screen . findAllByTitle ( filename ) ;
442463 await waitFor ( ( ) => {
443- expect ( sendFileSpy ) . toHaveBeenCalledWith ( file ) ;
444- expect ( sendImageSpy ) . toHaveBeenCalledWith ( image ) ;
464+ expectChannelUploadSendFile ( sendFileSpy , file ) ;
465+ expectChannelUploadSendImage ( sendImageSpy , image ) ;
445466 expect ( screen . getByTestId ( IMAGE_PREVIEW_TEST_ID ) ) . toBeInTheDocument ( ) ;
446467 expect ( screen . getByTestId ( FILE_PREVIEW_TEST_ID ) ) . toBeInTheDocument ( ) ;
447468 filenameTexts . forEach ( ( filenameText ) => expect ( filenameText ) . toBeInTheDocument ( ) ) ;
@@ -512,7 +533,7 @@ describe(`EditMessageForm`, () => {
512533 dropFile ( file , formElement ) ;
513534 } ) ;
514535 await waitFor ( ( ) => {
515- expect ( sendImageSpy ) . toHaveBeenCalledWith ( file ) ;
536+ expectChannelUploadSendImage ( sendImageSpy , file ) ;
516537 } ) ;
517538 const results = await axe ( container ) ;
518539 expect ( results ) . toHaveNoViolations ( ) ;
@@ -579,7 +600,7 @@ describe(`EditMessageForm`, () => {
579600 act ( ( ) => dropFile ( file , formElement ) ) ;
580601
581602 await waitFor ( ( ) => {
582- expect ( sendFileSpy ) . toHaveBeenCalledWith ( file ) ;
603+ expectChannelUploadSendFile ( sendFileSpy , file ) ;
583604 } ) ;
584605
585606 sendFileSpy . mockImplementationOnce ( ( ) => Promise . resolve ( { file } ) ) ;
@@ -590,7 +611,7 @@ describe(`EditMessageForm`, () => {
590611
591612 await waitFor ( ( ) => {
592613 expect ( sendFileSpy ) . toHaveBeenCalledTimes ( 2 ) ;
593- expect ( sendFileSpy ) . toHaveBeenCalledWith ( file ) ;
614+ expectChannelUploadSendFile ( sendFileSpy , file ) ;
594615 } ) ;
595616 await axeNoViolations ( container ) ;
596617 } ) ;
0 commit comments