mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-10-01 14:41:14 +00:00
[ACS-8779] Keep selections and question after going to the previous page (#4147)
This commit is contained in:
@@ -26,17 +26,22 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { SidenavComponent } from './sidenav.component';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
import { AppExtensionService, AppService } from '@alfresco/aca-shared';
|
||||
import { AppExtensionService, AppService, NavigationHistoryService } from '@alfresco/aca-shared';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import { SidenavLayoutComponent } from '@alfresco/adf-core';
|
||||
import { NavigationEnd } from '@angular/router';
|
||||
|
||||
describe('SidenavComponent', () => {
|
||||
let fixture: ComponentFixture<SidenavComponent>;
|
||||
let component: SidenavComponent;
|
||||
let extensionService: AppExtensionService;
|
||||
let sidenavLayoutComponent: SidenavLayoutComponent;
|
||||
let navigationHistoryService: jasmine.SpyObj<NavigationHistoryService>;
|
||||
let routerEvents$: Subject<NavigationEnd>;
|
||||
|
||||
beforeEach(() => {
|
||||
const navigationHistoryServiceSpy = jasmine.createSpyObj('NavigationHistoryService', ['listenToRouteChanges', 'setHistory']);
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule, SidenavComponent],
|
||||
providers: [
|
||||
@@ -48,6 +53,7 @@ describe('SidenavComponent', () => {
|
||||
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode')
|
||||
}
|
||||
},
|
||||
{ provide: NavigationHistoryService, useValue: navigationHistoryServiceSpy },
|
||||
SidenavLayoutComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
@@ -73,6 +79,11 @@ describe('SidenavComponent', () => {
|
||||
component.data = {
|
||||
layout: sidenavLayoutComponent
|
||||
};
|
||||
|
||||
navigationHistoryService = TestBed.inject(NavigationHistoryService) as jasmine.SpyObj<NavigationHistoryService>;
|
||||
|
||||
routerEvents$ = new Subject<NavigationEnd>();
|
||||
navigationHistoryService.listenToRouteChanges.and.returnValue(routerEvents$.asObservable());
|
||||
});
|
||||
|
||||
it('should set the sidenav data', async () => {
|
||||
@@ -89,4 +100,13 @@ describe('SidenavComponent', () => {
|
||||
title: 'item-1'
|
||||
});
|
||||
});
|
||||
|
||||
it('should call setHistory when a NavigationEnd event occurs', () => {
|
||||
const mockNavigationEnd = new NavigationEnd(1, '/path', '/redirect');
|
||||
|
||||
component.ngOnInit();
|
||||
routerEvents$.next(mockNavigationEnd);
|
||||
|
||||
expect(navigationHistoryService.setHistory).toHaveBeenCalledWith(mockNavigationEnd, 3);
|
||||
});
|
||||
});
|
||||
|
@@ -28,12 +28,13 @@ import { Store } from '@ngrx/store';
|
||||
import { AppStore, getSideNavState } from '@alfresco/aca-shared/store';
|
||||
import { Subject } from 'rxjs';
|
||||
import { takeUntil, distinctUntilChanged, debounceTime } from 'rxjs/operators';
|
||||
import { AppExtensionService, AppService } from '@alfresco/aca-shared';
|
||||
import { AppExtensionService, AppService, NavigationHistoryService } from '@alfresco/aca-shared';
|
||||
import { SidenavLayoutComponent } from '@alfresco/adf-core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { SidenavHeaderComponent } from './components/sidenav-header.component';
|
||||
import { MatListModule } from '@angular/material/list';
|
||||
import { ExpandMenuComponent } from './components/expand-menu.component';
|
||||
import { NavigationEnd } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
@@ -54,7 +55,12 @@ export class SidenavComponent implements OnInit, OnDestroy {
|
||||
groups: Array<NavBarGroupRef> = [];
|
||||
private onDestroy$ = new Subject<boolean>();
|
||||
|
||||
constructor(private store: Store<AppStore>, private extensions: AppExtensionService, private appService: AppService) {}
|
||||
constructor(
|
||||
private store: Store<AppStore>,
|
||||
private extensions: AppExtensionService,
|
||||
private appService: AppService,
|
||||
private navigationHistoryService: NavigationHistoryService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.store
|
||||
@@ -67,6 +73,12 @@ export class SidenavComponent implements OnInit, OnDestroy {
|
||||
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());
|
||||
this.navigationHistoryService
|
||||
.listenToRouteChanges()
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe((event: NavigationEnd) => {
|
||||
this.navigationHistoryService.setHistory(event, 3);
|
||||
});
|
||||
}
|
||||
|
||||
trackByGroupId(_: number, obj: NavBarGroupRef): string {
|
||||
|
Reference in New Issue
Block a user