Add TaskOverview router test

unit-test
Florian Hartwich 2017-04-17 13:05:30 +02:00
parent 89f5b2d1ab
commit cdc7a6f0e9
4 changed files with 55 additions and 4 deletions

View File

@ -1,9 +1,10 @@
import {BlogComponent} from './blog.component' 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 {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 {By} from "@angular/platform-browser";
import {BlogEntryComponent} from "./blog-entry/blog-entry.component";; import {BlogEntryComponent} from "./blog-entry/blog-entry.component";;
import {Router} from "@angular/router/router";
describe('Blog Component', () => { describe('Blog Component', () => {

View File

@ -6,7 +6,10 @@ import {BaseRequestOptions, ConnectionBackend, Http, RequestMethod, ResponseOpti
import {LoginService} from "./login-service"; import {LoginService} from "./login-service";
import {UserStore} from "../stores/user.store"; 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', () => { describe('Login-Service', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({

View File

@ -199,5 +199,4 @@ describe('EditTask Component', () => {
})); }));
}); });
}); });

View File

@ -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]}});
});
});
});