mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
68067: Route data menu sections - tests
This commit is contained in:
@@ -13,6 +13,8 @@ import { AuthService } from '../../core/auth/auth.service';
|
|||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
describe('AdminSidebarComponent', () => {
|
describe('AdminSidebarComponent', () => {
|
||||||
let comp: AdminSidebarComponent;
|
let comp: AdminSidebarComponent;
|
||||||
@@ -21,13 +23,14 @@ describe('AdminSidebarComponent', () => {
|
|||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), NoopAnimationsModule],
|
imports: [TranslateModule.forRoot(), NoopAnimationsModule, RouterTestingModule],
|
||||||
declarations: [AdminSidebarComponent],
|
declarations: [AdminSidebarComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: Injector, useValue: {} },
|
{ provide: Injector, useValue: {} },
|
||||||
{ provide: MenuService, useValue: menuService },
|
{ provide: MenuService, useValue: menuService },
|
||||||
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
|
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
|
||||||
{ provide: AuthService, useClass: AuthServiceStub },
|
{ provide: AuthService, useClass: AuthServiceStub },
|
||||||
|
{ provide: ActivatedRoute, useValue: {} },
|
||||||
{
|
{
|
||||||
provide: NgbModal, useValue: {
|
provide: NgbModal, useValue: {
|
||||||
open: () => {/*comment*/}
|
open: () => {/*comment*/}
|
||||||
|
@@ -11,6 +11,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|||||||
import { Injector, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { Injector, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { MenuService } from '../shared/menu/menu.service';
|
import { MenuService } from '../shared/menu/menu.service';
|
||||||
import { MenuServiceStub } from '../shared/testing/menu-service.stub';
|
import { MenuServiceStub } from '../shared/testing/menu-service.stub';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
|
||||||
let comp: NavbarComponent;
|
let comp: NavbarComponent;
|
||||||
let fixture: ComponentFixture<NavbarComponent>;
|
let fixture: ComponentFixture<NavbarComponent>;
|
||||||
@@ -24,12 +26,14 @@ describe('NavbarComponent', () => {
|
|||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
NoopAnimationsModule,
|
NoopAnimationsModule,
|
||||||
ReactiveFormsModule],
|
ReactiveFormsModule,
|
||||||
|
RouterTestingModule],
|
||||||
declarations: [NavbarComponent],
|
declarations: [NavbarComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: Injector, useValue: {} },
|
{ provide: Injector, useValue: {} },
|
||||||
{ provide: MenuService, useValue: menuService },
|
{ provide: MenuService, useValue: menuService },
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
||||||
|
{ provide: ActivatedRoute, useValue: {} }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
})
|
})
|
||||||
|
@@ -7,19 +7,65 @@ import { MenuComponent } from './menu.component';
|
|||||||
import { MenuServiceStub } from '../testing/menu-service.stub';
|
import { MenuServiceStub } from '../testing/menu-service.stub';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { MenuSection } from './menu.reducer';
|
import { MenuSection } from './menu.reducer';
|
||||||
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { MenuItemType } from './initial-menus-state';
|
||||||
|
import { LinkMenuItemModel } from './menu-item/models/link.model';
|
||||||
|
|
||||||
describe('MenuComponent', () => {
|
fdescribe('MenuComponent', () => {
|
||||||
let comp: MenuComponent;
|
let comp: MenuComponent;
|
||||||
let fixture: ComponentFixture<MenuComponent>;
|
let fixture: ComponentFixture<MenuComponent>;
|
||||||
let menuService: MenuService;
|
let menuService: MenuService;
|
||||||
|
let routeDataMenuSection: MenuSection;
|
||||||
|
let routeDataMenuChildSection: MenuSection;
|
||||||
|
let route: any;
|
||||||
|
let router: any;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
|
routeDataMenuSection = {
|
||||||
|
id: 'mockSection',
|
||||||
|
active: false,
|
||||||
|
visible: true,
|
||||||
|
model: {
|
||||||
|
type: MenuItemType.LINK,
|
||||||
|
text: 'menu.section.mockSection',
|
||||||
|
link: ''
|
||||||
|
} as LinkMenuItemModel
|
||||||
|
};
|
||||||
|
routeDataMenuChildSection = {
|
||||||
|
id: 'mockChildSection',
|
||||||
|
parentID: 'mockSection',
|
||||||
|
active: false,
|
||||||
|
visible: true,
|
||||||
|
model: {
|
||||||
|
type: MenuItemType.LINK,
|
||||||
|
text: 'menu.section.mockChildSection',
|
||||||
|
link: ''
|
||||||
|
} as LinkMenuItemModel
|
||||||
|
};
|
||||||
|
route = {
|
||||||
|
root: {
|
||||||
|
snapshot: {
|
||||||
|
data: {
|
||||||
|
menu: routeDataMenuSection
|
||||||
|
}
|
||||||
|
},
|
||||||
|
firstChild: {
|
||||||
|
snapshot: {
|
||||||
|
data: {
|
||||||
|
menu: routeDataMenuChildSection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), NoopAnimationsModule],
|
imports: [TranslateModule.forRoot(), NoopAnimationsModule, RouterTestingModule],
|
||||||
declarations: [MenuComponent],
|
declarations: [MenuComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: Injector, useValue: {} },
|
{ provide: Injector, useValue: {} },
|
||||||
{ provide: MenuService, useClass: MenuServiceStub },
|
{ provide: MenuService, useClass: MenuServiceStub },
|
||||||
|
{ provide: ActivatedRoute, useValue: route }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).overrideComponent(MenuComponent, {
|
}).overrideComponent(MenuComponent, {
|
||||||
@@ -31,11 +77,36 @@ describe('MenuComponent', () => {
|
|||||||
fixture = TestBed.createComponent(MenuComponent);
|
fixture = TestBed.createComponent(MenuComponent);
|
||||||
comp = fixture.componentInstance; // SearchPageComponent test instance
|
comp = fixture.componentInstance; // SearchPageComponent test instance
|
||||||
menuService = (comp as any).menuService;
|
menuService = (comp as any).menuService;
|
||||||
|
router = TestBed.get(Router);
|
||||||
spyOn(comp as any, 'getSectionDataInjector').and.returnValue(MenuSection);
|
spyOn(comp as any, 'getSectionDataInjector').and.returnValue(MenuSection);
|
||||||
spyOn(comp as any, 'getSectionComponent').and.returnValue(observableOf({}));
|
spyOn(comp as any, 'getSectionComponent').and.returnValue(observableOf({}));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ngOnInit', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'resolveMenuSections').and.returnValue([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call resolveMenuSections on init', () => {
|
||||||
|
router.events = observableOf(new NavigationEnd(0, '', ''));
|
||||||
|
comp.ngOnInit();
|
||||||
|
expect(comp.resolveMenuSections).toHaveBeenCalledWith(route.root);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('resolveMenuSections', () => {
|
||||||
|
let result: MenuSection[];
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
result = comp.resolveMenuSections(route.root);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the current route\'s menu sections', () => {
|
||||||
|
expect(result).toEqual([routeDataMenuSection, routeDataMenuChildSection])
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('toggle', () => {
|
describe('toggle', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(menuService, 'toggleMenu');
|
spyOn(menuService, 'toggleMenu');
|
||||||
|
@@ -1,15 +1,14 @@
|
|||||||
import { ChangeDetectionStrategy, Component, Injector, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, Injector, OnInit } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { MenuService } from '../../shared/menu/menu.service';
|
import { MenuService } from './menu.service';
|
||||||
import { MenuID } from '../../shared/menu/initial-menus-state';
|
import { MenuID } from './initial-menus-state';
|
||||||
import { MenuSection } from '../../shared/menu/menu.reducer';
|
import { MenuSection } from './menu.reducer';
|
||||||
import { distinctUntilChanged, filter, first, map, switchMap, tap } from 'rxjs/operators';
|
import { distinctUntilChanged, filter, first, map, tap } from 'rxjs/operators';
|
||||||
import { GenericConstructor } from '../../core/shared/generic-constructor';
|
import { GenericConstructor } from '../../core/shared/generic-constructor';
|
||||||
import { hasNoValue, hasValue } from '../empty.util';
|
import { hasNoValue, hasValue } from '../empty.util';
|
||||||
import { MenuSectionComponent } from './menu-section/menu-section.component';
|
import { MenuSectionComponent } from './menu-section/menu-section.component';
|
||||||
import { getComponentForMenu } from './menu-section.decorator';
|
import { getComponentForMenu } from './menu-section.decorator';
|
||||||
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||||
import { of as observableOf } from 'rxjs/internal/observable/of';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic implementation of a MenuComponent
|
* A basic implementation of a MenuComponent
|
||||||
|
@@ -59,6 +59,9 @@ export class MenuServiceStub {
|
|||||||
removeSection(): void { /***/
|
removeSection(): void { /***/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
resetSections(): void { /***/
|
||||||
|
};
|
||||||
|
|
||||||
isMenuVisible(id: MenuID): Observable<boolean> {
|
isMenuVisible(id: MenuID): Observable<boolean> {
|
||||||
return observableOf(true)
|
return observableOf(true)
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user