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);
taskEditPage.clearEnterTitle(testTitle);
taskEditPage.clearEnterDescription('');
browser.pause();
taskEditPage.validateError('title');
});

View File

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

View File

@ -2,9 +2,13 @@
"tasks": [
{
"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.",
"tags": [],
"tags": [
{
"label": "news"
}
],
"state": "BACKLOG",
"assignee": {
"name": "Christoph Höllers",
@ -54,4 +58,4 @@
"change_settings": false
}
]
}
}

View File

@ -2,7 +2,7 @@
"tasks": [
{
"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.",
"tags": [],
"state": "IN_PROGRESS",
@ -57,15 +57,6 @@
"state": "IN_PROGRESS",
"title": "New Task",
"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 {RouterTestingModule} from "@angular/router/testing";
import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core";
import {By} from "@angular/platform-browser";
import {FormsModule} from "@angular/forms";
describe('Blog Component', () => {
@ -50,12 +52,16 @@ describe('Blog Component', () => {
});
});
describe('Template Driven Form Integration Test', () => {
describe('Basic DOM Form Test ', () => {
let fixture;
let instance;
let element;
const testTitle = 'testTitle';
const testImage = 'imageUrl';
const testText = 'testText';
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([])],
@ -65,25 +71,34 @@ describe('Blog Component', () => {
});
fixture = TestBed.createComponent(BlogComponent);
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 testTitle = 'testTitle';
const testImage = 'imageUrl';
const testText = 'testText';
// beachten : value würde immer funktionieren um Werte als Variable
// übertragbar einzutragen, textContent hingegen nur bei textarea
element.querySelector('div /deep/ div > #title').value = testTitle;
element.querySelector('div /deep/ div > #image').value = testImage;
element.querySelector('div /deep/ div > #text').textContent = testText;
element.querySelector('div /deep/ div > button').click();
// übertragbar einzutragen/ auszulesen, textContent hingegen nur bei textarea
element.querySelector('div > #title').value = testTitle;
element.querySelector('.form :nth-child(2) > input').value = testImage;
element.querySelector('#text').textContent = testText;
element.querySelector('div > button').click();
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;
describe('Login Component Template Driven Form Test with Spy', () => {
describe('Login Component UI Driven Form Test with Spy', () => {
beforeEach(() => {
TestBed.configureTestingModule({