Encapsulate Test Suites for better readability

merge-requests/1/head
Florian Hartwich 2017-04-12 19:37:52 +02:00
parent d29c16005e
commit ad73633ae8
6 changed files with 157 additions and 149 deletions

View File

@ -6,6 +6,7 @@ import {RouterTestingModule} from "@angular/router/testing";
describe('Blog Entry Isolated Test', () => { describe('Blog Entry Isolated Test', () => {
describe('Isolated Test', () => {
it('should render DOM correctly according to Input', () => { it('should render DOM correctly according to Input', () => {
// Umgebung initialisieren // Umgebung initialisieren
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@ -55,10 +56,10 @@ describe('Blog Entry Isolated Test', () => {
// nur durch click-Event auslösen, was jedoch BlogComponent vorraussetzt // nur durch click-Event auslösen, was jedoch BlogComponent vorraussetzt
}); });
});
});
describe('BlogEntryComp -> BlogComp Dependent Test', () => { describe('BlogEntryComp -> BlogComp Dependent Test', () => {
it('should remove entry from BlogComponent on "delete" button click', () => { it('should remove entry from BlogComponent on "delete" button click', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@ -81,4 +82,8 @@ describe('BlogEntryComp -> BlogComp Dependent Test', () => {
expect(blogInstance.entries.length).toBe(oldLength - 1); expect(blogInstance.entries.length).toBe(oldLength - 1);
}); });
});
}); });

View File

@ -2,10 +2,10 @@ import {BlogComponent} from './blog.component'
import {TestBed} from "@angular/core/testing"; import {TestBed} from "@angular/core/testing";
import {RouterTestingModule} from "@angular/router/testing"; import {RouterTestingModule} from "@angular/router/testing";
import {BlogEntryComponent} from "./blog-entry/blog-entry.component"; import {BlogEntryComponent} from "./blog-entry/blog-entry.component";
import {BlogEntry} from "./blog-entry/blog-entry";
describe('Blog Component Isolated Test', () => { describe('Blog Component', () => {
describe('Isolated Class Test', () => {
let blogComponent: BlogComponent; let blogComponent: BlogComponent;
beforeEach(() => { beforeEach(() => {
@ -20,7 +20,7 @@ describe('Blog Component Isolated Test', () => {
}) })
}); });
it('should create new list entry and increment id', () => { it('should create new list entry and increment id-pointer', () => {
let preCreationId = blogComponent.id; let preCreationId = blogComponent.id;
let entryTitle = "some fancy title"; let entryTitle = "some fancy title";
let entryImage = "https://avatars1.githubusercontent.com/u/3284117"; let entryImage = "https://avatars1.githubusercontent.com/u/3284117";
@ -48,10 +48,10 @@ describe('Blog Component Isolated Test', () => {
} }
}).not.toBe(latestId); }).not.toBe(latestId);
}); });
}); });
describe('Blog Component Integration Form Test', () => { describe('Template Driven Form Integration Test', () => {
let fixture; let fixture;
let instance; let instance;
@ -84,4 +84,6 @@ describe('Blog Component Integration Form Test', () => {
expect(spy).toHaveBeenCalledWith(testTitle, testImage, testText); expect(spy).toHaveBeenCalledWith(testTitle, testImage, testText);
}) })
});
}); });

View File

@ -32,6 +32,7 @@ export class LoginService {
return this.results$; return this.results$;
} }
// Nur als theoretische Umsetzung - in Realität findet die PW-Validierung serverseitig statt
login(name, password) : boolean { login(name, password) : boolean {
if (this.getUser(name)) { if (this.getUser(name)) {
let user = this.results$[0]; let user = this.results$[0];

View File

@ -38,7 +38,7 @@ describe('Login-Service', () => {
}) })
); );
it('should trigger a HTTP-GET and receive Task', (() => { it('should trigger a HTTP-GET and receive Users', (() => {
mockBackend.connections.subscribe(connection => { mockBackend.connections.subscribe(connection => {
const expectedUrl = 'http://localhost:3000/api/users/'; const expectedUrl = 'http://localhost:3000/api/users/';
expect(connection.request.url).toBe(expectedUrl); expect(connection.request.url).toBe(expectedUrl);

View File

@ -13,24 +13,24 @@ export class UserStore {
this.items$.next(this.users); this.items$.next(this.users);
} }
_reduce(tasks: User[], action) { _reduce(users: User[], action) {
switch (action.type) { switch (action.type) {
case LOAD: case LOAD:
return [...action.data]; return [...action.data];
case ADD: case ADD:
return [...tasks, action.data]; return [...users, action.data];
case EDIT: case EDIT:
return tasks.map(task => { return users.map(user => {
const editedTask = action.data; const editedUser = action.data;
if (task.id !== editedTask.id) { if (user.id !== editedUser.id) {
return task; return user;
} }
return editedTask; return editedUser;
}); });
case REMOVE: case REMOVE:
return tasks.filter(task => task.id !== action.data.id); return users.filter(task => task.id !== action.data.id);
default: default:
return tasks; return users;
} }
} }

View File

@ -40,7 +40,7 @@ describe('EditTask Component', () => {
}); });
describe('Template Driven Form API-based Test', ()=>{ describe('Template Driven Form API-based Test', () => {
let fixture; let fixture;
@ -51,7 +51,7 @@ describe('EditTask Component', () => {
fixture.autoDetectChanges(true); fixture.autoDetectChanges(true);
}); });
it('should validate the title correctly', (done)=> { it('should validate the title correctly', (done) => {
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
form = fixture.componentInstance.form.form; form = fixture.componentInstance.form.form;
const titleControl = form.get('title'); const titleControl = form.get('title');
@ -103,7 +103,7 @@ describe('EditTask Component', () => {
}); });
}); });
it('should show error on tag name provided with gt 0 and lt 3', (done) => { it('should validate assignee email correctly', (done) => {
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
form = fixture.componentInstance.form.form; form = fixture.componentInstance.form.form;
const invalidEmailObject = {invalidEMail: true}; const invalidEmailObject = {invalidEMail: true};
@ -127,7 +127,7 @@ describe('EditTask Component', () => {
}); });
describe('Routing', ()=>{ describe('Routing', () => {
let taskService: TaskService; let taskService: TaskService;