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