Commit 97702802b2f1dbb0d73d8f2bbeba95c35f7b828b
1 parent
e882651c
Exists in
master
and in
34 other branches
new helpers methods
Showing
2 changed files
with
57 additions
and
23 deletions
Show diff stats
src/app/components/noosfero-articles/blog/blog.component.spec.ts
... | ... | @@ -12,7 +12,7 @@ import { |
12 | 12 | quickCreateComponent, |
13 | 13 | provideEmptyObjects, |
14 | 14 | createProviderToValue, |
15 | - getAngularService | |
15 | + getQService | |
16 | 16 | } from "../../../../spec/helpers.ts"; |
17 | 17 | |
18 | 18 | |
... | ... | @@ -21,7 +21,7 @@ const htmlTemplate: string = '<noosfero-blog [article]="ctrl.article" [profile]= |
21 | 21 | |
22 | 22 | let articleService: { |
23 | 23 | getChildren: Function |
24 | -} = < any > {}; | |
24 | +} = <any>{}; | |
25 | 25 | |
26 | 26 | describe("Blog Component", () => { |
27 | 27 | |
... | ... | @@ -31,7 +31,7 @@ describe("Blog Component", () => { |
31 | 31 | // component Noosfero ArtileView will be load on our tests |
32 | 32 | beforeEach(angular.mock.module("templates")); |
33 | 33 | |
34 | - function promiseResultTemplate(response ? : {}) { | |
34 | + function promiseResultTemplate(response?: {}) { | |
35 | 35 | let thenFuncEmpty = (func: Function) => { |
36 | 36 | // does nothing |
37 | 37 | }; |
... | ... | @@ -90,7 +90,7 @@ describe("Blog Component", () => { |
90 | 90 | }); |
91 | 91 | |
92 | 92 | it("get $q service", () => { |
93 | - let $q = getAngularService<ng.IQService>("$q"); | |
93 | + let $q: ng.IQService = getQService(); | |
94 | 94 | console.log($q); |
95 | 95 | }); |
96 | 96 | |
... | ... | @@ -102,7 +102,7 @@ describe("Blog Component", () => { |
102 | 102 | headers: (headerName: string) => { |
103 | 103 | return 1; |
104 | 104 | }, |
105 | - data: < any > { | |
105 | + data: <any>{ | |
106 | 106 | articles: [] |
107 | 107 | } |
108 | 108 | }); |
... | ... | @@ -128,9 +128,9 @@ describe("Blog Component", () => { |
128 | 128 | // gets the children component of BlogContainerComponent |
129 | 129 | let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance; |
130 | 130 | |
131 | - // check if the component property are the provided by the mocked articleService | |
132 | - expect(( < any > articleBlog)["posts"]).toEqual([]); | |
133 | - expect(( < any > articleBlog)["totalPosts"]).toEqual(1); | |
131 | + // check if the component property are the provided by the mocked articleService | |
132 | + expect((<any>articleBlog)["posts"]).toEqual([]); | |
133 | + expect((<any>articleBlog)["totalPosts"]).toEqual(1); | |
134 | 134 | |
135 | 135 | |
136 | 136 | // done needs to be called (it isn't really needed, as we can read in |
... | ... | @@ -142,4 +142,4 @@ describe("Blog Component", () => { |
142 | 142 | |
143 | 143 | }); |
144 | 144 | |
145 | -}); | |
146 | 145 | \ No newline at end of file |
146 | +}); | ... | ... |
src/spec/helpers.ts
... | ... | @@ -48,28 +48,62 @@ export function provideFilters(...filters: string[]) { |
48 | 48 | return providers; |
49 | 49 | } |
50 | 50 | |
51 | + | |
52 | +@Component({ | |
53 | + selector: 'helper_get_angular_service', | |
54 | + template: 'not-used', | |
55 | + providers: [] | |
56 | +}) | |
57 | +class AngularServiceHookComponent { | |
58 | + constructor() { | |
59 | + | |
60 | + } | |
61 | +} | |
62 | + | |
63 | +class AngularServiceFactory { | |
64 | + fixtureComponentHookPoint: ComponentFixture; | |
65 | + tcb: TestComponentBuilder = new TestComponentBuilder(); | |
66 | + | |
67 | + constructor() { | |
68 | + this.fixtureComponentHookPoint = (<any>this.tcb)["create"](AngularServiceHookComponent); | |
69 | + } | |
70 | + | |
71 | + getAngularService<T>(angularService: string) { | |
72 | + return this.fixtureComponentHookPoint.debugElement.getLocal(angularService); | |
73 | + } | |
74 | + | |
75 | + getQService(): ng.IQService { | |
76 | + return this.getAngularService<ng.IQService>("$q"); | |
77 | + } | |
78 | + | |
79 | + getHttpBackendService(): ng.IHttpBackendService { | |
80 | + return this.getAngularService<ng.IHttpBackendService>("$httpBackend"); | |
81 | + } | |
82 | +} | |
83 | + | |
84 | +export var angularServiceFactory = new AngularServiceFactory(); | |
51 | 85 | /** |
52 | 86 | * This help function allows get angular services to be used in integration tests |
53 | 87 | * i.e: '$http', '$q', '$location', etc... |
54 | 88 | */ |
55 | 89 | export function getAngularService<T>(angularService: string) { |
56 | - let tcb: TestComponentBuilder = new TestComponentBuilder(); | |
57 | - | |
58 | - @Component({ | |
59 | - selector: 'helper_get_angular_service', | |
60 | - template: 'not-used', | |
61 | - providers: [] | |
62 | - }) | |
63 | - class AnyService { | |
64 | - constructor() { | |
90 | + return angularServiceFactory.getAngularService(angularService); | |
91 | +} | |
65 | 92 | |
66 | - } | |
67 | - } | |
93 | +export function getQService(): ng.IQService { | |
94 | + return angularServiceFactory.getQService(); | |
95 | +} | |
68 | 96 | |
69 | - let fixture: ComponentFixture = (<any>tcb)["create"](AnyService); | |
70 | - return fixture.debugElement.getLocal(angularService); | |
97 | +export function getHttpBackendService(): ng.IHttpBackendService { | |
98 | + return angularServiceFactory.getHttpBackendService(); | |
71 | 99 | } |
72 | 100 | |
101 | +// export function getResolvablePromise() { | |
102 | +// let $q = getQService(); | |
103 | +// | |
104 | +// return null; | |
105 | +// } | |
106 | + | |
73 | 107 | export var fixtures = { |
74 | 108 | user: { |
75 | 109 | id: 1, |
... | ... | @@ -82,4 +116,4 @@ export var fixtures = { |
82 | 116 | private_token: 'token', |
83 | 117 | userRole: 'admin' |
84 | 118 | } |
85 | -}; | |
86 | 119 | \ No newline at end of file |
120 | +}; | ... | ... |