diff --git a/src/app/article/article-default-view-component.spec.ts b/src/app/article/article-default-view-component.spec.ts index 7158586..2ea2258 100644 --- a/src/app/article/article-default-view-component.spec.ts +++ b/src/app/article/article-default-view-component.spec.ts @@ -1,8 +1,7 @@ - import {Input, provide, Component} from 'ng-forward'; import {ArticleViewComponent, ArticleDefaultViewComponent} from './article-default-view.component'; -import {createComponentFromClass, quickCreateComponent} from "../../spec/helpers"; +import * as helpers from "../../spec/helpers"; // this htmlTemplate will be re-used between the container components in this spec file const htmlTemplate: string = ''; @@ -21,15 +20,22 @@ describe("Components", () => { it("renders the default component when no specific component is found", (done: Function) => { // Creating a container component (ArticleContainerComponent) to include // the component under test (ArticleView) - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleViewComponent] }) + @Component({ + selector: 'test-container-component', + template: htmlTemplate, + directives: [ArticleViewComponent], + providers: [ + helpers.createProviderToValue('CommentService', helpers.mocks.commentService), + helpers.provideFilters("translateFilter"), + helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService) + ] + }) class ArticleContainerComponent { article = { type: 'anyArticleType' }; profile = { name: 'profile-name' }; - constructor() { - } } - createComponentFromClass(ArticleContainerComponent).then((fixture) => { + helpers.createComponentFromClass(ArticleContainerComponent).then((fixture) => { // and here we can inspect and run the test assertions // gets the children component of ArticleContainerComponent @@ -51,16 +57,23 @@ describe("Components", () => { // Creating a container component (ArticleContainerComponent) to include // the component under test (ArticleView) - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleViewComponent] }) + @Component({ + selector: 'test-container-component', + template: htmlTemplate, + directives: [ArticleViewComponent], + providers: [ + helpers.createProviderToValue('CommentService', helpers.mocks.commentService), + helpers.provideFilters("translateFilter"), + helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService) + ] + }) class ArticleContainerComponent { article = { type: 'anyArticleType' }; profile = { name: 'profile-name' }; - constructor() { - } } // uses the TestComponentBuilder instance to initialize the component - createComponentFromClass(ArticleContainerComponent).then((fixture) => { + helpers.createComponentFromClass(ArticleContainerComponent).then((fixture) => { // and here we can inspect and run the test assertions let articleView: ArticleViewComponent = fixture.debugElement.componentViewChildren[0].componentInstance; @@ -93,10 +106,8 @@ describe("Components", () => { class CustomArticleType { article = { type: 'TinyMceArticle' }; profile = { name: 'profile-name' }; - constructor() { - } } - createComponentFromClass(CustomArticleType).then(fixture => { + helpers.createComponentFromClass(CustomArticleType).then(fixture => { let myComponent: CustomArticleType = fixture.componentInstance; expect(myComponent.article.type).toEqual("TinyMceArticle"); expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle"); @@ -105,4 +116,4 @@ describe("Components", () => { }); }); -}); \ No newline at end of file +}); diff --git a/src/spec/mocks.ts b/src/spec/mocks.ts index 3923e1b..1d501a9 100644 --- a/src/spec/mocks.ts +++ b/src/spec/mocks.ts @@ -73,6 +73,11 @@ export var mocks = { }, instant: () => { } }, + commentService: { + getByArticle: (article: noosfero.Article) => { + return Promise.resolve(); + } + }, sessionWithCurrentUser: (user: any) => { return { currentUser: () => { return user; } @@ -111,5 +116,8 @@ export var mocks = { currentLanguage: () => { }, changeLanguage: (lang: string) => { }, translate: (text: string) => { return text; } + }, + notificationService: { + } }; -- libgit2 0.21.2