@@ -40,6 +40,7 @@ describe('MessageListComponent', () => {
4040 let queryParentMessageReplyCount : ( ) => HTMLElement | null ;
4141 let queryTypingIndicator : ( ) => HTMLElement | null ;
4242 let queryTypingUsers : ( ) => HTMLElement | null ;
43+ let queryLoadingIndicator : ( pos : 'top' | 'bottom' ) => HTMLElement | null ;
4344
4445 beforeEach ( ( ) => {
4546 channelServiceMock = mockChannelService ( ) ;
@@ -90,6 +91,8 @@ describe('MessageListComponent', () => {
9091 nativeElement . querySelector ( '[data-testid="typing-users"]' ) ;
9192 queryParentMessageReplyCount = ( ) =>
9293 nativeElement . querySelector ( '[data-testid="reply-count"]' ) ;
94+ queryLoadingIndicator = ( pos : 'top' | 'bottom' ) =>
95+ nativeElement . querySelector ( `[data-testid="${ pos } -loading-indicator"]` ) ;
9396 TestBed . inject ( StreamI18nService ) . setTranslation ( 'en' ) ;
9497 fixture . detectChanges ( ) ;
9598 const scrollContainer = queryScrollContainer ( ) ! ;
@@ -870,4 +873,41 @@ describe('MessageListComponent', () => {
870873 ) ;
871874 } ) ;
872875 } ) ;
876+
877+ it ( 'should set isLoading flag' , ( ) => {
878+ expect ( component . isLoading ) . toBeFalse ( ) ;
879+
880+ const scrollContainer = queryScrollContainer ( ) ! ;
881+ scrollContainer . scrollTo ( { top : 0 } ) ;
882+ scrollContainer . dispatchEvent ( new Event ( 'scroll' ) ) ;
883+ fixture . detectChanges ( ) ;
884+
885+ expect ( component . isLoading ) . toBeTrue ( ) ;
886+
887+ channelServiceMock . activeChannelMessages$ . next ( generateMockMessages ( ) ) ;
888+
889+ expect ( component . isLoading ) . toBeFalse ( ) ;
890+ } ) ;
891+
892+ it ( 'should display loading indicator' , ( ) => {
893+ component . isLoading = false ;
894+ fixture . detectChanges ( ) ;
895+
896+ expect ( queryLoadingIndicator ( 'top' ) ) . toBeNull ( ) ;
897+ expect ( queryLoadingIndicator ( 'bottom' ) ) . toBeNull ( ) ;
898+
899+ component . direction = 'top-to-bottom' ;
900+ component . isLoading = true ;
901+ fixture . detectChanges ( ) ;
902+
903+ expect ( queryLoadingIndicator ( 'top' ) ) . toBeNull ( ) ;
904+ expect ( queryLoadingIndicator ( 'bottom' ) ) . not . toBeNull ( ) ;
905+
906+ component . direction = 'bottom-to-top' ;
907+ component . isLoading = true ;
908+ fixture . detectChanges ( ) ;
909+
910+ expect ( queryLoadingIndicator ( 'top' ) ) . not . toBeNull ( ) ;
911+ expect ( queryLoadingIndicator ( 'bottom' ) ) . toBeNull ( ) ;
912+ } ) ;
873913} ) ;
0 commit comments