TSK-1629: corrected nav-bar for workplace

and added tests
This commit is contained in:
Tristan 2022-01-24 18:48:55 +01:00 committed by Tristan2357
parent 38edeb208e
commit fd6a57dad3
4 changed files with 73 additions and 29 deletions

View File

@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { Component, DebugElement } from '@angular/core'; import { Component, DebugElement } from '@angular/core';
import { NavBarComponent } from './nav-bar.component'; import { NavBarComponent } from './nav-bar.component';
import { SelectedRouteService } from '../../services/selected-route/selected-route'; import { SelectedRouteService } from '../../services/selected-route/selected-route';
@ -28,16 +28,18 @@ describe('NavBarComponent', () => {
let debugElement: DebugElement; let debugElement: DebugElement;
let route = ''; let route = '';
beforeEach(async(() => { beforeEach(
TestBed.configureTestingModule({ waitForAsync(() => {
declarations: [NavBarComponent, SvgIconStub], TestBed.configureTestingModule({
imports: [MatIconModule, HttpClientTestingModule, MatToolbarModule], declarations: [NavBarComponent, SvgIconStub],
providers: [ imports: [MatIconModule, HttpClientTestingModule, MatToolbarModule],
{ provide: SidenavService, useValue: SidenavServiceSpy }, providers: [
{ provide: SelectedRouteService, useValue: SelectedRouteServiceSpy } { provide: SidenavService, useValue: SidenavServiceSpy },
] { provide: SelectedRouteService, useValue: SelectedRouteServiceSpy }
}).compileComponents(); ]
})); }).compileComponents();
})
);
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(NavBarComponent); fixture = TestBed.createComponent(NavBarComponent);
@ -57,6 +59,48 @@ describe('NavBarComponent', () => {
expect(component.title).toBe('Workbaskets'); expect(component.title).toBe('Workbaskets');
}); });
it('should set title to classification if classification ist selected', () => {
route = 'classifications';
fixture.detectChanges();
component.setTitle(route);
expect(component.title).toBe('Classifications');
});
it('should set title to monitor if monitor ist selected', () => {
route = 'monitor';
fixture.detectChanges();
component.setTitle(route);
expect(component.title).toBe('Monitor');
});
it('should set title to workplace if workplace ist selected', () => {
route = 'workplace';
fixture.detectChanges();
component.setTitle(route);
expect(component.title).toBe('Workplace');
});
it('should set title to access-items if access-items ist selected', () => {
route = 'access-items';
fixture.detectChanges();
component.setTitle(route);
expect(component.title).toBe('Access items');
});
it('should set title to history if history ist selected', () => {
route = 'history';
fixture.detectChanges();
component.setTitle(route);
expect(component.title).toBe('History');
});
it('should set title to settings if settings ist selected', () => {
route = 'settings';
fixture.detectChanges();
component.setTitle(route);
expect(component.title).toBe('Settings');
});
it('should toggle sidenav when button clicked', () => { it('should toggle sidenav when button clicked', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(component.toggle).toBe(false); expect(component.toggle).toBe(false);

View File

@ -40,19 +40,19 @@ export class NavBarComponent implements OnInit {
} }
setTitle(value: string = '') { setTitle(value: string = '') {
if (value.indexOf('workbaskets') === 0) { if (value.includes('workbaskets')) {
this.title = this.titleWorkbaskets; this.title = this.titleWorkbaskets;
} else if (value.indexOf('classifications') === 0) { } else if (value.includes('classifications')) {
this.title = this.titleClassifications; this.title = this.titleClassifications;
} else if (value.indexOf('monitor') === 0) { } else if (value.includes('monitor')) {
this.title = this.titleMonitor; this.title = this.titleMonitor;
} else if (value.indexOf('workplace') === 0) { } else if (value.includes('workplace')) {
this.title = this.titleWorkplace; this.title = this.titleWorkplace;
} else if (value.indexOf('access-items') === 0) { } else if (value.includes('access-items')) {
this.title = this.titleAccessItems; this.title = this.titleAccessItems;
} else if (value.indexOf('history') === 0) { } else if (value.includes('history')) {
this.title = this.titleHistory; this.title = this.titleHistory;
} else if (value.indexOf('settings') === 0) { } else if (value.includes('settings')) {
this.title = this.titleSettings; this.title = this.titleSettings;
} }
} }

View File

@ -1,8 +1,7 @@
import { TestBed, inject } from '@angular/core/testing'; import { inject, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { AccessIdsService } from './access-ids.service'; import { AccessIdsService } from './access-ids.service';
import { SelectedRouteService } from '../selected-route/selected-route';
import { StartupService } from '../startup/startup.service'; import { StartupService } from '../startup/startup.service';
import { TaskanaEngineService } from '../taskana-engine/taskana-engine.service'; import { TaskanaEngineService } from '../taskana-engine/taskana-engine.service';
import { WindowRefService } from '../window/window.service'; import { WindowRefService } from '../window/window.service';

View File

@ -1,18 +1,19 @@
import { Injectable, OnInit } from '@angular/core'; import { Injectable } from '@angular/core';
import { Subject, Observable } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import { Router, ActivatedRoute, NavigationStart } from '@angular/router'; import { Router } from '@angular/router';
@Injectable() @Injectable()
export class SelectedRouteService { export class SelectedRouteService {
public selectedRouteTriggered = new Subject<string>(); public selectedRouteTriggered = new Subject<string>();
private detailRoutes: Array<string> = [ private detailRoutes: Array<string> = [
'workbaskets',
'classifications',
'monitor',
'workplace', 'workplace',
'access-items-management', 'administration/workbaskets',
'history' 'administration/classifications',
'monitor',
'administration/access-items-management',
'history',
'settings'
]; ];
constructor(private router: Router) {} constructor(private router: Router) {}
@ -33,6 +34,6 @@ export class SelectedRouteService {
} }
private checkUrl(url: string): string { private checkUrl(url: string): string {
return this.detailRoutes.find((routeDetail) => url.indexOf(routeDetail) !== -1) || ''; return this.detailRoutes.find((routeDetail) => url.includes(routeDetail)) || '';
} }
} }