11import { fakeAsync , TestBed , tick } from '@angular/core/testing' ;
22import { Subject } from 'rxjs' ;
3- import { first } from 'rxjs/operators' ;
3+ import { first , take } from 'rxjs/operators' ;
44import {
55 Channel ,
66 ChannelMemberResponse ,
77 ChannelOptions ,
8+ ChannelResponse ,
89 ChannelSort ,
910 Event ,
1011 SendMessageAPIResponse ,
@@ -184,10 +185,24 @@ describe('ChannelService', () => {
184185 expect ( activeChannelSpy ) . toHaveBeenCalledWith ( undefined ) ;
185186 expect ( messageToQuoteSpy ) . toHaveBeenCalledWith ( undefined ) ;
186187 expect ( latestMessagesSpy ) . toHaveBeenCalledWith ( { } ) ;
188+
189+ channelsSpy . calls . reset ( ) ;
190+ events$ . next ( {
191+ eventType : 'message.new' ,
192+ event : {
193+ channel : {
194+ id : 'channel' ,
195+ } as ChannelResponse < DefaultStreamChatGenerics > ,
196+ } as Event < DefaultStreamChatGenerics > ,
197+ } ) ;
198+
199+ expect ( channelsSpy ) . not . toHaveBeenCalled ( ) ;
187200 } ) ;
188201
189202 it ( 'should deselect active channel' , async ( ) => {
190203 await init ( ) ;
204+ let activeChannel ! : Channel < DefaultStreamChatGenerics > ;
205+ service . activeChannel$ . pipe ( take ( 1 ) ) . subscribe ( ( c ) => ( activeChannel = c ! ) ) ;
191206 const messagesSpy = jasmine . createSpy ( ) ;
192207 service . activeChannelMessages$ . subscribe ( messagesSpy ) ;
193208 const activeChannelSpy = jasmine . createSpy ( ) ;
@@ -206,6 +221,11 @@ describe('ChannelService', () => {
206221 expect ( activeChannelSpy ) . toHaveBeenCalledWith ( undefined ) ;
207222 expect ( messageToQuoteSpy ) . toHaveBeenCalledWith ( undefined ) ;
208223 expect ( latestMessagesSpy ) . toHaveBeenCalledWith ( { } ) ;
224+
225+ messagesSpy . calls . reset ( ) ;
226+ ( activeChannel as MockChannel ) . handleEvent ( 'message.new' , mockMessage ( ) ) ;
227+
228+ expect ( messagesSpy ) . not . toHaveBeenCalled ( ) ;
209229 } ) ;
210230
211231 it ( 'should tell if user #hasMoreChannels$' , async ( ) => {
@@ -1508,4 +1528,20 @@ describe('ChannelService', () => {
15081528 expect ( customFileDeleteRequest ) . toHaveBeenCalledWith ( url , channel ) ;
15091529 expect ( channel . deleteFile ) . not . toHaveBeenCalled ( ) ;
15101530 } ) ;
1531+
1532+ it ( 'should reset state after connection recovered' , async ( ) => {
1533+ await init ( ) ;
1534+ spyOn ( service , 'init' ) ;
1535+ spyOn ( service , 'reset' ) ;
1536+ events$ . next ( { eventType : 'connection.recovered' } as ClientEvent ) ;
1537+
1538+ expect ( service . init ) . toHaveBeenCalledWith (
1539+ service [ 'filters' ] ! ,
1540+ service [ 'sort' ] ,
1541+ service [ 'options' ] ,
1542+ service [ 'shouldSetActiveChannel' ]
1543+ ) ;
1544+
1545+ expect ( service . reset ) . toHaveBeenCalledWith ( ) ;
1546+ } ) ;
15111547} ) ;
0 commit comments