diff --git a/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts b/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts index c669a2a..c571ee0 100644 --- a/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts +++ b/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts @@ -3,6 +3,7 @@ import {BlogEntryComponent} from "./blog-entry.component"; import {BlogEntry} from "./blog-entry"; import {BlogComponent} from "../blog.component"; import {RouterTestingModule} from "@angular/router/testing"; +import {Component} from "@angular/core"; describe('Blog Entry Isolated Test', () => { @@ -61,7 +62,36 @@ describe('Blog Entry Isolated Test', () => { describe('BlogEntryComp -> BlogComp Dependent Test', () => { + it('should remove entry from BlogComponent on "delete" button click', () => { + TestBed.configureTestingModule({ + declarations: [BlogEntryComponent, MockBlogComponent] + }); + + const entryFixture = TestBed.createComponent(BlogEntryComponent); + const entryInstance: BlogEntryComponent = entryFixture.componentInstance; + + const blogFixture = TestBed.createComponent(MockBlogComponent); + + const blogInstance: any = 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); + }); + + it('should remove entry from BlogComponent on "delete" button click : OVERRIDE BLOG TEMPLATE', () => { + + TestBed.overrideComponent(BlogComponent, { + set: { + template: '' + } + }); + TestBed.configureTestingModule({ imports: [RouterTestingModule.withRoutes([])], declarations: [BlogEntryComponent, BlogComponent] @@ -87,3 +117,21 @@ describe('Blog Entry Isolated Test', () => { }); +// Mocked Blog Component +@Component({ + selector: 'blog', + template: '' +}) +export class MockBlogComponent { + + entries = [{}, {}]; + + deleteBlogEntry(id) { + this.entries.splice(0, 1); + } + +} + + + + diff --git a/project-manager/src/app/blog/blog.component.spec.ts b/project-manager/src/app/blog/blog.component.spec.ts index e2b995e..cb5481f 100644 --- a/project-manager/src/app/blog/blog.component.spec.ts +++ b/project-manager/src/app/blog/blog.component.spec.ts @@ -1,7 +1,7 @@ import {BlogComponent} from './blog.component' import {TestBed} from "@angular/core/testing"; import {RouterTestingModule} from "@angular/router/testing"; -import {BlogEntryComponent} from "./blog-entry/blog-entry.component"; +import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; describe('Blog Component', () => { @@ -50,7 +50,6 @@ describe('Blog Component', () => { }); }); - describe('Template Driven Form Integration Test', () => { let fixture; @@ -60,7 +59,9 @@ describe('Blog Component', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [RouterTestingModule.withRoutes([])], - declarations: [BlogEntryComponent, BlogComponent] + declarations: [BlogComponent], + // CUSTOM_ELEMENTS_SCHEMA - verhindert das Laden von Sub-Komponenten + schemas: [CUSTOM_ELEMENTS_SCHEMA] }); fixture = TestBed.createComponent(BlogComponent); instance = fixture.componentInstance;