Commit 225708d81f7aefb1056602e15a07bdfb9ee822f2
Exists in
helpers-evolution
ll
Showing
24 changed files
with
643 additions
and
189 deletions
Show diff stats
... | ... | @@ -0,0 +1,54 @@ |
1 | +import {quickCreateComponent} from "../../spec/helpers"; | |
2 | +import {Cms} from "./cms.component"; | |
3 | + | |
4 | +describe("Components", () => { | |
5 | + describe("Cms Component", () => { | |
6 | + | |
7 | + let $rootScope: ng.IRootScopeService; | |
8 | + let $q: ng.IQService; | |
9 | + let articleServiceMock: any; | |
10 | + let profileServiceMock: any; | |
11 | + let $state: any; | |
12 | + let sweetAlert: any; | |
13 | + | |
14 | + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { | |
15 | + $rootScope = _$rootScope_; | |
16 | + $q = _$q_; | |
17 | + })); | |
18 | + | |
19 | + beforeEach(() => { | |
20 | + $state = jasmine.createSpyObj("$state", ["transitionTo"]); | |
21 | + sweetAlert = jasmine.createSpyObj("SweetAlert", ["swal"]); | |
22 | + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile"]); | |
23 | + articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["create"]); | |
24 | + | |
25 | + let getCurrentProfileResponse = $q.defer(); | |
26 | + getCurrentProfileResponse.resolve({ id: 1 }); | |
27 | + | |
28 | + let articleCreate = $q.defer(); | |
29 | + articleCreate.resolve({ data: { article: { path: "path", profile: { identifier: "profile" } } } }); | |
30 | + | |
31 | + profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise); | |
32 | + articleServiceMock.create = jasmine.createSpy("create").and.returnValue(articleCreate.promise); | |
33 | + }); | |
34 | + | |
35 | + it("create an article in the current profile when save", done => { | |
36 | + let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, sweetAlert); | |
37 | + component.save(); | |
38 | + $rootScope.$apply(); | |
39 | + expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); | |
40 | + expect(articleServiceMock.create).toHaveBeenCalledWith(1, component.article); | |
41 | + done(); | |
42 | + }); | |
43 | + | |
44 | + it("got to the new article page and display an alert when saving sucessfully", done => { | |
45 | + let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, sweetAlert); | |
46 | + component.save(); | |
47 | + $rootScope.$apply(); | |
48 | + expect($state.transitionTo).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "profile" }); | |
49 | + expect(sweetAlert.swal).toHaveBeenCalled(); | |
50 | + done(); | |
51 | + }); | |
52 | + | |
53 | + }); | |
54 | +}); | ... | ... |
src/app/cms/cms.component.ts
1 | -import {StateConfig, Component, Inject} from 'ng-forward'; | |
1 | +import {StateConfig, Component, Inject, provide} from 'ng-forward'; | |
2 | 2 | import {Profile} from "./../models/interfaces"; |
3 | 3 | import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; |
4 | +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; | |
4 | 5 | |
5 | 6 | @Component({ |
6 | 7 | selector: 'cms', |
7 | - templateUrl: "app/cms/cms.html" | |
8 | + templateUrl: "app/cms/cms.html", | |
9 | + providers: [ | |
10 | + provide('articleService', { useClass: ArticleService }), | |
11 | + provide('profileService', { useClass: ProfileService }) | |
12 | + ] | |
8 | 13 | }) |
9 | -@Inject(ArticleService, "noosfero", "$stateParams", "$httpParamSerializer", "$state", "SweetAlert") | |
14 | +@Inject(ArticleService, ProfileService, "$state", "SweetAlert") | |
10 | 15 | export class Cms { |
11 | 16 | |
12 | 17 | article: any = {}; |
13 | - profile: any; | |
14 | 18 | |
15 | - constructor(private ArticleService: ArticleService, private noosfero: any/* TODO convert noosferoService */, private $stateParams: ng.ui.IStateParamsService, private $httpParamSerializer: any, private $state: ng.ui.IStateService, private SweetAlert: any) { | |
16 | - | |
17 | - } | |
19 | + constructor(private articleService: ArticleService, | |
20 | + private profileService: ProfileService, | |
21 | + private $state: ng.ui.IStateService, private SweetAlert: any) { } | |
18 | 22 | |
19 | 23 | save() { |
20 | - this.noosfero.currentProfile.then((profile: Profile) => { | |
21 | - return this.ArticleService.create(profile.id, this.article); | |
24 | + this.profileService.getCurrentProfile().then((profile: Profile) => { | |
25 | + return this.articleService.create(profile.id, this.article); | |
22 | 26 | }).then((response: restangular.IResponse) => { |
23 | 27 | this.$state.transitionTo('main.profile.page', { page: response.data.article.path, profile: response.data.article.profile.identifier }); |
24 | 28 | this.SweetAlert.swal({ | ... | ... |
src/app/components/auth/auth_controller.ts
... | ... | @@ -3,7 +3,7 @@ import {AuthService} from "./auth_service"; |
3 | 3 | |
4 | 4 | export class AuthController { |
5 | 5 | |
6 | - static $inject = ["noosfero", "$log", "$stateParams", "AuthService"]; | |
6 | + static $inject = ["$log", "$stateParams", "AuthService"]; | |
7 | 7 | |
8 | 8 | constructor( |
9 | 9 | private noosfero: any, | ... | ... |
src/app/components/navbar/navbar.spec.ts
1 | 1 | <<<<<<< Updated upstream |
2 | 2 | import { |
3 | - createComponentFromClass, | |
4 | - quickCreateComponent, | |
5 | - provideEmptyObjects | |
3 | +createComponentFromClass, | |
4 | +quickCreateComponent, | |
5 | +provideEmptyObjects | |
6 | 6 | } from "./../../../spec/helpers"; |
7 | 7 | ======= |
8 | 8 | import * as helpers from "./../../../spec/helpers"; |
9 | 9 | >>>>>>> Stashed changes |
10 | 10 | import { |
11 | - Navbar | |
11 | +Navbar | |
12 | 12 | } from "./navbar"; |
13 | 13 | import { |
14 | - AUTH_EVENTS | |
14 | +AUTH_EVENTS | |
15 | 15 | } from "./../auth"; |
16 | 16 | import { |
17 | - User | |
17 | +User | |
18 | 18 | } from "./../../models/interfaces"; |
19 | 19 | import { |
20 | - Injectable, | |
21 | - Provider, | |
22 | - provide | |
20 | +Injectable, | |
21 | +Provider, | |
22 | +provide | |
23 | 23 | } from "ng-forward"; |
24 | 24 | |
25 | +<<<<<<< HEAD | |
25 | 26 | <<<<<<< Updated upstream |
26 | 27 | ======= |
27 | 28 | import { |
... | ... | @@ -31,19 +32,21 @@ AuthController, |
31 | 32 | IAuthEvents |
32 | 33 | } from "./../auth"; |
33 | 34 | >>>>>>> Stashed changes |
35 | +======= | |
36 | +import {Session, AuthService, AuthController, IAuthEvents} from "./../auth"; | |
37 | +>>>>>>> f4c0320e49cdd2aed7abc9e3718da9f9811d11dd | |
34 | 38 | |
35 | 39 | describe("Components", () => { |
36 | 40 | |
37 | - | |
38 | 41 | describe("Navbar Component", () => { |
39 | 42 | |
40 | 43 | let $rootScope: ng.IRootScopeService; |
44 | + | |
41 | 45 | let user = <User>{ |
42 | 46 | id: 1, |
43 | 47 | login: "user" |
44 | 48 | }; |
45 | 49 | |
46 | - | |
47 | 50 | let scope = { |
48 | 51 | eventCalledHook: () => { }, |
49 | 52 | $on: (eventName: string, func: Function) => { |
... | ... | @@ -96,6 +99,7 @@ describe("Components", () => { |
96 | 99 | }) |
97 | 100 | ]; |
98 | 101 | |
102 | + | |
99 | 103 | beforeEach(angular.mock.module("templates")); |
100 | 104 | |
101 | 105 | // beforeEach(inject((_$rootScope_: ng.IRootScopeService) => { |
... | ... | @@ -105,7 +109,6 @@ describe("Components", () => { |
105 | 109 | it('should get the loggedIn user', (done: Function) => { |
106 | 110 | |
107 | 111 | let scope = jasmine.createSpyObj("scope", ["$on"]); |
108 | - | |
109 | 112 | let providers = [ |
110 | 113 | helpers.provideEmptyObjects('moment', '$modal', 'AuthService', '$state'), |
111 | 114 | new Provider('Session', { |
... | ... | @@ -137,10 +140,16 @@ describe("Components", () => { |
137 | 140 | }); |
138 | 141 | }); |
139 | 142 | |
143 | +<<<<<<< HEAD | |
140 | 144 | |
141 | 145 | it('should open on click', (done: Function) => { |
142 | 146 | |
143 | 147 | helpers.quickCreateComponent({ |
148 | +======= | |
149 | + it('should open on click', (done: Function) => { | |
150 | + | |
151 | + quickCreateComponent({ | |
152 | +>>>>>>> f4c0320e49cdd2aed7abc9e3718da9f9811d11dd | |
144 | 153 | providers: providers, |
145 | 154 | template: "<acme-navbar></acme-navbar>", |
146 | 155 | directives: [Navbar] |
... | ... | @@ -152,17 +161,21 @@ describe("Components", () => { |
152 | 161 | expect($modal.open).toHaveBeenCalled(); |
153 | 162 | expect($modal.open).toHaveBeenCalledWith({ |
154 | 163 | templateUrl: 'app/components/auth/login.html', |
155 | - controller: 'AuthController', | |
164 | + controller: AuthController, | |
156 | 165 | controllerAs: 'vm', |
157 | 166 | bindToController: true |
158 | - }) | |
167 | + }); | |
159 | 168 | done(); |
160 | 169 | }); |
161 | 170 | }); |
162 | 171 | |
163 | 172 | it('should logout', (done: Function) => { |
164 | 173 | |
174 | +<<<<<<< HEAD | |
165 | 175 | helpers.quickCreateComponent({ |
176 | +======= | |
177 | + quickCreateComponent({ | |
178 | +>>>>>>> f4c0320e49cdd2aed7abc9e3718da9f9811d11dd | |
166 | 179 | providers: providers, |
167 | 180 | template: "<acme-navbar></acme-navbar>", |
168 | 181 | directives: [Navbar] |
... | ... | @@ -256,7 +269,42 @@ describe("Components", () => { |
256 | 269 | navbarComp.activate(); |
257 | 270 | navbarComp.openLogin(); |
258 | 271 | |
272 | +<<<<<<< HEAD | |
259 | 273 | let openArgs = { templateUrl: 'app/components/auth/login.html', controller: Function, controllerAs: 'vm', bindToController: true }; |
274 | +======= | |
275 | + it('should not activate user when logged in', (done: Function) => { | |
276 | + quickCreateComponent({ | |
277 | + providers: providers, | |
278 | + template: "<acme-navbar></acme-navbar>", | |
279 | + directives: [Navbar] | |
280 | + }) | |
281 | + .then(fixture => { | |
282 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
283 | + spyOn(navbarComp, "openLogin"); | |
284 | + navbarComp.activate(); | |
285 | + expect((<any>navbarComp.openLogin).calls.count()).toBe(0); | |
286 | + done(); | |
287 | + }) | |
288 | + | |
289 | + }); | |
290 | + | |
291 | + it('should activate when user not logged in', (done: Function) => { | |
292 | + user = null; | |
293 | + quickCreateComponent({ | |
294 | + providers: providers, | |
295 | + template: "<acme-navbar></acme-navbar>", | |
296 | + directives: [Navbar] | |
297 | + }) | |
298 | + .then(fixture => { | |
299 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
300 | + spyOn(navbarComp, "openLogin"); | |
301 | + navbarComp.activate(); | |
302 | + expect(navbarComp.openLogin).toHaveBeenCalled(); | |
303 | + done(); | |
304 | + }) | |
305 | + }); | |
306 | + | |
307 | +>>>>>>> f4c0320e49cdd2aed7abc9e3718da9f9811d11dd | |
260 | 308 | |
261 | 309 | |
262 | 310 | expect($modal.open).toHaveBeenCalled(); | ... | ... |
src/app/components/noosfero-articles/blog/blog.component.spec.ts
1 | 1 | import { |
2 | + providers | |
3 | +} from 'ng-forward/cjs/testing/providers'; | |
4 | + | |
5 | +import { | |
2 | 6 | Input, |
3 | - provide, | |
4 | 7 | Component |
5 | 8 | } from 'ng-forward'; |
6 | 9 | import { |
... | ... | @@ -12,26 +15,16 @@ import { |
12 | 15 | quickCreateComponent, |
13 | 16 | provideEmptyObjects, |
14 | 17 | createProviderToValue, |
15 | - getQService | |
18 | + getAngularService, | |
19 | + provideFilters | |
16 | 20 | } from "../../../../spec/helpers.ts"; |
17 | 21 | |
18 | - | |
19 | 22 | // this htmlTemplate will be re-used between the container components in this spec file |
20 | 23 | const htmlTemplate: string = '<noosfero-blog [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-blog>'; |
21 | 24 | |
22 | -let articleService: { | |
23 | - getChildren: Function | |
24 | -} = <any>{}; | |
25 | - | |
26 | 25 | describe("Blog Component", () => { |
27 | 26 | |
28 | - // the karma preprocessor html2js transform the templates html into js files which put | |
29 | - // the templates to the templateCache into the module templates | |
30 | - // we need to load the module templates here as the template for the | |
31 | - // component Noosfero ArtileView will be load on our tests | |
32 | - beforeEach(angular.mock.module("templates")); | |
33 | - | |
34 | - function promiseResultTemplate(response?: {}) { | |
27 | + function promiseResultTemplate(response ? : {}) { | |
35 | 28 | let thenFuncEmpty = (func: Function) => { |
36 | 29 | // does nothing |
37 | 30 | }; |
... | ... | @@ -50,48 +43,56 @@ describe("Blog Component", () => { |
50 | 43 | } |
51 | 44 | } |
52 | 45 | |
53 | - beforeAll(() => { | |
54 | - // creating mock for articleService | |
55 | - articleService = { | |
56 | - getChildren: (article_id: number, filters: {}) => { | |
57 | - return promiseResultTemplate(null); | |
58 | - } | |
46 | + let articleService = { | |
47 | + getChildren: (article_id: number, filters: {}) => { | |
48 | + return promiseResultTemplate(null); | |
49 | + } | |
50 | + }; | |
51 | + | |
52 | + @Component({ | |
53 | + selector: 'test-container-component', | |
54 | + template: htmlTemplate, | |
55 | + directives: [ArticleBlog], | |
56 | + providers: [ | |
57 | + provideEmptyObjects('Restangular'), | |
58 | + createProviderToValue('ArticleService', articleService), | |
59 | + provideFilters('truncateFilter') | |
60 | + ] | |
61 | + }) | |
62 | + class BlogContainerComponent { | |
63 | + article = { | |
64 | + type: 'anyArticleType' | |
65 | + }; | |
66 | + profile = { | |
67 | + name: 'profile-name' | |
59 | 68 | }; |
69 | + } | |
70 | + | |
71 | + beforeEach(() => { | |
72 | + | |
73 | + // the karma preprocessor html2js transform the templates html into js files which put | |
74 | + // the templates to the templateCache into the module templates | |
75 | + // we need to load the module templates here as the template for the | |
76 | + // component Noosfero ArtileView will be load on our tests | |
77 | + angular.mock.module("templates") | |
78 | + | |
79 | + providers((provide: any) => { | |
80 | + return <any > [ | |
81 | + provide('ArticleService', { | |
82 | + useValue: articleService | |
83 | + }) | |
84 | + ] | |
85 | + }); | |
60 | 86 | }); |
61 | 87 | |
62 | 88 | it("renders the blog content", (done: Function) => { |
63 | 89 | |
64 | - // Creating a container component (ArticleContainerComponent) to include | |
65 | - // the component under test (ArticleView) | |
66 | - @Component({ | |
67 | - selector: 'test-container-component', | |
68 | - template: htmlTemplate, | |
69 | - directives: [ArticleBlog], | |
70 | - providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] | |
71 | - }) | |
72 | - class BlogContainerComponent { | |
73 | - article = { | |
74 | - type: 'anyArticleType' | |
75 | - }; | |
76 | - profile = { | |
77 | - name: 'profile-name' | |
78 | - }; | |
79 | - } | |
80 | - | |
81 | 90 | createComponentFromClass(BlogContainerComponent).then((fixture) => { |
82 | 91 | |
83 | 92 | expect(fixture.debugElement.query('div.blog').length).toEqual(1); |
84 | 93 | |
85 | 94 | done(); |
86 | 95 | }); |
87 | - | |
88 | - | |
89 | - | |
90 | - }); | |
91 | - | |
92 | - it("get $q service", () => { | |
93 | - let $q: ng.IQService = getQService(); | |
94 | - console.log($q); | |
95 | 96 | }); |
96 | 97 | |
97 | 98 | it("verify the blog data", (done: Function) => { |
... | ... | @@ -102,44 +103,31 @@ describe("Blog Component", () => { |
102 | 103 | headers: (headerName: string) => { |
103 | 104 | return 1; |
104 | 105 | }, |
105 | - data: <any>{ | |
106 | - articles: [] | |
106 | + data: < any > { | |
107 | + articles: [{ | |
108 | + id: 1, | |
109 | + title: 'The article test' | |
110 | + }] | |
107 | 111 | } |
108 | 112 | }); |
109 | 113 | }; |
110 | 114 | |
111 | - @Component({ | |
112 | - selector: 'test-container-component', | |
113 | - template: htmlTemplate, | |
114 | - directives: [ArticleBlog], | |
115 | - providers: [provideEmptyObjects('Restangular'), createProviderToValue('ArticleService', articleService)] | |
116 | - }) | |
117 | - class BlogContainerComponent { | |
118 | - article = { | |
119 | - type: 'anyArticleType' | |
120 | - }; | |
121 | - profile = { | |
122 | - name: 'profile-name' | |
123 | - }; | |
124 | - } | |
125 | - | |
126 | 115 | createComponentFromClass(BlogContainerComponent).then((fixture) => { |
127 | 116 | |
128 | 117 | // gets the children component of BlogContainerComponent |
129 | 118 | let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance; |
130 | 119 | |
131 | 120 | // 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 | - | |
121 | + let post = { | |
122 | + id: 1, | |
123 | + title: 'The article test' | |
124 | + }; | |
125 | + expect(( < any > articleBlog)["posts"][0]).toEqual(jasmine.objectContaining(post)); | |
126 | + expect(( < any > articleBlog)["totalPosts"]).toEqual(1); | |
135 | 127 | |
136 | - // done needs to be called (it isn't really needed, as we can read in | |
137 | - // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync) | |
138 | - // because createAsync in ng-forward is not really async, but as the intention | |
139 | - // here is write tests in angular 2 ways, this is recommended | |
140 | 128 | done(); |
141 | 129 | }); |
142 | 130 | |
143 | 131 | }); |
144 | 132 | |
145 | 133 | -}); |
134 | +}); | |
146 | 135 | \ No newline at end of file | ... | ... |
src/app/components/noosfero-blocks/members-block/members-block.component.ts
... | ... | @@ -13,12 +13,12 @@ export class MembersBlock { |
13 | 13 | |
14 | 14 | members: any = []; |
15 | 15 | |
16 | - constructor(private ProfileService: ProfileService) { | |
16 | + constructor(private profileService: ProfileService) { | |
17 | 17 | |
18 | 18 | } |
19 | 19 | |
20 | 20 | ngOnInit() { |
21 | - this.ProfileService.getProfileMembers(this.owner.id, { per_page: 6 }).then((response: any) => { | |
21 | + this.profileService.getProfileMembers(this.owner.id, { per_page: 6 }).then((response: any) => { | |
22 | 22 | this.members = response.data.people; |
23 | 23 | }); |
24 | 24 | } | ... | ... |
src/app/components/noosfero-blocks/profile-image/profile-image.component.spec.ts
1 | -import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder'; | |
1 | +import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; | |
2 | 2 | import {Pipe, Input, provide, Component} from 'ng-forward'; |
3 | 3 | |
4 | 4 | import {ProfileImageBlock} from './profile-image.component'; |
5 | 5 | |
6 | +import {ProfileService} from "./../../../../lib/ng-noosfero-api/http/profile.service"; | |
7 | + | |
8 | +import * as helpers from "./../../../../spec/helpers"; | |
9 | + | |
6 | 10 | const tcb = new TestComponentBuilder(); |
7 | 11 | |
8 | 12 | const htmlTemplate: string = '<noosfero-profile-image-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-profile-image-block>'; |
9 | 13 | |
10 | 14 | |
15 | + | |
16 | + | |
11 | 17 | describe("Components", () => { |
12 | 18 | describe("Profile Image Block Component", () => { |
13 | 19 | |
14 | 20 | beforeEach(angular.mock.module("templates")); |
21 | + | |
22 | + //beforeEach(angular.mock.module("restangular")); | |
23 | + | |
24 | + function buildServiceMock() { | |
25 | + let profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getActivities"]); | |
26 | + | |
27 | + let thenObj = jasmine.createSpyObj("thenObj", ["then"]); | |
28 | + | |
29 | + thenObj.then = (func: Function) => { | |
30 | + func({ | |
31 | + data: { | |
32 | + image: { | |
33 | + name: 'some-thing', | |
34 | + url: 'http://image.com' | |
35 | + } | |
36 | + } | |
37 | + }) | |
38 | + } | |
39 | + | |
40 | + profileServiceMock.getActivities = jasmine.createSpy("getActivities").and.returnValue(thenObj); | |
41 | + | |
42 | + return profileServiceMock; | |
43 | + } | |
15 | 44 | |
16 | - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ProfileImageBlock] }) | |
45 | + @Component( | |
46 | + { | |
47 | + selector: 'test-container-component', | |
48 | + template: htmlTemplate, | |
49 | + directives: [ProfileImageBlock], | |
50 | + providers: [helpers.createProviderToValue("ProfileService", buildServiceMock())] | |
51 | + | |
52 | + }) | |
17 | 53 | class BlockContainerComponent { |
18 | 54 | block = { type: 'Block' }; |
19 | 55 | owner = { name: 'profile-name' }; |
20 | 56 | constructor() { |
21 | 57 | } |
22 | 58 | } |
59 | + | |
60 | + | |
23 | 61 | |
24 | - it("render the profile image", done => { | |
25 | - tcb.createAsync(BlockContainerComponent).then(fixture => { | |
26 | - expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); | |
27 | - done(); | |
62 | + it("show image if present", () => { | |
63 | + let profileServiceMock = buildServiceMock(); | |
64 | + helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { | |
65 | + var elProfile = fixture.debugElement.componentViewChildren[0]; | |
66 | + expect(elProfile.query('div.profile-image-block').length).toEqual(1); | |
28 | 67 | }); |
29 | 68 | }); |
30 | - | |
31 | - it("render the settings link", done => { | |
32 | - tcb.createAsync(BlockContainerComponent).then(fixture => { | |
33 | - expect(fixture.debugElement.queryAll(".settings-link").length).toEqual(1); | |
34 | - done(); | |
35 | - }); | |
69 | + | |
70 | + //TODO | |
71 | + it("not show image if image is missing", () => { | |
72 | + | |
36 | 73 | }); |
74 | + | |
75 | + it("has link to the profile", () => { | |
76 | + | |
77 | + }); | |
78 | + | |
79 | + it("get activitities from profileService", () => { | |
80 | + | |
81 | + | |
82 | + let profileServiceMock = buildServiceMock(); | |
83 | + | |
84 | + let profileImageBlock = new ProfileImageBlock(<any>profileServiceMock); | |
85 | + | |
86 | + profileImageBlock.ngOnInit(); | |
87 | + expect(profileServiceMock.getActivities).toHaveBeenCalled(); | |
88 | + expect(profileImageBlock.image.name).toEqual("some-thing"); | |
89 | + }) | |
90 | + | |
91 | + // it("render the profile image", done => { | |
92 | + // tcb.createAsync(BlockContainerComponent).then(fixture => { | |
93 | + // expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); | |
94 | + // done(); | |
95 | + // }); | |
96 | + // }); | |
97 | + // | |
98 | + // it("render the settings link", done => { | |
99 | + // tcb.createAsync(BlockContainerComponent).then(fixture => { | |
100 | + // expect(fixture.debugElement.queryAll(".settings-link").length).toEqual(1); | |
101 | + // done(); | |
102 | + // }); | |
103 | + // }); | |
37 | 104 | |
38 | 105 | }); |
39 | 106 | }); |
40 | 107 | \ No newline at end of file | ... | ... |
src/app/components/noosfero-blocks/profile-image/profile-image.component.ts
1 | -import {Input, Component} from "ng-forward"; | |
1 | +import {Inject, Input, Component} from "ng-forward"; | |
2 | +import {ProfileService} from "./../../../../lib/ng-noosfero-api/http/profile.service"; | |
2 | 3 | |
3 | 4 | @Component({ |
4 | 5 | selector: "noosfero-profile-image-block", |
5 | 6 | templateUrl: 'app/components/noosfero-blocks/profile-image/profile-image.html', |
7 | + providers: [ProfileService] | |
6 | 8 | }) |
9 | +@Inject(ProfileService) | |
7 | 10 | export class ProfileImageBlock { |
8 | 11 | |
9 | 12 | @Input() block: any; |
10 | 13 | @Input() owner: any; |
14 | + | |
15 | + image: any; | |
16 | + | |
17 | + constructor(private profileService: ProfileService) { | |
18 | + | |
19 | + } | |
20 | + | |
21 | + ngOnInit() { | |
22 | + this.profileService.getActivities(null, {}).then((resp:any) => { | |
23 | + this.image = resp.data.image; | |
24 | + }) | |
25 | + } | |
11 | 26 | |
12 | 27 | } | ... | ... |
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
... | ... | @@ -13,10 +13,10 @@ export class RecentDocumentsBlock { |
13 | 13 | |
14 | 14 | profile: any; |
15 | 15 | documents: any; |
16 | - | |
16 | + | |
17 | 17 | documentsLoaded: boolean = false; |
18 | 18 | |
19 | - constructor(private ArticleService: ArticleService, private $state: any) { | |
19 | + constructor(private articleService: ArticleService, private $state: any) { | |
20 | 20 | } |
21 | 21 | |
22 | 22 | ngOnInit() { |
... | ... | @@ -25,7 +25,7 @@ export class RecentDocumentsBlock { |
25 | 25 | |
26 | 26 | var limit = (this.block && this.block.settings) ? this.block.settings.limit : null || 5; |
27 | 27 | //FIXME get all text articles |
28 | - this.ArticleService.getByProfile(this.profile.id, { content_type: 'TinyMceArticle', per_page: limit }).then((response: any) => { | |
28 | + this.articleService.getByProfile(this.profile.id, { content_type: 'TinyMceArticle', per_page: limit }).then((response: any) => { | |
29 | 29 | this.documents = response.data.articles; |
30 | 30 | this.documentsLoaded = true; |
31 | 31 | }); |
... | ... | @@ -36,4 +36,3 @@ export class RecentDocumentsBlock { |
36 | 36 | } |
37 | 37 | |
38 | 38 | } |
39 | - | ... | ... |
src/app/components/noosfero/noosfero.service.js
... | ... | @@ -1,12 +0,0 @@ |
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - | |
4 | - angular.module('noosferoApp').factory('noosfero', function(Restangular, $q) { | |
5 | - var currentProfile = $q.defer(); | |
6 | - | |
7 | - return { | |
8 | - currentProfile: currentProfile.promise, | |
9 | - setCurrentProfile: function(profile) { currentProfile.resolve(profile) } | |
10 | - } | |
11 | - }); | |
12 | -})(); |
src/app/content-viewer/content-viewer-actions.component.ts
1 | -import {Component, Inject} from "ng-forward"; | |
1 | +import {Component, Inject, provide} from "ng-forward"; | |
2 | +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; | |
2 | 3 | |
3 | 4 | import {Profile} from "./../models/interfaces"; |
5 | + | |
4 | 6 | @Component({ |
5 | 7 | selector: "content-viewer-actions", |
6 | 8 | templateUrl: "app/content-viewer/navbar-actions.html", |
9 | + providers: [provide('profileService', { useClass: ProfileService })] | |
7 | 10 | }) |
8 | -@Inject("noosfero") | |
11 | +@Inject(ProfileService) | |
9 | 12 | export class ContentViewerActions { |
10 | 13 | |
11 | 14 | article: any; |
12 | 15 | profile: any; |
13 | 16 | |
14 | - constructor(noosfero: any) { | |
15 | - noosfero.currentProfile.then((profile: Profile) => { | |
17 | + constructor(profileService: ProfileService) { | |
18 | + profileService.getCurrentProfile().then((profile: Profile) => { | |
16 | 19 | this.profile = profile; |
17 | 20 | }); |
18 | 21 | } | ... | ... |
src/app/content-viewer/content-viewer.component.ts
... | ... | @@ -2,17 +2,22 @@ import * as noosfero from "../models/interfaces"; |
2 | 2 | |
3 | 3 | |
4 | 4 | import {ArticleView} from "../components/noosfero-articles/article/article_view"; |
5 | -import {Input, Component, StateConfig, Inject} from "ng-forward"; | |
5 | +import {Input, Component, StateConfig, Inject, provide} from "ng-forward"; | |
6 | 6 | |
7 | 7 | import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; |
8 | 8 | import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; |
9 | +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; | |
9 | 10 | |
10 | 11 | @Component({ |
11 | 12 | selector: "content-viewer", |
12 | 13 | templateUrl: "app/content-viewer/page.html", |
13 | - directives: [ArticleBlog, ArticleView] | |
14 | + directives: [ArticleBlog, ArticleView], | |
15 | + providers: [ | |
16 | + provide('articleService', { useClass: ArticleService }), | |
17 | + provide('profileService', { useClass: ProfileService }) | |
18 | + ] | |
14 | 19 | }) |
15 | -@Inject(ArticleService, "noosfero", "$log", "$stateParams") | |
20 | +@Inject(ArticleService, ProfileService, "$log", "$stateParams") | |
16 | 21 | export class ContentViewer { |
17 | 22 | |
18 | 23 | @Input() |
... | ... | @@ -21,14 +26,14 @@ export class ContentViewer { |
21 | 26 | @Input() |
22 | 27 | profile: noosfero.Profile = null; |
23 | 28 | |
24 | - constructor(private ArticleService: ArticleService, private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { | |
29 | + constructor(private articleService: ArticleService, private profileService: ProfileService, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { | |
25 | 30 | this.activate(); |
26 | 31 | } |
27 | 32 | |
28 | 33 | activate() { |
29 | - this.noosfero.currentProfile.then((profile: noosfero.Profile) => { | |
34 | + this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { | |
30 | 35 | this.profile = profile; |
31 | - return this.ArticleService.getByProfile(this.profile.id, { path: this.$stateParams["page"] }); | |
36 | + return this.articleService.getByProfile(this.profile.id, { path: this.$stateParams["page"] }); | |
32 | 37 | }).then((response: restangular.IResponse) => { |
33 | 38 | this.article = response.data.article; |
34 | 39 | }); | ... | ... |
src/app/index.ts
... | ... | @@ -28,7 +28,6 @@ NoosferoApp.addConstants("AUTH_EVENTS", AUTH_EVENTS); |
28 | 28 | NoosferoApp.addConfig(noosferoModuleConfig); |
29 | 29 | NoosferoApp.run(noosferoAngularRunBlock); |
30 | 30 | |
31 | -require("./components/noosfero/noosfero.service.js"); | |
32 | 31 | require("./components/noosfero/profile-image/profile-image.component.js"); |
33 | 32 | |
34 | 33 | NoosferoApp.addConfig(routeConfig); | ... | ... |
src/app/profile-info/profile-info.component.ts
1 | -import {StateConfig, Component, Inject} from 'ng-forward'; | |
1 | +import {StateConfig, Component, Inject, provide} from 'ng-forward'; | |
2 | 2 | |
3 | 3 | import {Profile} from "./../models/interfaces"; |
4 | 4 | import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; |
5 | 5 | |
6 | 6 | @Component({ |
7 | 7 | selector: 'profile', |
8 | - templateUrl: "app/profile-info/profile-info.html" | |
8 | + templateUrl: "app/profile-info/profile-info.html", | |
9 | + providers: [provide('profileService', { useClass: ProfileService })] | |
9 | 10 | }) |
10 | -@Inject(ProfileService, "noosfero") | |
11 | +@Inject(ProfileService) | |
11 | 12 | export class ProfileInfo { |
12 | 13 | |
13 | 14 | activities: any |
14 | 15 | profile: any |
15 | 16 | |
16 | - constructor(private ProfileService: ProfileService, private noosfero: any) { | |
17 | + constructor(private profileService: ProfileService) { | |
17 | 18 | this.activate(); |
18 | 19 | } |
19 | 20 | |
20 | 21 | activate() { |
21 | - this.noosfero.currentProfile.then((profile: Profile) => { | |
22 | + this.profileService.getCurrentProfile().then((profile: Profile) => { | |
22 | 23 | this.profile = profile; |
23 | - return this.ProfileService.getActivities(this.profile.id); | |
24 | + return this.profileService.getActivities(this.profile.id); | |
24 | 25 | }).then((response: restangular.IResponse) => { |
25 | 26 | this.activities = response.data.activities; |
26 | 27 | }); | ... | ... |
... | ... | @@ -0,0 +1,58 @@ |
1 | +import {quickCreateComponent} from "../../spec/helpers"; | |
2 | +import {ProfileHome} from "./profile-home.component"; | |
3 | + | |
4 | +describe("Components", () => { | |
5 | + describe("Profile Home Component", () => { | |
6 | + | |
7 | + let $rootScope: ng.IRootScopeService; | |
8 | + let $q: ng.IQService; | |
9 | + let homePageResponse: ng.IDeferred<any>; | |
10 | + let profileServiceMock: any; | |
11 | + let $state: any; | |
12 | + | |
13 | + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { | |
14 | + $rootScope = _$rootScope_; | |
15 | + $q = _$q_; | |
16 | + })); | |
17 | + | |
18 | + beforeEach(() => { | |
19 | + $state = jasmine.createSpyObj("$state", ["transitionTo"]); | |
20 | + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile", "getHomePage"]); | |
21 | + | |
22 | + let currentProfileResponse = $q.defer(); | |
23 | + currentProfileResponse.resolve({ identifier: "profile" }); | |
24 | + homePageResponse = $q.defer(); | |
25 | + | |
26 | + profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(currentProfileResponse.promise); | |
27 | + profileServiceMock.getHomePage = jasmine.createSpy("getHomePage").and.returnValue(homePageResponse.promise); | |
28 | + }); | |
29 | + | |
30 | + it("transition to profile homepage when there is a homepage setted", done => { | |
31 | + homePageResponse.resolve({ data: { article: { path: "something" } } }); | |
32 | + | |
33 | + let component: ProfileHome = new ProfileHome(profileServiceMock, $state); | |
34 | + $rootScope.$apply(); | |
35 | + expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); | |
36 | + expect(profileServiceMock.getHomePage).toHaveBeenCalled(); | |
37 | + | |
38 | + expect($state.transitionTo). | |
39 | + toHaveBeenCalledWith("main.profile.page", | |
40 | + { page: "something", profile: "profile" }, { location: false }); | |
41 | + done(); | |
42 | + }); | |
43 | + | |
44 | + it("transition to profile info page when there is no homepage setted", done => { | |
45 | + homePageResponse.resolve({ data: {} }); | |
46 | + | |
47 | + let component: ProfileHome = new ProfileHome(profileServiceMock, $state); | |
48 | + $rootScope.$apply(); | |
49 | + expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); | |
50 | + expect(profileServiceMock.getHomePage).toHaveBeenCalled(); | |
51 | + | |
52 | + expect($state.transitionTo). | |
53 | + toHaveBeenCalledWith("main.profile.info", | |
54 | + { profile: "profile" }, { location: false }); | |
55 | + done(); | |
56 | + }); | |
57 | + }); | |
58 | +}); | ... | ... |
src/app/profile/profile-home.component.ts
1 | -import {StateConfig, Component, Inject} from 'ng-forward'; | |
1 | +import {StateConfig, Component, Inject, provide} from 'ng-forward'; | |
2 | 2 | |
3 | 3 | import {Profile} from "./../models/interfaces"; |
4 | 4 | import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; |
5 | 5 | |
6 | 6 | @Component({ |
7 | 7 | selector: 'profile-home', |
8 | - template: "<div></div>" | |
8 | + template: "<div></div>", | |
9 | + providers: [provide('profileService', { useClass: ProfileService })] | |
9 | 10 | }) |
10 | -@Inject(ProfileService, "noosfero", "$log", "$stateParams", "$scope", "$state") | |
11 | +@Inject(ProfileService, "$state") | |
11 | 12 | export class ProfileHome { |
12 | 13 | |
13 | 14 | profile: Profile; |
14 | 15 | |
15 | - constructor(ProfileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { | |
16 | - noosfero.currentProfile.then((profile: Profile) => { | |
16 | + constructor(profileService: ProfileService, $state: ng.ui.IStateService) { | |
17 | + profileService.getCurrentProfile().then((profile: Profile) => { | |
17 | 18 | this.profile = profile; |
18 | - return ProfileService.get(this.profile.id).customGET('home_page', { fields: 'path' }); | |
19 | + return profileService.getHomePage(this.profile.id, { fields: 'path' }); | |
19 | 20 | }).then((response: restangular.IResponse) => { |
20 | 21 | if (response.data.article) { |
21 | 22 | $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); | ... | ... |
... | ... | @@ -0,0 +1,47 @@ |
1 | +import {quickCreateComponent} from "../../spec/helpers"; | |
2 | +import {Profile} from "./profile.component"; | |
3 | + | |
4 | +describe("Components", () => { | |
5 | + describe("Profile Component", () => { | |
6 | + | |
7 | + let $rootScope: ng.IRootScopeService; | |
8 | + let $q: ng.IQService; | |
9 | + let profileServiceMock: any; | |
10 | + let $stateParams: any; | |
11 | + | |
12 | + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { | |
13 | + $rootScope = _$rootScope_; | |
14 | + $q = _$q_; | |
15 | + })); | |
16 | + | |
17 | + beforeEach(() => { | |
18 | + $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]); | |
19 | + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getByIdentifier", "getBoxes", "setCurrentProfile"]); | |
20 | + | |
21 | + let getByIdentifierResponse = $q.defer(); | |
22 | + getByIdentifierResponse.resolve({ data: [{ id: 1 }] }); | |
23 | + let getBoxesResponse = $q.defer(); | |
24 | + getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } }); | |
25 | + | |
26 | + profileServiceMock.getByIdentifier = jasmine.createSpy("getByIdentifier").and.returnValue(getByIdentifierResponse.promise); | |
27 | + profileServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise); | |
28 | + }); | |
29 | + | |
30 | + it("get the profile and store in profile service", done => { | |
31 | + let component: Profile = new Profile(profileServiceMock, $stateParams); | |
32 | + $rootScope.$apply(); | |
33 | + expect(profileServiceMock.getByIdentifier).toHaveBeenCalled(); | |
34 | + expect(profileServiceMock.setCurrentProfile).toHaveBeenCalled(); | |
35 | + expect(component.profile).toEqual({ id: 1 }); | |
36 | + done(); | |
37 | + }); | |
38 | + | |
39 | + it("get the profile boxes", done => { | |
40 | + let component: Profile = new Profile(profileServiceMock, $stateParams); | |
41 | + $rootScope.$apply(); | |
42 | + expect(profileServiceMock.getBoxes).toHaveBeenCalled(); | |
43 | + expect(component.boxes).toEqual([{ id: 2 }]); | |
44 | + done(); | |
45 | + }); | |
46 | + }); | |
47 | +}); | ... | ... |
src/app/profile/profile.component.ts
1 | -import {StateConfig, Component, Inject} from 'ng-forward'; | |
1 | +import {StateConfig, Component, Inject, provide} from 'ng-forward'; | |
2 | 2 | import {ProfileInfo} from '../profile-info/profile-info.component'; |
3 | 3 | import {ProfileHome} from '../profile/profile-home.component'; |
4 | 4 | import {Cms} from '../cms/cms.component'; |
... | ... | @@ -12,7 +12,8 @@ import * as noosferoModels from "./../models/interfaces"; |
12 | 12 | @Component({ |
13 | 13 | selector: 'profile', |
14 | 14 | templateUrl: "app/profile/profile.html", |
15 | - directives: [NoosferoActivities] | |
15 | + directives: [NoosferoActivities], | |
16 | + providers: [provide('profileService', { useClass: ProfileService })] | |
16 | 17 | }) |
17 | 18 | @StateConfig([ |
18 | 19 | { |
... | ... | @@ -68,17 +69,17 @@ import * as noosferoModels from "./../models/interfaces"; |
68 | 69 | } |
69 | 70 | } |
70 | 71 | ]) |
71 | -@Inject(ProfileService, "noosfero", "$log", "$stateParams") | |
72 | +@Inject(ProfileService, "$stateParams") | |
72 | 73 | export class Profile { |
73 | 74 | |
74 | 75 | boxes: noosferoModels.Box[]; |
75 | 76 | profile: noosferoModels.Profile; |
76 | 77 | |
77 | - constructor(ProfileService: ProfileService, noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { | |
78 | - ProfileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => { | |
78 | + constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService) { | |
79 | + profileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => { | |
79 | 80 | this.profile = response.data[0]; |
80 | - noosfero.setCurrentProfile(this.profile); | |
81 | - return ProfileService.getBoxes(this.profile.id); | |
81 | + profileService.setCurrentProfile(this.profile); | |
82 | + return profileService.getBoxes(this.profile.id); | |
82 | 83 | }).then((response: restangular.IResponse) => { |
83 | 84 | this.boxes = response.data.boxes; |
84 | 85 | }); | ... | ... |
src/app/profile/profile.controller.spec.js
... | ... | @@ -0,0 +1,76 @@ |
1 | +import {Article} from "../../../app/models/interfaces"; | |
2 | +import {ArticleService} from "./article.service"; | |
3 | + | |
4 | + | |
5 | +describe("Services", () => { | |
6 | + | |
7 | + describe("Article Service", () => { | |
8 | + | |
9 | + let $httpBackend: ng.IHttpBackendService; | |
10 | + let articleService: ArticleService; | |
11 | + | |
12 | + beforeEach(angular.mock.module("noosferoApp")); | |
13 | + | |
14 | + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _ArticleService_: ArticleService) => { | |
15 | + $httpBackend = _$httpBackend_; | |
16 | + articleService = _ArticleService_; | |
17 | + })); | |
18 | + | |
19 | + | |
20 | + describe("Succesfull requests", () => { | |
21 | + | |
22 | + it("should return article children", (done) => { | |
23 | + let articleId = 1; | |
24 | + $httpBackend.expectGET(`/api/v1/articles/${articleId}/children`).respond(200, { articles: [{ name: "article1" }] }); | |
25 | + articleService.getChildren(articleId).then((response: restangular.IResponse) => { | |
26 | + expect(response.data.articles).toEqual([{ name: "article1" }]); | |
27 | + done(); | |
28 | + }); | |
29 | + $httpBackend.flush(); | |
30 | + }); | |
31 | + | |
32 | + it("should get articles by profile", (done) => { | |
33 | + let profileId = 1; | |
34 | + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles`).respond(200, { articles: [{ name: "article1" }] }); | |
35 | + articleService.getByProfile(profileId).then((response: restangular.IResponse) => { | |
36 | + expect(response.data.articles).toEqual([{ name: "article1" }]); | |
37 | + done(); | |
38 | + }); | |
39 | + $httpBackend.flush(); | |
40 | + }); | |
41 | + | |
42 | + it("should get articles by profile with additional filters", (done) => { | |
43 | + let profileId = 1; | |
44 | + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles?path=test`).respond(200, { articles: [{ name: "article1" }] }); | |
45 | + articleService.getByProfile(profileId, { path: 'test' }).then((response: restangular.IResponse) => { | |
46 | + expect(response.data.articles).toEqual([{ name: "article1" }]); | |
47 | + done(); | |
48 | + }); | |
49 | + $httpBackend.flush(); | |
50 | + }); | |
51 | + | |
52 | + it("should get article children with additional filters", (done) => { | |
53 | + let articleId = 1; | |
54 | + $httpBackend.expectGET(`/api/v1/articles/${articleId}/children?path=test`).respond(200, { articles: [{ name: "article1" }] }); | |
55 | + articleService.getChildren(articleId, { path: 'test' }).then((response: restangular.IResponse) => { | |
56 | + expect(response.data.articles).toEqual([{ name: "article1" }]); | |
57 | + done(); | |
58 | + }); | |
59 | + $httpBackend.flush(); | |
60 | + }); | |
61 | + | |
62 | + it("should create an article in a profile", (done) => { | |