Commit fd340759d1545b47cdf2af97b4fb26c5a9481a18
1 parent
b58d8d11
Exists in
master
and in
30 other branches
Fix article view tests
Showing
2 changed files
with
33 additions
and
14 deletions
Show diff stats
src/app/article/article-default-view-component.spec.ts
| 1 | - | ||
| 2 | import {Input, provide, Component} from 'ng-forward'; | 1 | import {Input, provide, Component} from 'ng-forward'; |
| 3 | import {ArticleViewComponent, ArticleDefaultViewComponent} from './article-default-view.component'; | 2 | import {ArticleViewComponent, ArticleDefaultViewComponent} from './article-default-view.component'; |
| 4 | 3 | ||
| 5 | -import {createComponentFromClass, quickCreateComponent} from "../../spec/helpers"; | 4 | +import * as helpers from "../../spec/helpers"; |
| 6 | 5 | ||
| 7 | // this htmlTemplate will be re-used between the container components in this spec file | 6 | // this htmlTemplate will be re-used between the container components in this spec file |
| 8 | const htmlTemplate: string = '<noosfero-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-article>'; | 7 | const htmlTemplate: string = '<noosfero-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-article>'; |
| @@ -21,15 +20,22 @@ describe("Components", () => { | @@ -21,15 +20,22 @@ describe("Components", () => { | ||
| 21 | it("renders the default component when no specific component is found", (done: Function) => { | 20 | it("renders the default component when no specific component is found", (done: Function) => { |
| 22 | // Creating a container component (ArticleContainerComponent) to include | 21 | // Creating a container component (ArticleContainerComponent) to include |
| 23 | // the component under test (ArticleView) | 22 | // the component under test (ArticleView) |
| 24 | - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleViewComponent] }) | 23 | + @Component({ |
| 24 | + selector: 'test-container-component', | ||
| 25 | + template: htmlTemplate, | ||
| 26 | + directives: [ArticleViewComponent], | ||
| 27 | + providers: [ | ||
| 28 | + helpers.createProviderToValue('CommentService', helpers.mocks.commentService), | ||
| 29 | + helpers.provideFilters("translateFilter"), | ||
| 30 | + helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService) | ||
| 31 | + ] | ||
| 32 | + }) | ||
| 25 | class ArticleContainerComponent { | 33 | class ArticleContainerComponent { |
| 26 | article = { type: 'anyArticleType' }; | 34 | article = { type: 'anyArticleType' }; |
| 27 | profile = { name: 'profile-name' }; | 35 | profile = { name: 'profile-name' }; |
| 28 | - constructor() { | ||
| 29 | - } | ||
| 30 | } | 36 | } |
| 31 | 37 | ||
| 32 | - createComponentFromClass(ArticleContainerComponent).then((fixture) => { | 38 | + helpers.createComponentFromClass(ArticleContainerComponent).then((fixture) => { |
| 33 | // and here we can inspect and run the test assertions | 39 | // and here we can inspect and run the test assertions |
| 34 | 40 | ||
| 35 | // gets the children component of ArticleContainerComponent | 41 | // gets the children component of ArticleContainerComponent |
| @@ -51,16 +57,23 @@ describe("Components", () => { | @@ -51,16 +57,23 @@ describe("Components", () => { | ||
| 51 | 57 | ||
| 52 | // Creating a container component (ArticleContainerComponent) to include | 58 | // Creating a container component (ArticleContainerComponent) to include |
| 53 | // the component under test (ArticleView) | 59 | // the component under test (ArticleView) |
| 54 | - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleViewComponent] }) | 60 | + @Component({ |
| 61 | + selector: 'test-container-component', | ||
| 62 | + template: htmlTemplate, | ||
| 63 | + directives: [ArticleViewComponent], | ||
| 64 | + providers: [ | ||
| 65 | + helpers.createProviderToValue('CommentService', helpers.mocks.commentService), | ||
| 66 | + helpers.provideFilters("translateFilter"), | ||
| 67 | + helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService) | ||
| 68 | + ] | ||
| 69 | + }) | ||
| 55 | class ArticleContainerComponent { | 70 | class ArticleContainerComponent { |
| 56 | article = { type: 'anyArticleType' }; | 71 | article = { type: 'anyArticleType' }; |
| 57 | profile = { name: 'profile-name' }; | 72 | profile = { name: 'profile-name' }; |
| 58 | - constructor() { | ||
| 59 | - } | ||
| 60 | } | 73 | } |
| 61 | 74 | ||
| 62 | // uses the TestComponentBuilder instance to initialize the component | 75 | // uses the TestComponentBuilder instance to initialize the component |
| 63 | - createComponentFromClass(ArticleContainerComponent).then((fixture) => { | 76 | + helpers.createComponentFromClass(ArticleContainerComponent).then((fixture) => { |
| 64 | // and here we can inspect and run the test assertions | 77 | // and here we can inspect and run the test assertions |
| 65 | let articleView: ArticleViewComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | 78 | let articleView: ArticleViewComponent = fixture.debugElement.componentViewChildren[0].componentInstance; |
| 66 | 79 | ||
| @@ -93,10 +106,8 @@ describe("Components", () => { | @@ -93,10 +106,8 @@ describe("Components", () => { | ||
| 93 | class CustomArticleType { | 106 | class CustomArticleType { |
| 94 | article = { type: 'TinyMceArticle' }; | 107 | article = { type: 'TinyMceArticle' }; |
| 95 | profile = { name: 'profile-name' }; | 108 | profile = { name: 'profile-name' }; |
| 96 | - constructor() { | ||
| 97 | - } | ||
| 98 | } | 109 | } |
| 99 | - createComponentFromClass(CustomArticleType).then(fixture => { | 110 | + helpers.createComponentFromClass(CustomArticleType).then(fixture => { |
| 100 | let myComponent: CustomArticleType = fixture.componentInstance; | 111 | let myComponent: CustomArticleType = fixture.componentInstance; |
| 101 | expect(myComponent.article.type).toEqual("TinyMceArticle"); | 112 | expect(myComponent.article.type).toEqual("TinyMceArticle"); |
| 102 | expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle"); | 113 | expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle"); |
| @@ -105,4 +116,4 @@ describe("Components", () => { | @@ -105,4 +116,4 @@ describe("Components", () => { | ||
| 105 | }); | 116 | }); |
| 106 | 117 | ||
| 107 | }); | 118 | }); |
| 108 | -}); | ||
| 109 | \ No newline at end of file | 119 | \ No newline at end of file |
| 120 | +}); |
src/spec/mocks.ts
| @@ -73,6 +73,11 @@ export var mocks = { | @@ -73,6 +73,11 @@ export var mocks = { | ||
| 73 | }, | 73 | }, |
| 74 | instant: () => { } | 74 | instant: () => { } |
| 75 | }, | 75 | }, |
| 76 | + commentService: { | ||
| 77 | + getByArticle: (article: noosfero.Article) => { | ||
| 78 | + return Promise.resolve(); | ||
| 79 | + } | ||
| 80 | + }, | ||
| 76 | sessionWithCurrentUser: (user: any) => { | 81 | sessionWithCurrentUser: (user: any) => { |
| 77 | return { | 82 | return { |
| 78 | currentUser: () => { return user; } | 83 | currentUser: () => { return user; } |
| @@ -111,5 +116,8 @@ export var mocks = { | @@ -111,5 +116,8 @@ export var mocks = { | ||
| 111 | currentLanguage: () => { }, | 116 | currentLanguage: () => { }, |
| 112 | changeLanguage: (lang: string) => { }, | 117 | changeLanguage: (lang: string) => { }, |
| 113 | translate: (text: string) => { return text; } | 118 | translate: (text: string) => { return text; } |
| 119 | + }, | ||
| 120 | + notificationService: { | ||
| 121 | + | ||
| 114 | } | 122 | } |
| 115 | }; | 123 | }; |