@@ -36,7 +36,8 @@ import {
3636 ChannelPreviewMessenger ,
3737} from '../../ChannelPreview' ;
3838
39- import { ChatContext } from '../../../context/ChatContext' ;
39+ import { ChatContext , useChatContext } from '../../../context/ChatContext' ;
40+ import { ChannelListMessenger } from '../ChannelListMessenger' ;
4041
4142expect . extend ( toHaveNoViolations ) ;
4243
@@ -256,6 +257,42 @@ describe('ChannelList', () => {
256257 expect ( results ) . toHaveNoViolations ( ) ;
257258 } ) ;
258259
260+ it ( 'should render loading indicator before the first channel list load and on reload' , async ( ) => {
261+ const channelsQueryStatesHistory = [ ] ;
262+ const channelListMessengerLoadingHistory = [ ] ;
263+ useMockedApis ( chatClient , [ queryChannelsApi ( [ testChannel1 ] ) ] ) ;
264+
265+ const QueryStateInterceptor = ( { children } ) => {
266+ const { channelsQueryState } = useChatContext ( ) ;
267+ channelsQueryStatesHistory . push ( channelsQueryState . queryInProgress ) ;
268+ return children ;
269+ } ;
270+
271+ const ChannelListMessengerPropsInterceptor = ( props ) => {
272+ channelListMessengerLoadingHistory . push ( props . loading ) ;
273+ return < ChannelListMessenger { ...props } /> ;
274+ } ;
275+
276+ await act ( ( ) => {
277+ render (
278+ < Chat client = { chatClient } >
279+ < QueryStateInterceptor >
280+ < ChannelList List = { ChannelListMessengerPropsInterceptor } />
281+ </ QueryStateInterceptor >
282+ </ Chat > ,
283+ ) ;
284+ } ) ;
285+
286+ expect ( channelsQueryStatesHistory ) . toHaveLength ( 3 ) ;
287+ expect ( channelListMessengerLoadingHistory ) . toHaveLength ( 3 ) ;
288+ expect ( channelsQueryStatesHistory [ 0 ] ) . toBe ( 'uninitialized' ) ;
289+ expect ( channelListMessengerLoadingHistory [ 0 ] ) . toBe ( true ) ;
290+ expect ( channelsQueryStatesHistory [ 1 ] ) . toBe ( 'reload' ) ;
291+ expect ( channelListMessengerLoadingHistory [ 1 ] ) . toBe ( true ) ;
292+ expect ( channelsQueryStatesHistory [ 2 ] ) . toBeNull ( ) ;
293+ expect ( channelListMessengerLoadingHistory [ 2 ] ) . toBe ( false ) ;
294+ } ) ;
295+
259296 it ( 'ChannelPreview UI components should render `Avatar` when the custom prop is provided' , async ( ) => {
260297 useMockedApis ( chatClient , [ queryChannelsApi ( [ testChannel1 ] ) ] ) ;
261298
0 commit comments