diff --git a/src/app/components/noosfero-articles/blog/blog.component.spec.ts b/src/app/components/noosfero-articles/blog/blog.component.spec.ts index 0e1adf5..1b20fc8 100644 --- a/src/app/components/noosfero-articles/blog/blog.component.spec.ts +++ b/src/app/components/noosfero-articles/blog/blog.component.spec.ts @@ -1,14 +1,27 @@ - -import {Input, provide, Component} from 'ng-forward'; -import {ArticleBlog} from './blog.component'; - -import {createComponentFromClass, quickCreateComponent, provideEmptyObjects, createProviderToValue} from "../../../../spec/helpers.ts"; +import { + Input, + provide, + Component +} from 'ng-forward'; +import { + ArticleBlog +} from './blog.component'; + +import { + createComponentFromClass, + quickCreateComponent, + provideEmptyObjects, + createProviderToValue, + getAngularService +} from "../../../../spec/helpers.ts"; // this htmlTemplate will be re-used between the container components in this spec file const htmlTemplate: string = ''; -let articleService: { getChildren: Function } = {}; +let articleService: { + getChildren: Function +} = < any > {}; describe("Blog Component", () => { @@ -18,7 +31,7 @@ describe("Blog Component", () => { // component Noosfero ArtileView will be load on our tests beforeEach(angular.mock.module("templates")); - function promiseResultTemplate(response?: {}) { + function promiseResultTemplate(response ? : {}) { let thenFuncEmpty = (func: Function) => { // does nothing }; @@ -57,8 +70,12 @@ describe("Blog Component", () => { providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] }) class BlogContainerComponent { - article = { type: 'anyArticleType' }; - profile = { name: 'profile-name' }; + article = { + type: 'anyArticleType' + }; + profile = { + name: 'profile-name' + }; } createComponentFromClass(BlogContainerComponent).then((fixture) => { @@ -72,18 +89,23 @@ describe("Blog Component", () => { }); + it("get $q service", () => { + let $q = getAngularService("$q"); + console.log($q); + }); + it("verify the blog data", (done: Function) => { // defining a mock result to articleService.getChildren method articleService.getChildren = (article_id: number, filters: {}) => { return promiseResultTemplate({ - headers: (headerName: string) => { - return 1; - }, - data: { - articles: [] - } - }); + headers: (headerName: string) => { + return 1; + }, + data: < any > { + articles: [] + } + }); }; @Component({ @@ -93,8 +115,12 @@ describe("Blog Component", () => { providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] }) class BlogContainerComponent { - article = { type: 'anyArticleType' }; - profile = { name: 'profile-name' }; + article = { + type: 'anyArticleType' + }; + profile = { + name: 'profile-name' + }; } createComponentFromClass(BlogContainerComponent).then((fixture) => { @@ -103,8 +129,8 @@ describe("Blog Component", () => { let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance; // check if the component property are the provided by the mocked articleService - expect((articleBlog)["posts"]).toEqual([]); - expect((articleBlog)["totalPosts"]).toEqual(1); + expect(( < any > articleBlog)["posts"]).toEqual([]); + expect(( < any > articleBlog)["totalPosts"]).toEqual(1); // done needs to be called (it isn't really needed, as we can read in @@ -116,4 +142,4 @@ describe("Blog Component", () => { }); -}); +}); \ No newline at end of file diff --git a/src/spec/helpers.ts b/src/spec/helpers.ts index 3c8ebee..ae7cf6f 100644 --- a/src/spec/helpers.ts +++ b/src/spec/helpers.ts @@ -1,6 +1,6 @@ import {ngClass, TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; -import {Provider, Input, provide, Component} from 'ng-forward'; +import {Injectable, Inject, Provider, Input, provide, Component} from 'ng-forward'; import {User, Person} from "./../app/models/interfaces"; @@ -48,6 +48,28 @@ export function provideFilters(...filters: string[]) { return providers; } +/** + * This help function allows get angular services to be used in integration tests + * i.e: '$http', '$q', '$location', etc... + */ +export function getAngularService(angularService: string) { + let tcb: TestComponentBuilder = new TestComponentBuilder(); + + @Component({ + selector: 'helper_get_angular_service', + template: 'not-used', + providers: [] + }) + class AnyService { + constructor() { + + } + } + + let fixture: ComponentFixture = (tcb)["create"](AnyService); + return fixture.debugElement.getLocal(angularService); +} + export var fixtures = { user: { id: 1, -- libgit2 0.21.2