Optimized tests

unit-test
Florian Hartwich 2017-04-16 23:21:41 +02:00
parent 38a53b4001
commit 3d98366a1c
6 changed files with 39 additions and 29 deletions

View File

@ -24,6 +24,7 @@ describe('Create New Task Form', function () {
const taskEditPage = new TaskEditPage(true); const taskEditPage = new TaskEditPage(true);
taskEditPage.clearEnterTitle(testTitle); taskEditPage.clearEnterTitle(testTitle);
taskEditPage.clearEnterDescription(''); taskEditPage.clearEnterDescription('');
browser.pause();
taskEditPage.validateError('title'); taskEditPage.validateError('title');
}); });

View File

@ -49,7 +49,6 @@ module.exports = function(config) {
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { preprocessors: {
'./src/test.ts': ['@angular/cli'] './src/test.ts': ['@angular/cli']
}, },

View File

@ -2,9 +2,13 @@
"tasks": [ "tasks": [
{ {
"id": 3, "id": 3,
"title": "Ersten Prototyp mit Angular 2.0 entwickeln", "title": "Ersten Prototyp mit Angular 4.0 entwickeln",
"description": "Der Prototyp soll zeigen, wie Routing und HTTP-Anbindung umgesetzt werden können.", "description": "Der Prototyp soll zeigen, wie Routing und HTTP-Anbindung umgesetzt werden können.",
"tags": [], "tags": [
{
"label": "news"
}
],
"state": "BACKLOG", "state": "BACKLOG",
"assignee": { "assignee": {
"name": "Christoph Höllers", "name": "Christoph Höllers",

View File

@ -2,7 +2,7 @@
"tasks": [ "tasks": [
{ {
"id": 3, "id": 3,
"title": "Ersten Prototyp mit Angular 4.0 entwickelt", "title": "Ersten Prototyp mit Angular 2.0 entwickeln",
"description": "Der Prototyp soll zeigen, wie Routing und HTTP-Anbindung umgesetzt werden können.", "description": "Der Prototyp soll zeigen, wie Routing und HTTP-Anbindung umgesetzt werden können.",
"tags": [], "tags": [],
"state": "IN_PROGRESS", "state": "IN_PROGRESS",
@ -57,15 +57,6 @@
"state": "IN_PROGRESS", "state": "IN_PROGRESS",
"title": "New Task", "title": "New Task",
"id": 9 "id": 9
},
{
"assignee": {
"email": "testuser@test.com"
},
"tags": [],
"state": "BACKLOG",
"title": "valid title",
"id": 10
} }
] ]
} }

View File

@ -2,6 +2,8 @@ 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 {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core";
import {By} from "@angular/platform-browser";
import {FormsModule} from "@angular/forms";
describe('Blog Component', () => { describe('Blog Component', () => {
@ -50,12 +52,16 @@ describe('Blog Component', () => {
}); });
}); });
describe('Template Driven Form Integration Test', () => { describe('Basic DOM Form Test ', () => {
let fixture; let fixture;
let instance; let instance;
let element; let element;
const testTitle = 'testTitle';
const testImage = 'imageUrl';
const testText = 'testText';
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([])], imports: [RouterTestingModule.withRoutes([])],
@ -65,25 +71,34 @@ describe('Blog Component', () => {
}); });
fixture = TestBed.createComponent(BlogComponent); fixture = TestBed.createComponent(BlogComponent);
instance = fixture.componentInstance; instance = fixture.componentInstance;
element = fixture.nativeElement;
}); });
it('should call create method with provided field input', () => { it('should call create method with provided field input - using nativeElement', () => {
element = fixture.nativeElement;
const spy = spyOn(instance, 'createBlogEntry'); const spy = spyOn(instance, 'createBlogEntry');
const testTitle = 'testTitle';
const testImage = 'imageUrl';
const testText = 'testText';
// beachten : value würde immer funktionieren um Werte als Variable // beachten : value würde immer funktionieren um Werte als Variable
// übertragbar einzutragen, textContent hingegen nur bei textarea // übertragbar einzutragen/ auszulesen, textContent hingegen nur bei textarea
element.querySelector('div /deep/ div > #title').value = testTitle; element.querySelector('div > #title').value = testTitle;
element.querySelector('div /deep/ div > #image').value = testImage; element.querySelector('.form :nth-child(2) > input').value = testImage;
element.querySelector('div /deep/ div > #text').textContent = testText; element.querySelector('#text').textContent = testText;
element.querySelector('div /deep/ div > button').click(); element.querySelector('div > button').click();
expect(spy).toHaveBeenCalledWith(testTitle, testImage, testText); expect(spy).toHaveBeenCalledWith(testTitle, testImage, testText);
}) });
it('should call create method with provided field input - using debugElement', () => {
element = fixture.debugElement;
const spy = spyOn(instance, 'createBlogEntry');
// beachten : value würde immer funktionieren um Werte als Variable
// übertragbar einzutragen/ auszulesen, textContent hingegen nur bei textarea
element.query(By.css('#title')).nativeElement.value = testTitle;
element.query(By.css('.form :nth-child(2) > input')).nativeElement.value = testImage;
element.query(By.css('#text')).nativeElement.textContent = testText;
element.query(By.css('button')).nativeElement.click();
expect(spy).toHaveBeenCalledWith(testTitle, testImage, testText);
});
}); });

View File

@ -7,7 +7,7 @@ import {MockEmptyClass} from "../mocks/mock-empty-class";
import Spy = jasmine.Spy; import Spy = jasmine.Spy;
describe('Login Component Template Driven Form Test with Spy', () => { describe('Login Component UI Driven Form Test with Spy', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({