Commit f7c01b774aae6ec2fa1e942815f7996e6bcc1e3a
Exists in
master
and in
34 other branches
merge
Showing
8 changed files
with
158 additions
and
40 deletions
Show diff stats
src/app/components/navbar/navbar.spec.ts
1 | 1 | import { |
2 | -createComponentFromClass, | |
3 | -quickCreateComponent, | |
4 | -provideEmptyObjects | |
2 | + createComponentFromClass, | |
3 | + quickCreateComponent, | |
4 | + provideEmptyObjects | |
5 | 5 | } from "./../../../spec/helpers"; |
6 | 6 | import { |
7 | -Navbar | |
7 | + Navbar | |
8 | 8 | } from "./navbar"; |
9 | 9 | import { |
10 | -AUTH_EVENTS | |
10 | + AUTH_EVENTS | |
11 | 11 | } from "./../auth"; |
12 | 12 | import { |
13 | -User | |
13 | + User | |
14 | 14 | } from "./../../models/interfaces"; |
15 | 15 | import { |
16 | -Injectable, | |
17 | -Provider, | |
18 | -provide | |
16 | + Injectable, | |
17 | + Provider, | |
18 | + provide | |
19 | 19 | } from "ng-forward"; |
20 | 20 | |
21 | 21 | |
... | ... | @@ -59,7 +59,6 @@ describe("Components", () => { |
59 | 59 | }) |
60 | 60 | ]; |
61 | 61 | |
62 | - | |
63 | 62 | quickCreateComponent({ |
64 | 63 | providers: providers, |
65 | 64 | template: "<acme-navbar></acme-navbar>", |
... | ... | @@ -72,5 +71,118 @@ describe("Components", () => { |
72 | 71 | }); |
73 | 72 | }); |
74 | 73 | |
74 | + it('It should open on click', (done: Function) => { | |
75 | + | |
76 | + let scope = { | |
77 | + eventCalledHook: () => { }, | |
78 | + $on: (eventName: string, func: Function) => { | |
79 | + console.log("ON Called!"); | |
80 | + this.eventCalledHook = func; | |
81 | + } | |
82 | + } | |
83 | + | |
84 | + let modalInstance = { | |
85 | + close: () => { | |
86 | + console.log("CLOSE Called!"); | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + let $modal = { | |
91 | + open: (args: {}) => { | |
92 | + return modalInstance; | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + let stateService = jasmine.createSpyObj("$state", ["go"]); | |
97 | + let providers = [ | |
98 | + new Provider('moment', { useValue: {} }), | |
99 | + new Provider('$modal', { useValue: $modal }), | |
100 | + new Provider('AuthService', { useValue: {} }), | |
101 | + new Provider('Session', { | |
102 | + useValue: { | |
103 | + currentUser: () => { return user } | |
104 | + } | |
105 | + }), | |
106 | + new Provider('$scope', { useValue: scope }), | |
107 | + new Provider('$state', { useValue: stateService }), | |
108 | + new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | |
109 | + ]; | |
110 | + quickCreateComponent({ | |
111 | + providers: providers, | |
112 | + template: "<acme-navbar></acme-navbar>", | |
113 | + directives: [Navbar] | |
114 | + }) | |
115 | + .then(fixture => { | |
116 | + console.log("entrou no .then") | |
117 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
118 | + spyOn($modal, "open"); | |
119 | + //navbarComp.activate(); | |
120 | + navbarComp.openLogin(); | |
121 | + expect($modal.open).toHaveBeenCalled(); | |
122 | + expect($modal.open).toHaveBeenCalledWith({ | |
123 | + templateUrl: 'app/components/auth/login.html', | |
124 | + controller: 'AuthController', | |
125 | + controllerAs: 'vm', | |
126 | + bindToController: true | |
127 | + }) | |
128 | + done(); | |
129 | + }) | |
130 | + }); | |
131 | + | |
132 | + | |
133 | + // it('closes the modal the login', (done: Function) => { | |
134 | + // let scope = { | |
135 | + // eventCalledHook: () => { }, | |
136 | + // $on: (eventName: string, func: Function) => { | |
137 | + // console.log("ON Called!"); | |
138 | + // this.eventCalledHook = func; | |
139 | + // } | |
140 | + // } | |
141 | + // | |
142 | + // let modalInstance = { | |
143 | + // close: () => { | |
144 | + // console.log("CLOSE Called!"); | |
145 | + // } | |
146 | + // } | |
147 | + // | |
148 | + // let $modal = { | |
149 | + // $open: (args: {}) => { | |
150 | + // return modalInstance; | |
151 | + // } | |
152 | + // } | |
153 | + // | |
154 | + // let stateService = jasmine.createSpyObj("$state", ["go"]); | |
155 | + // let providers = [ | |
156 | + // new Provider('moment', { useValue: {} }), | |
157 | + // new Provider('$modal', { useValue: $modal }), | |
158 | + // new Provider('AuthService', { useValue: {} }), | |
159 | + // new Provider('Session', { | |
160 | + // useValue: { | |
161 | + // currentUser: () => { return user } | |
162 | + // } | |
163 | + // }), | |
164 | + // new Provider('$scope', { useValue: scope }), | |
165 | + // new Provider('$state', { useValue: stateService }), | |
166 | + // new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | |
167 | + // ]; | |
168 | + // spyOn(modalInstance, "close"); | |
169 | + // | |
170 | + // quickCreateComponent({ | |
171 | + // providers: providers, | |
172 | + // template: "<acme-navbar></acme-navbar>", | |
173 | + // directives: [Navbar] | |
174 | + // }) | |
175 | + // .then(fixture => { | |
176 | + // let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
177 | + // navbarComp.activate(); | |
178 | + // navbarComp.openLogin | |
179 | + // | |
180 | + // expect($modal.open).toHaveBeenCalledWith({}) | |
181 | + // scope.eventCalledHook(); | |
182 | + // expect(modalInstance.close).toHaveBeenCalled(); | |
183 | + // done(); | |
184 | + // }) | |
185 | + // //done(); | |
186 | + // }); | |
75 | 187 | }); |
76 | -}); | |
77 | 188 | \ No newline at end of file |
189 | +}); | ... | ... |
src/app/components/navbar/navbar.ts
src/app/components/noosfero/noosfero-template.filter.js
... | ... | @@ -1,13 +0,0 @@ |
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - angular | |
4 | - .module("noosferoApp") | |
5 | - .filter("noosferoTemplate", function() { | |
6 | - return function(text, options) { | |
7 | - for(var option in options) { | |
8 | - text = text.replace('{'+option+'}', options[option]); | |
9 | - } | |
10 | - return text; | |
11 | - } | |
12 | - }) | |
13 | -})(); |
src/app/components/noosfero/noosfero-template.filter.spec.ts
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +import {quickCreateComponent} from "../../../spec/helpers"; | |
2 | +import {NoosferoTemplate} from './noosfero-template.filter'; | |
3 | + | |
4 | +describe("Filters", () => { | |
5 | + describe("Noosfero Template Filter", () => { | |
6 | + | |
7 | + beforeEach(angular.mock.module("templates")); | |
8 | + | |
9 | + it("replace the options in text with the values passed on options", done => { | |
10 | + let text = 'profile: {profile}, other: {other}'; | |
11 | + let htmlTemplate = `{{ '${text}' | noosferoTemplate: {profile: 'profile1', other: 'other value'} }}`; | |
12 | + quickCreateComponent({ providers: [NoosferoTemplate], template: htmlTemplate }).then(fixture => { | |
13 | + expect(fixture.debugElement.text()).toEqual("profile: profile1, other: other value"); | |
14 | + done(); | |
15 | + }); | |
16 | + }); | |
17 | + | |
18 | + }); | |
19 | +}); | ... | ... |
src/app/components/noosfero/noosfero-template.filter.ts
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - angular | |
4 | - .module("noosferoApp") | |
5 | - .filter("noosferoTemplate", function() { | |
6 | - return function(text, options) { | |
7 | - for(var option in options) { | |
8 | - text = text.replace('{'+option+'}', options[option]); | |
1 | +import {Pipe} from "ng-forward"; | |
2 | + | |
3 | +@Pipe("noosferoTemplate") | |
4 | +export class NoosferoTemplate { | |
5 | + | |
6 | + transform(text: string, options: any) { | |
7 | + for (var option in options) { | |
8 | + text = text.replace('{' + option + '}', options[option]); | |
9 | 9 | } |
10 | 10 | return text; |
11 | - } | |
12 | - }) | |
13 | -})(); | |
11 | + } | |
12 | + | |
13 | +} | ... | ... |
src/app/index.ts
... | ... | @@ -42,7 +42,6 @@ NoosferoApp.run(noosferoAngularRunBlock); |
42 | 42 | NoosferoApp.addController("AuthController", AuthController); |
43 | 43 | |
44 | 44 | |
45 | -require("./components/noosfero/noosfero-template.filter.js"); | |
46 | 45 | require("./components/noosfero/noosfero.service.js"); |
47 | 46 | require("./components/noosfero/profile-image/profile-image.component.js"); |
48 | 47 | ... | ... |
src/app/main/main.component.ts
... | ... | @@ -10,7 +10,7 @@ import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.c |
10 | 10 | import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component"; |
11 | 11 | import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image/profile-image.component"; |
12 | 12 | import {MembersBlock} from "../components/noosfero-blocks/members-block/members-block.component"; |
13 | - | |
13 | +import {NoosferoTemplate} from "../components/noosfero/noosfero-template.filter"; | |
14 | 14 | |
15 | 15 | import {AuthService} from "./../components/auth/auth_service"; |
16 | 16 | import {Session} from "./../components/auth/session"; |
... | ... | @@ -35,7 +35,8 @@ export class MainContent { |
35 | 35 | template: '<div ng-view></div>', |
36 | 36 | directives: [ |
37 | 37 | ArticleBlog, ArticleView, Boxes, Block, LinkListBlock, |
38 | - MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, MembersBlock | |
38 | + MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, | |
39 | + MembersBlock, NoosferoTemplate | |
39 | 40 | ], |
40 | 41 | providers: [AuthService, Session] |
41 | 42 | }) | ... | ... |
src/lib/ng-noosfero-api/http/article.service.ts
... | ... | @@ -7,7 +7,7 @@ export class ArticleService { |
7 | 7 | constructor(private Restangular: any) { } |
8 | 8 | |
9 | 9 | getByProfile(profileId: number, filters: any) { |
10 | - return this.Restangular.service('profiles').one(profileId).one('articles').get(filters); | |
10 | + return this.Restangular.one('profiles', profileId).customGET('articles', filters); | |
11 | 11 | } |
12 | 12 | |
13 | 13 | getChildren(id: number, filters: any) { | ... | ... |