Add spec reporter; Add BlogEntry delete button funct test

merge-requests/1/head
Florian Hartwich 2017-04-04 01:10:22 +02:00
parent 155881ad0f
commit d40cf1f01e
7 changed files with 59 additions and 34 deletions

View File

@ -18,10 +18,16 @@ module.exports = function(config) {
plugins: [ plugins: [
require('karma-jasmine'), require('karma-jasmine'),
require('karma-chrome-launcher'), require('karma-chrome-launcher'),
require('karma-spec-reporter'),
require('@angular/cli/plugins/karma') require('@angular/cli/plugins/karma')
], ],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
'./src/test.ts' './src/test.ts'
@ -50,7 +56,7 @@ module.exports = function(config) {
// test results reporter to use // test results reporter to use
// possible values: 'dots', 'progress' // possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter // available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'], reporters: ['spec'],
// web server port // web server port

View File

@ -1,17 +1,16 @@
import {TestBed} from "@angular/core/testing"; import {TestBed} from "@angular/core/testing";
import {BlogEntryComponent} from "./blog-entry.component"; import {BlogEntryComponent} from "./blog-entry.component";
import {BlogEntry} from "./blog-entry"; import {BlogEntry} from "./blog-entry";
import {BlogComponent} from "../blog.component";
import {RouterTestingModule} from "@angular/router/testing";
describe('Blog Entry Isolated Test', () => { describe('Blog Entry Isolated Test', () => {
beforeEach(() => { it('should render DOM correctly according to Input', () => {
// Umgebung initialisieren
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [BlogEntryComponent], declarations: [BlogEntryComponent],
})
}); });
it('should render DOM correct according to Input', () => {
// Umgebung initialisieren
const fixture = TestBed.createComponent(BlogEntryComponent); const fixture = TestBed.createComponent(BlogEntryComponent);
const blogEntryComponent : BlogEntryComponent = fixture.componentInstance; const blogEntryComponent : BlogEntryComponent = fixture.componentInstance;
const element = fixture.nativeElement; const element = fixture.nativeElement;
@ -40,8 +39,8 @@ describe('Blog Entry Isolated Test', () => {
// textContent statt innerHtml // textContent statt innerHtml
// siehe http://stackoverflow.com/questions/40227533/angular-2-and-jasmine-unit-testing-cannot-get-the-innerhtml // siehe http://stackoverflow.com/questions/40227533/angular-2-and-jasmine-unit-testing-cannot-get-the-innerhtml
const blogTitle = element.querySelector('div /deep/ .blog-summary > span'); const blogTitle = element.querySelector('div /deep/ .blog-summary > span').textContent;
expect(blogTitle.textContent).toBe(testTitle); expect(blogTitle).toBe(testTitle);
const blogText = element.querySelector('div /deep/ .blog-summary > p').textContent; const blogText = element.querySelector('div /deep/ .blog-summary > p').textContent;
expect(blogText).toBe(testText); expect(blogText).toBe(testText);
@ -58,3 +57,28 @@ describe('Blog Entry Isolated Test', () => {
}); });
}); });
describe('BlogEntryComp -> BlogComp Relational Test', () => {
it ('should remove entry from BlogComponent on "delete" button click', () => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([])],
declarations: [BlogEntryComponent, BlogComponent]
});
const entryFixture = TestBed.createComponent(BlogEntryComponent);
const entryInstance : BlogEntryComponent = entryFixture.componentInstance;
const blogFixture = TestBed.createComponent(BlogComponent);
const blogInstance : BlogComponent = blogFixture.componentInstance;
const blogEntry : BlogEntry = blogInstance.entries[0];
entryInstance.entry = blogEntry;
entryInstance.blogComponent = blogInstance;
const oldLength = blogInstance.entries.length;
entryFixture.nativeElement.querySelector('div /deep/ .blog-delete > button').click();
expect(blogInstance.entries.length).toBe(oldLength - 1);
});
});

View File

@ -1,12 +1,11 @@
import {BlogComponent} from './blog.component' import {BlogComponent} from './blog.component'
import {Title} from "@angular/platform-browser";
describe('Blog Component Isolated Test', () => { describe('Blog Component Isolated Test', () => {
let blogComponent: BlogComponent; let blogComponent: BlogComponent;
beforeEach(() => { beforeEach(() => {
blogComponent = new BlogComponent(null, null, new Title('Project Blog')); blogComponent = new BlogComponent(null, null, null);
}); });
it('should have initial entries', () => { it('should have initial entries', () => {
@ -25,7 +24,7 @@ describe('Blog Component Isolated Test', () => {
blogComponent.createBlogEntry(entryTitle, entryImage, entryText); blogComponent.createBlogEntry(entryTitle, entryImage, entryText);
let newEntry = blogComponent.entries[blogComponent.entries.length - 1]; let newEntry = blogComponent.entries[blogComponent.entries.length - 1];
expect(newEntry.id - 1).toBe(preCreationId) expect(newEntry.id - 1).toBe(preCreationId);
expect(newEntry.image).toBe(entryImage); expect(newEntry.image).toBe(entryImage);
expect(newEntry.text).toBe(entryText); expect(newEntry.text).toBe(entryText);
expect(newEntry.createdAt.getDate()).toBe(new Date().getDate()); expect(newEntry.createdAt.getDate()).toBe(new Date().getDate());

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,6 @@ export class LoginComponent {
constructor(private loginService: LoginService, constructor(private loginService: LoginService,
private router: Router, private router: Router,
private route: ActivatedRoute) { private route: ActivatedRoute) {
} }
login(userName: string, password: string) { login(userName: string, password: string) {

View File

@ -1,5 +1,5 @@
// Test Suite // Test Suite
describe('Basic test', () => { describe('Basic Test', () => {
// Variablendeklaration zur Verwendung in mehreren Testfällen // Variablendeklaration zur Verwendung in mehreren Testfällen
let someInt; let someInt;