diff --git a/docusaurus/docs/Angular/code-examples/responsive-layout.mdx b/docusaurus/docs/Angular/code-examples/responsive-layout.mdx index 1c6577ee..1a12e031 100644 --- a/docusaurus/docs/Angular/code-examples/responsive-layout.mdx +++ b/docusaurus/docs/Angular/code-examples/responsive-layout.mdx @@ -204,20 +204,14 @@ Lastly, implement auto close behavior for the channel list: ```html ``` ```ts -closeMenu() { - let isChannelQueryInProgress = false; - this.channelService.channelQueryState$.pipe(take(1)).subscribe((state) => { - if (state?.state === 'in-progress') { - isChannelQueryInProgress = true; - } - }); - if (!isChannelQueryInProgress) { +closeMenu(event: Event) { + if ((event.target as HTMLElement).closest('stream-channel-preview')) { this.isMenuOpen = false; } } diff --git a/projects/sample-app/src/app/app.component.html b/projects/sample-app/src/app/app.component.html index 79a9e2db..3e753b7e 100644 --- a/projects/sample-app/src/app/app.component.html +++ b/projects/sample-app/src/app/app.component.html @@ -3,9 +3,9 @@ class="channel-list menu-{{ isMenuOpen ? 'open' : 'close' }} thread-{{ isThreadOpen ? 'open' : 'close' }}" - (click)="closeMenu()" + (click)="closeMenu($event)" > - + - + @@ -89,7 +74,10 @@ -
+
diff --git a/projects/stream-chat-angular/src/lib/channel-list/channel-list.component.spec.ts b/projects/stream-chat-angular/src/lib/channel-list/channel-list.component.spec.ts index 1dbbc2b2..7c3e0dc3 100644 --- a/projects/stream-chat-angular/src/lib/channel-list/channel-list.component.spec.ts +++ b/projects/stream-chat-angular/src/lib/channel-list/channel-list.component.spec.ts @@ -12,6 +12,8 @@ import { import { ThemeService } from '../theme.service'; import { ChannelListComponent } from './channel-list.component'; import { Subject, of } from 'rxjs'; +import { PaginatedListComponent } from '../paginated-list/paginated-list.component'; +import { Channel } from 'stream-chat'; describe('ChannelListComponent', () => { let channelServiceMock: MockChannelService; @@ -21,14 +23,17 @@ describe('ChannelListComponent', () => { let queryChannels: () => ChannelPreviewComponent[]; let queryChatdownContainer: () => HTMLElement | null; let queryLoadingIndicator: () => HTMLElement | null; - let queryLoadMoreButton: () => HTMLElement | null; let queryEmptyIndicator: () => HTMLElement | null; beforeEach(() => { channelServiceMock = mockChannelService(); TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], - declarations: [ChannelListComponent, ChannelPreviewComponent], + declarations: [ + ChannelListComponent, + ChannelPreviewComponent, + PaginatedListComponent, + ], providers: [ { provide: ChannelService, useValue: channelServiceMock }, { @@ -51,9 +56,9 @@ describe('ChannelListComponent', () => { queryChatdownContainer = () => nativeElement.querySelector('[data-testid="chatdown-container"]'); queryLoadingIndicator = () => - nativeElement.querySelector('[data-testid="loading-indicator"]'); - queryLoadMoreButton = () => - nativeElement.querySelector('[data-testid="load-more"]'); + nativeElement.querySelector( + '[data-testid="loading-indicator-full-size"]' + ); queryEmptyIndicator = () => nativeElement.querySelector( '[data-testid="empty-channel-list-indicator"]' @@ -121,30 +126,38 @@ describe('ChannelListComponent', () => { expect(queryEmptyIndicator()).not.toBeNull(); }); - it('should display load more button', () => { + it('should bind #hasMore', () => { const channels = generateMockChannels(); channelServiceMock.channels$.next(channels); + fixture.detectChanges(); + const paginatedListComponent = fixture.debugElement.query( + By.directive(PaginatedListComponent) + ).componentInstance as PaginatedListComponent; channelServiceMock.hasMoreChannels$.next(false); fixture.detectChanges(); - expect(queryLoadMoreButton()).toBeNull(); + expect(paginatedListComponent.hasMore).toBeFalse(); channelServiceMock.hasMoreChannels$.next(true); fixture.detectChanges(); - expect(queryLoadMoreButton()).not.toBeNull(); + expect(paginatedListComponent.hasMore).toBeTrue(); }); - it(`should load more channels, but shouldn't loading indicator`, () => { + it(`should load more channels, but shouldn't display full-size loading indicator`, () => { const channels = generateMockChannels(); channelServiceMock.channels$.next(channels); channelServiceMock.hasMoreChannels$.next(true); spyOn(channelServiceMock, 'loadMoreChannels'); fixture.detectChanges(); - queryLoadMoreButton()?.click(); + const paginatedListComponent = fixture.debugElement.query( + By.directive(PaginatedListComponent) + ).componentInstance as PaginatedListComponent; + paginatedListComponent.loadMore.emit(); + fixture.detectChanges(); - expect(queryLoadingIndicator()).toBeNull(); expect(channelServiceMock.loadMoreChannels).toHaveBeenCalledWith(); + expect(queryLoadingIndicator()).toBeNull(); }); it('should apply dark/light theme', () => {