@@ -314,6 +314,42 @@ describe('ChannelList', () => {
314314 expect ( results ) . toHaveNoViolations ( ) ;
315315 } ) ;
316316
317+ it ( 'should add a notification when the first page of channels fails to load' , async ( ) => {
318+ useMockedApis ( chatClient , [ erroredPostApi ( ) ] ) ;
319+ const addNotificationSpy = vi . spyOn ( chatClient . notifications , 'add' ) ;
320+ vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => null ) ;
321+
322+ render (
323+ < Chat client = { chatClient } >
324+ < WithComponents
325+ overrides = { {
326+ ChannelListItemUI : ChannelPreviewComponent ,
327+ ChannelListUI : ChannelListComponent ,
328+ } }
329+ >
330+ < ChannelList
331+ filters = { { } }
332+ options = { { presence : true , state : true , watch : true } }
333+ />
334+ </ WithComponents >
335+ </ Chat > ,
336+ ) ;
337+
338+ await waitFor ( ( ) => {
339+ expect ( addNotificationSpy ) . toHaveBeenCalledWith (
340+ expect . objectContaining ( {
341+ message : 'Failed to load channels' ,
342+ options : expect . objectContaining ( {
343+ severity : 'error' ,
344+ tags : expect . arrayContaining ( [ 'target:channel-list' ] ) ,
345+ type : 'api:channel-list:load:failed' ,
346+ } ) ,
347+ origin : { emitter : 'ChannelList' } ,
348+ } ) ,
349+ ) ;
350+ } ) ;
351+ } ) ;
352+
317353 it ( 'provides the error object to LoadingErrorIndicator' , async ( ) => {
318354 useMockedApis ( chatClient , [ erroredPostApi ( ) ] ) ;
319355 vi . spyOn ( console , 'warn' ) . mockImplementationOnce ( ( ) => null ) ;
@@ -341,6 +377,54 @@ describe('ChannelList', () => {
341377 expect ( screen . getByText ( 'StreamChat error HTTP code: 500' ) ) . toBeInTheDocument ( ) ;
342378 } ) ;
343379
380+ it ( 'should keep loaded channels visible and add a notification when loading more fails' , async ( ) => {
381+ useMockedApis ( chatClient , [ queryChannelsApi ( [ testChannel1 , testChannel2 ] ) ] ) ;
382+ const addNotificationSpy = vi . spyOn ( chatClient . notifications , 'add' ) ;
383+ vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => null ) ;
384+
385+ render (
386+ < Chat client = { chatClient } >
387+ < WithComponents
388+ overrides = { {
389+ ChannelListItemUI : ChannelPreviewComponent ,
390+ ChannelListUI : ChannelListComponent ,
391+ } }
392+ >
393+ < ChannelList filters = { { } } options = { { limit : 2 } } />
394+ </ WithComponents >
395+ </ Chat > ,
396+ ) ;
397+
398+ await waitFor ( ( ) => {
399+ expect ( screen . getByTestId ( testChannel1 . channel . id ) ) . toBeInTheDocument ( ) ;
400+ expect ( screen . getByTestId ( testChannel2 . channel . id ) ) . toBeInTheDocument ( ) ;
401+ } ) ;
402+
403+ useMockedApis ( chatClient , [ erroredPostApi ( ) ] ) ;
404+
405+ await act ( ( ) => {
406+ fireEvent . click ( screen . getByTestId ( 'load-more-button' ) ) ;
407+ } ) ;
408+
409+ await waitFor ( ( ) => {
410+ expect ( addNotificationSpy ) . toHaveBeenCalledWith (
411+ expect . objectContaining ( {
412+ message : 'Failed to load more channels' ,
413+ options : expect . objectContaining ( {
414+ severity : 'error' ,
415+ tags : expect . arrayContaining ( [ 'target:channel-list' ] ) ,
416+ type : 'api:channel-list:load-more:failed' ,
417+ } ) ,
418+ origin : { emitter : 'ChannelList' } ,
419+ } ) ,
420+ ) ;
421+ } ) ;
422+
423+ expect ( screen . getByTestId ( testChannel1 . channel . id ) ) . toBeInTheDocument ( ) ;
424+ expect ( screen . getByTestId ( testChannel2 . channel . id ) ) . toBeInTheDocument ( ) ;
425+ expect ( screen . queryByTestId ( 'error-indicator' ) ) . not . toBeInTheDocument ( ) ;
426+ } ) ;
427+
344428 it ( 'should render loading indicator before the first channel list load and on reload' , async ( ) => {
345429 const channelsQueryStatesHistory = [ ] ;
346430 const channelListMessengerLoadingHistory = [ ] ;
0 commit comments