Skip to content

Commit

Permalink
[ACS-5932] - Sidenav not able to expand when search page is closed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikiwanekhyland committed Sep 5, 2023
1 parent 4a8faea commit 46ea854
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ describe('SearchComponent', () => {
provide: AppService,
useValue: {
appNavNarMode$: new BehaviorSubject('expanded'),
toggleAppNavBar$: new Subject()
toggleAppNavBar$: new Subject(),
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode')
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('SidenavComponent', () => {
provide: AppService,
useValue: {
appNavNarMode$: new BehaviorSubject('expanded'),
toggleAppNavBar$: new Subject()
toggleAppNavBar$: new Subject(),
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode')
}
},
SidenavLayoutComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions projects/aca-shared/src/lib/services/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 46ea854

Please sign in to comment.