mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[MNT-25423] Prevent minimizing menu again when previous and current route contain minimize URL (#11345)
* [MNT-25423] Prevent minimizing menu again when previous and current route contain minimize URL * [MNT-25423] Remove unnecessary spy
This commit is contained in:
@@ -18,29 +18,19 @@
|
|||||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||||
import { AppConfigService } from '@alfresco/adf-core';
|
import { AppConfigService } from '@alfresco/adf-core';
|
||||||
import { ShellLayoutComponent } from './shell.component';
|
import { ShellLayoutComponent } from './shell.component';
|
||||||
import { Router, NavigationStart, RouterModule } from '@angular/router';
|
import { provideRouter, RouterModule } from '@angular/router';
|
||||||
import { of, Subject } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { ShellAppService, SHELL_APP_SERVICE } from '../../services/shell-app.service';
|
import { ShellAppService, SHELL_APP_SERVICE } from '../../services/shell-app.service';
|
||||||
|
import { RouterTestingHarness } from '@angular/router/testing';
|
||||||
class MockRouter {
|
|
||||||
private url = 'some-url';
|
|
||||||
private subject = new Subject();
|
|
||||||
events = this.subject.asObservable();
|
|
||||||
routerState = { snapshot: { url: this.url } };
|
|
||||||
|
|
||||||
navigateByUrl(url: string) {
|
|
||||||
const navigationStart = new NavigationStart(0, url);
|
|
||||||
this.subject.next(navigationStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('AppLayoutComponent', () => {
|
describe('AppLayoutComponent', () => {
|
||||||
let fixture: ComponentFixture<ShellLayoutComponent>;
|
let fixture: ComponentFixture<ShellLayoutComponent>;
|
||||||
let component: ShellLayoutComponent;
|
let component: ShellLayoutComponent;
|
||||||
let appConfig: AppConfigService;
|
let appConfig: AppConfigService;
|
||||||
let shellAppService: ShellAppService;
|
let shellAppService: ShellAppService;
|
||||||
|
let routerHarness: RouterTestingHarness;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
const shellService: ShellAppService = {
|
const shellService: ShellAppService = {
|
||||||
pageHeading$: of('Title'),
|
pageHeading$: of('Title'),
|
||||||
hideSidenavConditions: [],
|
hideSidenavConditions: [],
|
||||||
@@ -54,14 +44,11 @@ describe('AppLayoutComponent', () => {
|
|||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [RouterModule.forChild([]), ShellLayoutComponent],
|
imports: [RouterModule.forChild([]), ShellLayoutComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
|
||||||
provide: Router,
|
|
||||||
useClass: MockRouter
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
provide: SHELL_APP_SERVICE,
|
provide: SHELL_APP_SERVICE,
|
||||||
useValue: shellService
|
useValue: shellService
|
||||||
}
|
},
|
||||||
|
provideRouter([{ path: 'minimize', component: ShellLayoutComponent }])
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,6 +56,7 @@ describe('AppLayoutComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
appConfig = TestBed.inject(AppConfigService);
|
appConfig = TestBed.inject(AppConfigService);
|
||||||
shellAppService = TestBed.inject(SHELL_APP_SERVICE);
|
shellAppService = TestBed.inject(SHELL_APP_SERVICE);
|
||||||
|
routerHarness = await RouterTestingHarness.create();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -163,4 +151,43 @@ describe('AppLayoutComponent', () => {
|
|||||||
|
|
||||||
expect(component.layout.container.toggleMenu).toHaveBeenCalled();
|
expect(component.layout.container.toggleMenu).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should minimize menu when navigates to minimize url', async () => {
|
||||||
|
shellAppService.minimizeSidenavConditions = ['/minimize'];
|
||||||
|
component.layout.container = {
|
||||||
|
isMobileScreenSize: false,
|
||||||
|
isMenuMinimized: false,
|
||||||
|
toggleMenu: () => {}
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(component.layout.container, 'toggleMenu');
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await routerHarness.navigateByUrl('/minimize');
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.minimizeSidenav).toBeTrue();
|
||||||
|
expect(component.layout.isMenuMinimized).toBeTrue();
|
||||||
|
expect(component.layout.container.toggleMenu).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not minimize menu again when previous and current route contain minimize url', async () => {
|
||||||
|
shellAppService.minimizeSidenavConditions = ['/minimize'];
|
||||||
|
component.layout.container = {
|
||||||
|
isMobileScreenSize: false,
|
||||||
|
isMenuMinimized: false,
|
||||||
|
toggleMenu: () => {}
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await routerHarness.navigateByUrl('/minimize?query=123');
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.minimizeSidenav).toBeTrue();
|
||||||
|
|
||||||
|
await routerHarness.navigateByUrl('/minimize?query=456');
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.minimizeSidenav).toBeFalse();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -102,7 +102,11 @@ export class ShellLayoutComponent implements OnInit {
|
|||||||
takeUntilDestroyed(this.destroyRef)
|
takeUntilDestroyed(this.destroyRef)
|
||||||
)
|
)
|
||||||
.subscribe((event: NavigationEnd) => {
|
.subscribe((event: NavigationEnd) => {
|
||||||
this.minimizeSidenav = this.shellService.minimizeSidenavConditions.some((el) => event.urlAfterRedirects.includes(el));
|
this.minimizeSidenav = this.shellService.minimizeSidenavConditions.some((el) => {
|
||||||
|
const previousNavigation = this.router.getCurrentNavigation()?.previousNavigation?.finalUrl;
|
||||||
|
const previousPath = previousNavigation ? this.router.serializeUrl(previousNavigation) : '';
|
||||||
|
return event.urlAfterRedirects.includes(el) && !previousPath.includes(el);
|
||||||
|
});
|
||||||
this.hideSidenav = this.shellService.hideSidenavConditions.some((el) => event.urlAfterRedirects.includes(el));
|
this.hideSidenav = this.shellService.hideSidenavConditions.some((el) => event.urlAfterRedirects.includes(el));
|
||||||
|
|
||||||
this.updateState();
|
this.updateState();
|
||||||
|
|||||||
Reference in New Issue
Block a user