From cdc7a6f0e92a602373e816e16f4a2f8ee6927c5d Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Mon, 17 Apr 2017 13:05:30 +0200 Subject: [PATCH] Add TaskOverview router test --- .../src/app/blog/blog.component.spec.ts | 5 +- .../login-service/login.service.spec.ts | 5 +- .../edit-task/edit-task.component.spec.ts | 1 - .../task-list/task-overview.component.spec.ts | 48 +++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 project-manager/src/app/tasks/task-list/task-overview.component.spec.ts diff --git a/project-manager/src/app/blog/blog.component.spec.ts b/project-manager/src/app/blog/blog.component.spec.ts index e681e40..a3a8e18 100644 --- a/project-manager/src/app/blog/blog.component.spec.ts +++ b/project-manager/src/app/blog/blog.component.spec.ts @@ -1,9 +1,10 @@ import {BlogComponent} from './blog.component' -import {async, TestBed} from "@angular/core/testing"; +import {async, inject, TestBed} from "@angular/core/testing"; import {RouterTestingModule} from "@angular/router/testing"; -import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; +import {Component, CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; import {By} from "@angular/platform-browser"; import {BlogEntryComponent} from "./blog-entry/blog-entry.component";; +import {Router} from "@angular/router/router"; describe('Blog Component', () => { diff --git a/project-manager/src/app/services/login-service/login.service.spec.ts b/project-manager/src/app/services/login-service/login.service.spec.ts index 9c6d013..8fa0438 100644 --- a/project-manager/src/app/services/login-service/login.service.spec.ts +++ b/project-manager/src/app/services/login-service/login.service.spec.ts @@ -6,7 +6,10 @@ import {BaseRequestOptions, ConnectionBackend, Http, RequestMethod, ResponseOpti import {LoginService} from "./login-service"; import {UserStore} from "../stores/user.store"; - +/** + * Initialisierung und Durchführung nach Vorlage aus dem + * TaskService Tests (../task-service/task.service.spec.ts) von Christoph Höller + */ describe('Login-Service', () => { beforeEach(() => { TestBed.configureTestingModule({ diff --git a/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts b/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts index 529cdb1..72541e4 100644 --- a/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts +++ b/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts @@ -199,5 +199,4 @@ describe('EditTask Component', () => { })); }); - }); diff --git a/project-manager/src/app/tasks/task-list/task-overview.component.spec.ts b/project-manager/src/app/tasks/task-list/task-overview.component.spec.ts new file mode 100644 index 0000000..3b08404 --- /dev/null +++ b/project-manager/src/app/tasks/task-list/task-overview.component.spec.ts @@ -0,0 +1,48 @@ +import {async, TestBed} from "@angular/core/testing"; +import {Router} from "@angular/router"; +import {ReactiveFormsModule} from "@angular/forms"; +import {inject} from "@angular/core/testing"; +import {TaskListComponent} from "./task-list.component"; +import {TaskItemComponent} from "./task-item.component"; + +import {RouterTestingModule} from "@angular/router/testing"; +import {MockTaskService} from "../../mocks/mock-task-service"; +import {TaskService} from "../../services/task-service/task.service"; + + + +describe('Task Overview Component Routing', () => { + let component: TaskListComponent; + let fixture; + let router; + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ReactiveFormsModule, RouterTestingModule.withRoutes([])], + declarations: [TaskListComponent, TaskItemComponent], + providers: [ {provide: TaskService, useClass: MockTaskService} + ] + }); + fixture = TestBed.createComponent(TaskListComponent); + component = fixture.componentInstance; + })); + + beforeEach(inject([Router], + (_router) => { + router = _router; + }) + ); + + it('should call Router.navigate with id to open quickedit ',() => { + fixture.whenStable().then(() => { + let taskId = 12; + + let spyNavigation = spyOn(router, 'navigate'); + + component.selectTask(taskId); + expect(spyNavigation).toHaveBeenCalled(); + expect(spyNavigation.calls.first().args[0]) + .toContain({outlets: {'right': ['overview', taskId]}}); + }); + }); + +});