@@ -25,14 +25,13 @@ import {
2525 generateMessage ,
2626 generateUser ,
2727 getOrCreateChannelApi ,
28+ getTestClient ,
2829 getTestClientWithUser ,
2930 useMockedApis ,
3031} from '../../../mock-builders' ;
3132
3233expect . extend ( toHaveNoViolations ) ;
3334
34- jest . mock ( '../../Channel/utils' , ( ) => ( { makeAddNotifications : jest . fn } ) ) ;
35-
3635let chatClient ;
3736let channel ;
3837
@@ -76,6 +75,11 @@ const mockFaultyUploadApi = (cause) => jest.fn().mockImplementation(() => Promis
7675
7776const submitMock = jest . fn ( ) ;
7877const editMock = jest . fn ( ) ;
78+ const mockAddNotification = jest . fn ( ) ;
79+
80+ jest . mock ( '../../Channel/utils' , ( ) => ( {
81+ makeAddNotifications : ( ) => mockAddNotification ,
82+ } ) ) ;
7983
8084const defaultMessageContextValue = {
8185 getMessageActions : ( ) => [ 'delete' , 'edit' , 'quote' ] ,
@@ -509,6 +513,55 @@ function axeNoViolations(container) {
509513 await axeNoViolations ( container ) ;
510514 } ) ;
511515
516+ it ( 'should show notification if size limit is exceeded' , async ( ) => {
517+ chatClient = getTestClient ( {
518+ getAppSettings : ( ) => ( {
519+ app : {
520+ file_upload_config : { size_limit : 1 } ,
521+ image_upload_config : { size_limit : 1 } ,
522+ } ,
523+ } ) ,
524+ } ) ;
525+ await renderComponent ( {
526+ messageInputProps : {
527+ doFileUploadRequest : mockUploadApi ( ) ,
528+ } ,
529+ } ) ;
530+ const formElement = await screen . findByPlaceholderText ( inputPlaceholder ) ;
531+ const file = getFile ( filename1 ) ;
532+ act ( ( ) => dropFile ( file , formElement ) ) ;
533+ await waitFor ( ( ) => expect ( screen . queryByText ( filename1 ) ) . toBeInTheDocument ( ) ) ;
534+
535+ expect ( mockAddNotification ) . toHaveBeenCalledTimes ( 1 ) ;
536+ expect ( mockAddNotification . mock . calls [ 0 ] [ 0 ] ) . toContain ( 'File is too large' ) ;
537+ } ) ;
538+
539+ it ( 'should apply separate limits to files and images' , async ( ) => {
540+ chatClient = getTestClient ( {
541+ getAppSettings : ( ) => ( {
542+ app : {
543+ file_upload_config : { size_limit : 100 } ,
544+ image_upload_config : { size_limit : 1 } ,
545+ } ,
546+ } ) ,
547+ } ) ;
548+ const doImageUploadRequest = mockUploadApi ( ) ;
549+ await renderComponent ( {
550+ messageInputProps : {
551+ doImageUploadRequest,
552+ } ,
553+ } ) ;
554+ const formElement = await screen . findByPlaceholderText ( inputPlaceholder ) ;
555+ const file = getImage ( ) ;
556+ await act ( ( ) => {
557+ dropFile ( file , formElement ) ;
558+ } ) ;
559+ await waitFor ( ( ) => {
560+ expect ( mockAddNotification ) . toHaveBeenCalledTimes ( 1 ) ;
561+ expect ( mockAddNotification . mock . calls [ 0 ] [ 0 ] ) . toContain ( 'File is too large' ) ;
562+ } ) ;
563+ } ) ;
564+
512565 // TODO: Check if pasting plaintext is not prevented -> tricky because recreating exact event is hard
513566 // TODO: Remove image/file -> difficult because there is no easy selector and components are in react-file-utils
514567 } ) ;
0 commit comments