68067: Route menu data - menu ID

This commit is contained in:
Kristof De Langhe
2020-05-19 17:34:56 +02:00
parent 8761d0ac27
commit 79eecc7c76
2 changed files with 13 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ import { of as observableOf } from 'rxjs';
import { MenuSection } from './menu.reducer'; import { MenuSection } from './menu.reducer';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { MenuItemType } from './initial-menus-state'; import { MenuID, MenuItemType } from './initial-menus-state';
import { LinkMenuItemModel } from './menu-item/models/link.model'; import { LinkMenuItemModel } from './menu-item/models/link.model';
describe('MenuComponent', () => { describe('MenuComponent', () => {
@@ -21,6 +21,8 @@ describe('MenuComponent', () => {
let route: any; let route: any;
let router: any; let router: any;
const mockMenuID = 'mock-menuID' as MenuID;
beforeEach(async(() => { beforeEach(async(() => {
routeDataMenuSection = { routeDataMenuSection = {
id: 'mockSection', id: 'mockSection',
@@ -47,13 +49,17 @@ describe('MenuComponent', () => {
root: { root: {
snapshot: { snapshot: {
data: { data: {
menu: routeDataMenuSection menu: {
[mockMenuID]: routeDataMenuSection
}
} }
}, },
firstChild: { firstChild: {
snapshot: { snapshot: {
data: { data: {
menu: routeDataMenuChildSection menu: {
[mockMenuID]: routeDataMenuChildSection
}
} }
} }
} }
@@ -76,6 +82,7 @@ describe('MenuComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(MenuComponent); fixture = TestBed.createComponent(MenuComponent);
comp = fixture.componentInstance; // SearchPageComponent test instance comp = fixture.componentInstance; // SearchPageComponent test instance
comp.menuID = mockMenuID;
menuService = (comp as any).menuService; menuService = (comp as any).menuService;
router = TestBed.get(Router); router = TestBed.get(Router);
spyOn(comp as any, 'getSectionDataInjector').and.returnValue(MenuSection); spyOn(comp as any, 'getSectionDataInjector').and.returnValue(MenuSection);

View File

@@ -125,11 +125,11 @@ export class MenuComponent implements OnInit, OnDestroy {
const data = route.snapshot.data; const data = route.snapshot.data;
const last: boolean = hasNoValue(route.firstChild); const last: boolean = hasNoValue(route.firstChild);
if (hasValue(data) && hasValue(data.menu)) { if (hasValue(data) && hasValue(data.menu) && hasValue(data.menu[this.menuID])) {
if (!last) { if (!last) {
return [...data.menu, ...this.resolveMenuSections(route.firstChild)] return [...data.menu[this.menuID], ...this.resolveMenuSections(route.firstChild)]
} else { } else {
return [...data.menu]; return [...data.menu[this.menuID]];
} }
} }