Commit 11f93c350255ee0a23739a87c8f6cf7552c07020
1 parent
bb1b7631
Exists in
master
and in
32 other branches
Added specs to test content-view-actions component
Showing
2 changed files
with
68 additions
and
1 deletions
Show diff stats
src/app/content-viewer/content-viewer-actions.component.spec.ts
0 → 100644
| @@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
| 1 | +import {providers} from 'ng-forward/cjs/testing/providers'; | ||
| 2 | + | ||
| 3 | +import {Input, Component, provide} from 'ng-forward'; | ||
| 4 | + | ||
| 5 | +import * as helpers from "../../spec/helpers"; | ||
| 6 | + | ||
| 7 | +import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; | ||
| 8 | +import {ContentViewerActions} from './content-viewer-actions.component'; | ||
| 9 | + | ||
| 10 | +// this htmlTemplate will be re-used between the container components in this spec file | ||
| 11 | +const htmlTemplate: string = '<content-viewer-actions [article]="ctrl.article" [profile]="ctrl.profile"></content-viewer-actions>'; | ||
| 12 | + | ||
| 13 | +describe('Content Viewer Actions Component', () => { | ||
| 14 | + | ||
| 15 | + beforeEach(() => { | ||
| 16 | + | ||
| 17 | + angular.mock.module("templates"); | ||
| 18 | + | ||
| 19 | + providers((provide: any) => { | ||
| 20 | + return <any>[ | ||
| 21 | + provide('ProfileService', { | ||
| 22 | + useValue: helpers.mocks.profileService | ||
| 23 | + }) | ||
| 24 | + ]; | ||
| 25 | + }); | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + let buildComponent = (): Promise<ComponentFixture> => { | ||
| 29 | + return helpers.quickCreateComponent({ | ||
| 30 | + providers: [ | ||
| 31 | + helpers.provideEmptyObjects('Restangular'), | ||
| 32 | + helpers.provideFilters('translateFilter') | ||
| 33 | + ], | ||
| 34 | + directives: [ContentViewerActions], | ||
| 35 | + template: htmlTemplate | ||
| 36 | + }); | ||
| 37 | + }; | ||
| 38 | + | ||
| 39 | + it('renders content viewer actions directive', (done: Function) => { | ||
| 40 | + buildComponent().then((fixture: ComponentFixture) => { | ||
| 41 | + expect(fixture.debugElement.query('content-viewer-actions').length).toEqual(1); | ||
| 42 | + | ||
| 43 | + done(); | ||
| 44 | + }); | ||
| 45 | + }); | ||
| 46 | + | ||
| 47 | + it('check if profile was loaded', (done: Function) => { | ||
| 48 | + let profile: any = { | ||
| 49 | + id: 1, | ||
| 50 | + identifier: 'the-profile-test', | ||
| 51 | + type: 'Person' | ||
| 52 | + }; | ||
| 53 | + | ||
| 54 | + helpers.mocks.profileService.getCurrentProfile = () => { | ||
| 55 | + return helpers.mocks.promiseResultTemplate(profile); | ||
| 56 | + }; | ||
| 57 | + | ||
| 58 | + buildComponent().then((fixture: ComponentFixture) => { | ||
| 59 | + let contentViewerComp: ContentViewerActions = fixture.debugElement.componentViewChildren[0].componentInstance; | ||
| 60 | + | ||
| 61 | + expect(contentViewerComp.profile).toEqual(jasmine.objectContaining(profile)); | ||
| 62 | + | ||
| 63 | + done(); | ||
| 64 | + }); | ||
| 65 | + }); | ||
| 66 | + | ||
| 67 | +}); |
src/spec/mocks.ts