Commit 94fa90c3afd2ee74f4e98c35147691a9d5d37ab2
1 parent
30c6672c
Exists in
master
and in
34 other branches
fixed blog component spec compilation issues
Showing
1 changed file
with
49 additions
and
44 deletions
Show diff stats
src/app/components/noosfero-articles/blog/blog.component.spec.ts
| @@ -7,7 +7,8 @@ import {createComponentFromClass, quickCreateComponent, provideEmptyObjects, cre | @@ -7,7 +7,8 @@ import {createComponentFromClass, quickCreateComponent, provideEmptyObjects, cre | ||
| 7 | 7 | ||
| 8 | // this htmlTemplate will be re-used between the container components in this spec file | 8 | // this htmlTemplate will be re-used between the container components in this spec file |
| 9 | const htmlTemplate: string = '<noosfero-blog [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-blog>'; | 9 | const htmlTemplate: string = '<noosfero-blog [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-blog>'; |
| 10 | -let articleService = {}; | 10 | + |
| 11 | +let articleService: { getChildren: Function } = <any>{}; | ||
| 11 | 12 | ||
| 12 | describe("Blog Component", () => { | 13 | describe("Blog Component", () => { |
| 13 | 14 | ||
| @@ -17,19 +18,22 @@ describe("Blog Component", () => { | @@ -17,19 +18,22 @@ describe("Blog Component", () => { | ||
| 17 | // component Noosfero ArtileView will be load on our tests | 18 | // component Noosfero ArtileView will be load on our tests |
| 18 | beforeEach(angular.mock.module("templates")); | 19 | beforeEach(angular.mock.module("templates")); |
| 19 | 20 | ||
| 20 | - function promiseResultTemplate(thenFunc: Function) { | 21 | + function promiseResultTemplate(response?: {}) { |
| 21 | let thenFuncEmpty = (func: Function) => { | 22 | let thenFuncEmpty = (func: Function) => { |
| 22 | // does nothing | 23 | // does nothing |
| 23 | - //func() | ||
| 24 | }; | 24 | }; |
| 25 | - if (thenFunc) { | 25 | + if (response) { |
| 26 | return { | 26 | return { |
| 27 | - then: thenFunc | ||
| 28 | - } | 27 | + then: (func: (response: any) => void) => { |
| 28 | + func(response); | ||
| 29 | + } | ||
| 30 | + }; | ||
| 29 | } else { | 31 | } else { |
| 30 | return { | 32 | return { |
| 31 | - then: thenFuncEmpty | ||
| 32 | - } | 33 | + then: (func: (response: any) => void) => { |
| 34 | + // does nothing | ||
| 35 | + } | ||
| 36 | + }; | ||
| 33 | } | 37 | } |
| 34 | } | 38 | } |
| 35 | 39 | ||
| @@ -37,7 +41,7 @@ describe("Blog Component", () => { | @@ -37,7 +41,7 @@ describe("Blog Component", () => { | ||
| 37 | // creating mock for articleService | 41 | // creating mock for articleService |
| 38 | articleService = { | 42 | articleService = { |
| 39 | getChildren: (article_id: number, filters: {}) => { | 43 | getChildren: (article_id: number, filters: {}) => { |
| 40 | - return promiseResultTemplate(); | 44 | + return promiseResultTemplate(null); |
| 41 | } | 45 | } |
| 42 | }; | 46 | }; |
| 43 | }); | 47 | }); |
| @@ -64,51 +68,52 @@ describe("Blog Component", () => { | @@ -64,51 +68,52 @@ describe("Blog Component", () => { | ||
| 64 | done(); | 68 | done(); |
| 65 | }); | 69 | }); |
| 66 | 70 | ||
| 67 | - it("verify the blog data", (done: Function) => { | ||
| 68 | 71 | ||
| 69 | - articleService.getChildren = (article_id: number, filters: {}) => { | ||
| 70 | - return promiseResultTemplate(() => { | ||
| 71 | - return { | ||
| 72 | - headers: { | ||
| 73 | - total: 1 | 72 | + |
| 73 | + }); | ||
| 74 | + | ||
| 75 | + it("verify the blog data", (done: Function) => { | ||
| 76 | + | ||
| 77 | + // defining a mock result to articleService.getChildren method | ||
| 78 | + articleService.getChildren = (article_id: number, filters: {}) => { | ||
| 79 | + return promiseResultTemplate({ | ||
| 80 | + headers: (headerName: string) => { | ||
| 81 | + return 1; | ||
| 74 | }, | 82 | }, |
| 75 | - data: { | ||
| 76 | - articles: [ | ||
| 77 | - ] | 83 | + data: <any>{ |
| 84 | + articles: [] | ||
| 78 | } | 85 | } |
| 79 | - } | ||
| 80 | }); | 86 | }); |
| 81 | - } | ||
| 82 | - @Component({ | ||
| 83 | - selector: 'test-container-component', | ||
| 84 | - template: htmlTemplate, | ||
| 85 | - directives: [ArticleBlog], | ||
| 86 | - providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] | ||
| 87 | - }) | ||
| 88 | - class BlogContainerComponent { | ||
| 89 | - article = { type: 'anyArticleType' }; | ||
| 90 | - profile = { name: 'profile-name' }; | ||
| 91 | - } | 87 | + }; |
| 92 | 88 | ||
| 93 | - createComponentFromClass(BlogContainerComponent).then((fixture) => { | ||
| 94 | - // and here we can inspect and run the test assertions | 89 | + @Component({ |
| 90 | + selector: 'test-container-component', | ||
| 91 | + template: htmlTemplate, | ||
| 92 | + directives: [ArticleBlog], | ||
| 93 | + providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] | ||
| 94 | + }) | ||
| 95 | + class BlogContainerComponent { | ||
| 96 | + article = { type: 'anyArticleType' }; | ||
| 97 | + profile = { name: 'profile-name' }; | ||
| 98 | + } | ||
| 95 | 99 | ||
| 96 | - // gets the children component of ArticleContainerComponent | ||
| 97 | - let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | 100 | + createComponentFromClass(BlogContainerComponent).then((fixture) => { |
| 98 | 101 | ||
| 99 | - // and checks if the article View rendered was the Default Article View | ||
| 100 | - //expect(articleView.constructor.prototype).toEqual(ArticleDefaultView.prototype); | ||
| 101 | - expect(articleBlog["posts"]).toEqual([]); | ||
| 102 | - expect(articleBlog["totalPosts"]).toEqual(1); | 102 | + // gets the children component of BlogContainerComponent |
| 103 | + let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
| 103 | 104 | ||
| 105 | + // check if the component property are the provided by the mocked articleService | ||
| 106 | + expect((<any>articleBlog)["posts"]).toEqual([]); | ||
| 107 | + expect((<any>articleBlog)["totalPosts"]).toEqual(1); | ||
| 104 | 108 | ||
| 105 | - // done needs to be called (it isn't really needed, as we can read in | ||
| 106 | - // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync) | ||
| 107 | - // because createAsync in ng-forward is not really async, but as the intention | ||
| 108 | - // here is write tests in angular 2 ways, this is recommended | ||
| 109 | - done(); | ||
| 110 | - }); | ||
| 111 | 109 | ||
| 110 | + // done needs to be called (it isn't really needed, as we can read in | ||
| 111 | + // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync) | ||
| 112 | + // because createAsync in ng-forward is not really async, but as the intention | ||
| 113 | + // here is write tests in angular 2 ways, this is recommended | ||
| 114 | + done(); | ||
| 112 | }); | 115 | }); |
| 113 | 116 | ||
| 114 | }); | 117 | }); |
| 118 | + | ||
| 119 | +}); |