mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
68067: Route menu data - menu ID
This commit is contained in:
@@ -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);
|
||||||
|
@@ -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]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user