From e17a0a932d1789dea8819e6e132a2cc5f271b9e3 Mon Sep 17 00:00:00 2001 From: DominikIwanek Date: Thu, 31 Aug 2023 16:05:16 +0200 Subject: [PATCH] [ACS-5932] - Sidenav not able to expand when search page is closed --- .../search/search-input/search-input.component.spec.ts | 8 ++++---- .../search/search-input/search-input.component.ts | 4 ++-- .../search-libraries-results.component.spec.ts | 7 ++++--- .../search-libraries-results.component.ts | 2 +- .../search-results/search-results.component.spec.ts | 3 ++- .../src/lib/components/sidenav/sidenav.component.spec.ts | 3 ++- .../src/lib/components/sidenav/sidenav.component.ts | 4 ++-- projects/aca-shared/src/lib/services/app.service.ts | 5 +++++ 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts b/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts index 999a114a15..730cbe15e0 100644 --- a/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts @@ -42,10 +42,12 @@ describe('SearchInputComponent', () => { let searchInputService: SearchNavigationService; const appServiceMock = { appNavNarMode$: new BehaviorSubject('collapsed'), + setAppNavbarMode: jasmine.createSpy('setAppNavbarMode'), toggleAppNavBar$: new Subject() }; beforeEach(() => { + appServiceMock.setAppNavbarMode.calls.reset(); TestBed.configureTestingModule({ imports: [AppTestingModule, SearchInputComponent], providers: [ @@ -70,10 +72,9 @@ describe('SearchInputComponent', () => { }); it('should collapsed sidenav by default', () => { - spyOn(appServiceMock.appNavNarMode$, 'next'); component.ngOnInit(); - expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('collapsed'); + expect(appServiceMock.setAppNavbarMode).toHaveBeenCalledWith('collapsed'); }); it('should change flag on library400Error event', async () => { @@ -244,9 +245,8 @@ describe('SearchInputComponent', () => { }); it('should sidenav expanded after the component is destroy', () => { - spyOn(appServiceMock.appNavNarMode$, 'next'); component.ngOnDestroy(); - expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('expanded'); + expect(appServiceMock.setAppNavbarMode).toHaveBeenCalledWith('expanded'); }); }); diff --git a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts index c3147acc41..0aa5d5b985 100644 --- a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts +++ b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts @@ -139,7 +139,7 @@ export class SearchInputComponent implements OnInit, OnDestroy { } showInputValue() { - this.appService.appNavNarMode$.next('collapsed'); + this.appService.setAppNavbarMode('collapsed'); this.has400LibraryError = false; this.hasLibrariesConstraint = this.evaluateLibrariesConstraint(); this.searchedWord = this.getUrlSearchTerm(); @@ -150,7 +150,7 @@ export class SearchInputComponent implements OnInit, OnDestroy { } ngOnDestroy(): void { - this.appService.appNavNarMode$.next('expanded'); + this.appService.setAppNavbarMode('expanded'); this.onDestroy$.next(true); this.onDestroy$.complete(); this.removeContentFilters(); diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts index 5ca800f3e1..c340eb9a61 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts @@ -37,10 +37,12 @@ describe('SearchLibrariesResultsComponent', () => { const emptyPage = { list: { pagination: { totalItems: 0 }, entries: [] } }; const appServiceMock = { appNavNarMode$: new BehaviorSubject('collapsed'), - toggleAppNavBar$: new Subject() + toggleAppNavBar$: new Subject(), + setAppNavbarMode: jasmine.createSpy('setAppNavbarMode') }; beforeEach(() => { + appServiceMock.setAppNavbarMode.calls.reset(); TestBed.configureTestingModule({ imports: [AppTestingModule, SearchLibrariesResultsComponent], schemas: [NO_ERRORS_SCHEMA], @@ -65,9 +67,8 @@ describe('SearchLibrariesResultsComponent', () => { }); it('should collapsed sidenav by default', () => { - spyOn(appServiceMock.appNavNarMode$, 'next'); component.ngOnInit(); - expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('collapsed'); + expect(appServiceMock.setAppNavbarMode).toHaveBeenCalledWith('collapsed'); }); }); diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts index 29b39fe6a4..145f5501f0 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts @@ -92,7 +92,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On } ngOnInit() { - this.appService.appNavNarMode$.next('collapsed'); + this.appService.setAppNavbarMode('collapsed'); super.ngOnInit(); this.columns = this.extensions.documentListPresets.searchLibraries || []; diff --git a/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts b/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts index 3fba9d2320..2229e648e5 100644 --- a/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts @@ -54,7 +54,8 @@ describe('SearchComponent', () => { provide: AppService, useValue: { appNavNarMode$: new BehaviorSubject('expanded'), - toggleAppNavBar$: new Subject() + toggleAppNavBar$: new Subject(), + setAppNavbarMode: jasmine.createSpy('setAppNavbarMode') } }, { diff --git a/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts b/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts index 5ee56dcb33..0d89fbec4d 100644 --- a/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts +++ b/projects/aca-content/src/lib/components/sidenav/sidenav.component.spec.ts @@ -44,7 +44,8 @@ describe('SidenavComponent', () => { provide: AppService, useValue: { appNavNarMode$: new BehaviorSubject('expanded'), - toggleAppNavBar$: new Subject() + toggleAppNavBar$: new Subject(), + setAppNavbarMode: jasmine.createSpy('setAppNavbarMode') } }, SidenavLayoutComponent diff --git a/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts b/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts index 993da2b0f5..4376f186d1 100755 --- a/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts +++ b/projects/aca-content/src/lib/components/sidenav/sidenav.component.ts @@ -64,7 +64,7 @@ export class SidenavComponent implements OnInit, OnDestroy { this.groups = this.extensions.getApplicationNavigation(this.extensions.navbar); }); - this.appService.appNavNarMode$.next(this.data.mode); + this.appService.setAppNavbarMode(this.data.mode); this.appService.toggleAppNavBar$.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.toggleNavBar()); this.data.layout.expanded.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.setNavBarMode()); } @@ -82,7 +82,7 @@ export class SidenavComponent implements OnInit, OnDestroy { } private setNavBarMode() { - this.appService.appNavNarMode$.next(this.data.layout.isMenuMinimized || this.data.layout.isHeaderInside ? 'collapsed' : 'expanded'); + this.appService.setAppNavbarMode(this.data.layout.isMenuMinimized || this.data.layout.isHeaderInside ? 'collapsed' : 'expanded'); } private toggleNavBar() { diff --git a/projects/aca-shared/src/lib/services/app.service.ts b/projects/aca-shared/src/lib/services/app.service.ts index fc46d3cfbe..7fdf78994b 100644 --- a/projects/aca-shared/src/lib/services/app.service.ts +++ b/projects/aca-shared/src/lib/services/app.service.ts @@ -174,6 +174,11 @@ export class AppService implements OnDestroy { this.overlayContainer.getContainerElement().setAttribute('role', 'region'); } + setAppNavbarMode(mode: 'expanded' | 'collapsed'): void { + this.appNavNarMode$.next(mode); + this.preferencesService.set('expandedSidenav', mode === 'expanded'); + } + private loadRepositoryStatus() { this.contentApi.getRepositoryInformation().subscribe((response: DiscoveryEntry) => { if (response?.entry?.repository) {