Commit 5f9ef2aecc4640864235373b51f464441aeb1292
1 parent
00eaab03
Exists in
master
and in
27 other branches
Refactor tests of content viewer actions to use ComponentTestHelper
Showing
1 changed file
with
31 additions
and
63 deletions
Show diff stats
src/app/article/content-viewer/content-viewer-actions.component.spec.ts
| 1 | -import {providers} from 'ng-forward/cjs/testing/providers'; | ||
| 2 | - | ||
| 3 | import {Input, Component, provide} from 'ng-forward'; | 1 | import {Input, Component, provide} from 'ng-forward'; |
| 4 | 2 | ||
| 5 | import * as helpers from "../../../spec/helpers"; | 3 | import * as helpers from "../../../spec/helpers"; |
| 6 | - | ||
| 7 | -import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; | 4 | +import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper'; |
| 8 | import {ContentViewerActionsComponent} from './content-viewer-actions.component'; | 5 | import {ContentViewerActionsComponent} from './content-viewer-actions.component'; |
| 9 | 6 | ||
| 10 | // this htmlTemplate will be re-used between the container components in this spec file | 7 | // this htmlTemplate will be re-used between the container components in this spec file |
| @@ -12,86 +9,57 @@ const htmlTemplate: string = '<content-viewer-actions [article]="ctrl.article" [ | @@ -12,86 +9,57 @@ const htmlTemplate: string = '<content-viewer-actions [article]="ctrl.article" [ | ||
| 12 | 9 | ||
| 13 | describe('Content Viewer Actions Component', () => { | 10 | describe('Content Viewer Actions Component', () => { |
| 14 | 11 | ||
| 15 | - beforeEach(() => { | 12 | + let helper: ComponentTestHelper<ContentViewerActionsComponent>; |
| 16 | 13 | ||
| 17 | - angular.mock.module("templates"); | 14 | + beforeEach(angular.mock.module("templates")); |
| 18 | 15 | ||
| 19 | - providers((provide: any) => { | ||
| 20 | - return <any>[ | ||
| 21 | - provide('ProfileService', { | ||
| 22 | - useValue: helpers.mocks.profileService | ||
| 23 | - }), | ||
| 24 | - provide('ArticleService', { | ||
| 25 | - useValue: helpers.mocks.articleService | ||
| 26 | - }) | ||
| 27 | - ]; | ||
| 28 | - }); | ||
| 29 | - }); | 16 | + let providers = [ |
| 17 | + provide('ProfileService', { | ||
| 18 | + useValue: helpers.mocks.profileService | ||
| 19 | + }), | ||
| 20 | + provide('ArticleService', { | ||
| 21 | + useValue: helpers.mocks.articleService | ||
| 22 | + }) | ||
| 23 | + ].concat(helpers.provideFilters("translateFilter")); | ||
| 30 | 24 | ||
| 31 | - let buildComponent = (): Promise<ComponentFixture> => { | ||
| 32 | - return helpers.quickCreateComponent({ | ||
| 33 | - providers: [ | ||
| 34 | - helpers.provideEmptyObjects('Restangular'), | ||
| 35 | - helpers.provideFilters('translateFilter') | ||
| 36 | - ], | 25 | + beforeEach((done) => { |
| 26 | + let cls = createClass({ | ||
| 27 | + template: htmlTemplate, | ||
| 37 | directives: [ContentViewerActionsComponent], | 28 | directives: [ContentViewerActionsComponent], |
| 38 | - template: htmlTemplate | 29 | + providers: providers |
| 39 | }); | 30 | }); |
| 40 | - }; | ||
| 41 | - | ||
| 42 | - it('renders content viewer actions directive', (done: Function) => { | ||
| 43 | - buildComponent().then((fixture: ComponentFixture) => { | ||
| 44 | - expect(fixture.debugElement.query('content-viewer-actions').length).toEqual(1); | 31 | + helper = new ComponentTestHelper<ContentViewerActionsComponent>(cls, done); |
| 32 | + }); | ||
| 45 | 33 | ||
| 46 | - done(); | ||
| 47 | - }); | 34 | + it('renders content viewer actions directive', () => { |
| 35 | + expect(helper.all("content-viewer-actions").length).toEqual(1); | ||
| 48 | }); | 36 | }); |
| 49 | 37 | ||
| 50 | - it('return article parent as container when it is not a folder', (done: Function) => { | ||
| 51 | - buildComponent().then((fixture: ComponentFixture) => { | ||
| 52 | - let component = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
| 53 | - let article = <noosfero.Article>({ id: 1, type: 'TextArticle', parent: { id: 2 } }); | ||
| 54 | - expect(component.getArticleContainer(article)).toEqual(2); | ||
| 55 | - done(); | ||
| 56 | - }); | 38 | + it('return article parent as container when it is not a folder', () => { |
| 39 | + let article = <noosfero.Article>({ id: 1, type: 'TextArticle', parent: { id: 2 } }); | ||
| 40 | + expect(helper.component.getArticleContainer(article)).toEqual(2); | ||
| 57 | }); | 41 | }); |
| 58 | 42 | ||
| 59 | - it('return article as container when it is a folder', (done: Function) => { | ||
| 60 | - buildComponent().then((fixture: ComponentFixture) => { | ||
| 61 | - let component = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
| 62 | - let article = <noosfero.Article>({ id: 1, type: 'Folder' }); | ||
| 63 | - expect(component.getArticleContainer(article)).toEqual(1); | ||
| 64 | - done(); | ||
| 65 | - }); | 43 | + it('return article as container when it is a folder', () => { |
| 44 | + let article = <noosfero.Article>({ id: 1, type: 'Folder' }); | ||
| 45 | + expect(helper.component.getArticleContainer(article)).toEqual(1); | ||
| 66 | }); | 46 | }); |
| 67 | 47 | ||
| 68 | - it('return article as container when it is a blog', (done: Function) => { | ||
| 69 | - buildComponent().then((fixture: ComponentFixture) => { | ||
| 70 | - let component = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
| 71 | - let article = <noosfero.Article>({ id: 1, type: 'Blog' }); | ||
| 72 | - expect(component.getArticleContainer(article)).toEqual(1); | ||
| 73 | - done(); | ||
| 74 | - }); | 48 | + it('return article as container when it is a blog', () => { |
| 49 | + let article = <noosfero.Article>({ id: 1, type: 'Blog' }); | ||
| 50 | + expect(helper.component.getArticleContainer(article)).toEqual(1); | ||
| 75 | }); | 51 | }); |
| 76 | 52 | ||
| 77 | - it('check if profile was loaded', (done: Function) => { | 53 | + it('check if profile was loaded', () => { |
| 78 | let profile: any = { | 54 | let profile: any = { |
| 79 | id: 1, | 55 | id: 1, |
| 80 | identifier: 'the-profile-test', | 56 | identifier: 'the-profile-test', |
| 81 | type: 'Person' | 57 | type: 'Person' |
| 82 | }; | 58 | }; |
| 83 | - | ||
| 84 | helpers.mocks.profileService.getCurrentProfile = () => { | 59 | helpers.mocks.profileService.getCurrentProfile = () => { |
| 85 | return helpers.mocks.promiseResultTemplate(profile); | 60 | return helpers.mocks.promiseResultTemplate(profile); |
| 86 | }; | 61 | }; |
| 87 | - | ||
| 88 | - buildComponent().then((fixture: ComponentFixture) => { | ||
| 89 | - let contentViewerComp: ContentViewerActionsComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
| 90 | - | ||
| 91 | - expect(contentViewerComp.profile).toEqual(jasmine.objectContaining(profile)); | ||
| 92 | - | ||
| 93 | - done(); | ||
| 94 | - }); | 62 | + let component = new ContentViewerActionsComponent(<any>helpers.mocks.profileService, <any>helpers.mocks.articleService); |
| 63 | + expect(component.profile).toEqual(jasmine.objectContaining(profile)); | ||
| 95 | }); | 64 | }); |
| 96 | - | ||
| 97 | }); | 65 | }); |