Commit 1fa4fdeaf2a3b6007f6b8730ff877c5e8f339b00

Authored by Ábner Oliveira
1 parent 41a1626d

fixed webpack errors and warnings

Showing 28 changed files with 136 additions and 93 deletions   Show diff stats
dev-scripts/fix-jqlite.ts 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +let replace = require("replace");
  2 +
  3 +import * as path from "path";
  4 +
  5 +let wrong_jqlite_d_ts_file = path.join(__dirname, "../node_modules/ng-forward/cjs/util/jqlite-extensions.d.ts");
  6 +
  7 +replace({
  8 + regex: /import JQuery from \".\/\";/,
  9 + replacement: "",
  10 + paths: [wrong_jqlite_d_ts_file],
  11 + sillent: false
  12 +});
  13 +
@@ -4,20 +4,22 @@ @@ -4,20 +4,22 @@
4 "dependencies": { 4 "dependencies": {
5 "angular": "^1.5.0", 5 "angular": "^1.5.0",
6 "angular-mock": "^1.0.0", 6 "angular-mock": "^1.0.0",
7 - "moment": "^2.11.2" 7 + "moment": "^2.11.2",
  8 + "ng-forward": "0.0.1-alpha.12"
8 }, 9 },
9 "scripts": { 10 "scripts": {
10 "build": "webpack; gulp build", 11 "build": "webpack; gulp build",
11 "webpack": "webpack", 12 "webpack": "webpack",
12 - "karma": "karma", 13 + "karma": "concurrently \"webpack -w\" \"karma start\"",
13 "coverage": "karma start --single-run; npm run remap-coverage", 14 "coverage": "karma start --single-run; npm run remap-coverage",
14 "remap-coverage": "ts-node --project ./dev-scripts ./dev-scripts/remapCoverage.ts", 15 "remap-coverage": "ts-node --project ./dev-scripts ./dev-scripts/remapCoverage.ts",
15 "test-single": "karma start --single-run", 16 "test-single": "karma start --single-run",
16 "test-and-coverage": "karma start & npm run remap-coverage", 17 "test-and-coverage": "karma start & npm run remap-coverage",
17 "test": "webpack -w --test", 18 "test": "webpack -w --test",
18 - "postinstall": "npm install -g bower && bower install && typings install && cd dev-scripts && typings install", 19 + "postinstall": "npm install -g bower; bower install; typings install; npm run fix-jqlite; cd dev-scripts; typings install",
19 "start": "concurrently \"webpack -w\" \"gulp serve\"", 20 "start": "concurrently \"webpack -w\" \"gulp serve\"",
20 - "generate-indexes": "ts-node --project ./dev-scripts ./dev-scripts/generate-index-modules.ts" 21 + "generate-indexes": "ts-node --project ./dev-scripts ./dev-scripts/generate-index-modules.ts",
  22 + "fix-jqlite": "ts-node --project ./dev-scripts dev-scripts/fix-jqlite.ts"
21 }, 23 },
22 "devDependencies": { 24 "devDependencies": {
23 "browser-sync": "~2.9.11", 25 "browser-sync": "~2.9.11",
src/app/components/auth/auth_service.spec.ts
@@ -55,7 +55,7 @@ describe("Services", () => { @@ -55,7 +55,7 @@ describe("Services", () => {
55 let eventEmmited: boolean = false; 55 let eventEmmited: boolean = false;
56 $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: User) => { 56 $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: User) => {
57 eventEmmited = true; 57 eventEmmited = true;
58 - expect(userThroughEvent).toEqual(user) 58 + expect(userThroughEvent).toEqual(user);
59 }); 59 });
60 60
61 $httpBackend.flush(); 61 $httpBackend.flush();
src/app/components/language-selector/language-selector.component.spec.ts
@@ -30,7 +30,7 @@ describe("Components", () => { @@ -30,7 +30,7 @@ describe("Components", () => {
30 }) 30 })
31 ].concat(helpers.provideFilters("translateFilter")) 31 ].concat(helpers.provideFilters("translateFilter"))
32 }); 32 });
33 - } 33 + };
34 34
35 it("set available languages when change language", (done) => { 35 it("set available languages when change language", (done) => {
36 let component: LanguageSelector = new LanguageSelector( 36 let component: LanguageSelector = new LanguageSelector(
src/app/components/language-selector/language-selector.component.ts
@@ -41,7 +41,7 @@ export class LanguageSelector { @@ -41,7 +41,7 @@ export class LanguageSelector {
41 41
42 private changeMomentLocale(language: string) { 42 private changeMomentLocale(language: string) {
43 let localePromise = Promise.resolve(); 43 let localePromise = Promise.resolve();
44 - if (language != "en") { 44 + if (language !== "en") {
45 localePromise = this.angularLoad.loadScript(`/bower_components/moment/locale/${language}.js`); 45 localePromise = this.angularLoad.loadScript(`/bower_components/moment/locale/${language}.js`);
46 } 46 }
47 localePromise.then(() => { 47 localePromise.then(() => {
src/app/components/navbar/navbar.spec.ts
@@ -88,7 +88,7 @@ describe("Components", () => { @@ -88,7 +88,7 @@ describe("Components", () => {
88 directives: [Navbar], 88 directives: [Navbar],
89 template: '<acme-navbar></acme-navbar>' 89 template: '<acme-navbar></acme-navbar>'
90 }); 90 });
91 - } 91 + };
92 92
93 93
94 it('should get the loggedIn user', (done: Function) => { 94 it('should get the loggedIn user', (done: Function) => {
src/app/components/noosfero-articles/blog/blog.component.spec.ts
@@ -73,14 +73,14 @@ describe(&quot;Blog Component&quot;, () =&gt; { @@ -73,14 +73,14 @@ describe(&quot;Blog Component&quot;, () =&gt; {
73 // the templates to the templateCache into the module templates 73 // the templates to the templateCache into the module templates
74 // we need to load the module templates here as the template for the 74 // we need to load the module templates here as the template for the
75 // component Noosfero ArtileView will be load on our tests 75 // component Noosfero ArtileView will be load on our tests
76 - angular.mock.module("templates") 76 + angular.mock.module("templates");
77 77
78 providers((provide: any) => { 78 providers((provide: any) => {
79 return <any>[ 79 return <any>[
80 provide('ArticleService', { 80 provide('ArticleService', {
81 useValue: articleService 81 useValue: articleService
82 }) 82 })
83 - ] 83 + ];
84 }); 84 });
85 }); 85 });
86 86
src/app/components/noosfero-articles/blog/blog.component.ts
@@ -13,7 +13,7 @@ export class ArticleBlog { @@ -13,7 +13,7 @@ export class ArticleBlog {
13 @Input() article: noosfero.Article; 13 @Input() article: noosfero.Article;
14 @Input() profile: Profile; 14 @Input() profile: Profile;
15 15
16 - private posts: any[]; 16 + private posts: noosfero.Article[];
17 private perPage: number = 3; 17 private perPage: number = 3;
18 private currentPage: number; 18 private currentPage: number;
19 private totalPosts: number = 0; 19 private totalPosts: number = 0;
@@ -33,9 +33,9 @@ export class ArticleBlog { @@ -33,9 +33,9 @@ export class ArticleBlog {
33 33
34 this.articleService 34 this.articleService
35 .getChildren(this.article, filters) 35 .getChildren(this.article, filters)
36 - .then((result: noosfero.RestResult<noosfero.Article>) => { 36 + .then((result: noosfero.RestResult<noosfero.Article[]>) => {
37 this.totalPosts = <number>result.headers("total"); 37 this.totalPosts = <number>result.headers("total");
38 - this.posts = <noosfero.Article[]> result.data; 38 + this.posts = result.data;
39 }); 39 });
40 } 40 }
41 41
src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts
@@ -28,7 +28,7 @@ describe(&quot;Components&quot;, () =&gt; { @@ -28,7 +28,7 @@ describe(&quot;Components&quot;, () =&gt; {
28 } 28 }
29 29
30 // uses the TestComponentBuilder instance to initialize the component 30 // uses the TestComponentBuilder instance to initialize the component
31 - //.overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] }) 31 + // .overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] })
32 tcb.createAsync(BlockContainerComponent).then(fixture => { 32 tcb.createAsync(BlockContainerComponent).then(fixture => {
33 // and here we can inspect and run the test assertions 33 // and here we can inspect and run the test assertions
34 let myComponent: LinkListBlock = fixture.componentInstance; 34 let myComponent: LinkListBlock = fixture.componentInstance;
src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts
@@ -28,14 +28,13 @@ describe(&quot;Components&quot;, () =&gt; { @@ -28,14 +28,13 @@ describe(&quot;Components&quot;, () =&gt; {
28 // uses the TestComponentBuilder instance to initialize the component 28 // uses the TestComponentBuilder instance to initialize the component
29 tcb.createAsync(BlockContainerComponent).then(fixture => { 29 tcb.createAsync(BlockContainerComponent).then(fixture => {
30 // and here we can inspect and run the test assertions 30 // and here we can inspect and run the test assertions
31 - //let myComponent: MainBlock = fixture.componentInstance; 31 + // let myComponent: MainBlock = fixture.componentInstance;
32 32
33 // assure the block object inside the Block matches 33 // assure the block object inside the Block matches
34 // the provided through the parent component 34 // the provided through the parent component
35 - expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1) 35 + expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1);
36 done(); 36 done();
37 }); 37 });
38 }); 38 });
39 -  
40 }); 39 });
41 }); 40 });
42 \ No newline at end of file 41 \ No newline at end of file
src/app/components/noosfero-blocks/main-block/main-block.component.ts
1 -import {Component, Input} from 'ng-forward' 1 +import {Component, Input} from 'ng-forward';
2 import {Block} from '../block.component'; 2 import {Block} from '../block.component';
3 3
4 @Component({ 4 @Component({
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts
@@ -30,14 +30,14 @@ describe(&quot;Components&quot;, () =&gt; { @@ -30,14 +30,14 @@ describe(&quot;Components&quot;, () =&gt; {
30 30
31 it("show image if present", () => { 31 it("show image if present", () => {
32 helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { 32 helpers.tcb.createAsync(BlockContainerComponent).then(fixture => {
33 - var elProfile = fixture.debugElement.componentViewChildren[0]; 33 + let elProfile = fixture.debugElement.componentViewChildren[0];
34 expect(elProfile.query('div.profile-image-block').length).toEqual(1); 34 expect(elProfile.query('div.profile-image-block').length).toEqual(1);
35 }); 35 });
36 }); 36 });
37 37
38 it("has link to the profile", () => { 38 it("has link to the profile", () => {
39 helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { 39 helpers.tcb.createAsync(BlockContainerComponent).then(fixture => {
40 - var elProfile = fixture.debugElement.componentViewChildren[0]; 40 + let elProfile = fixture.debugElement.componentViewChildren[0];
41 expect(elProfile.query('a.settings-link').length).toEqual(1); 41 expect(elProfile.query('a.settings-link').length).toEqual(1);
42 }); 42 });
43 }); 43 });
src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts
@@ -10,5 +10,5 @@ export class ProfileImageBlock { @@ -10,5 +10,5 @@ export class ProfileImageBlock {
10 10
11 @Input() block: any; 11 @Input() block: any;
12 @Input() owner: any; 12 @Input() owner: any;
13 - 13 +
14 } 14 }
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
@@ -10,30 +10,42 @@ const tcb = new TestComponentBuilder(); @@ -10,30 +10,42 @@ const tcb = new TestComponentBuilder();
10 describe("Components", () => { 10 describe("Components", () => {
11 describe("Recent Documents Block Component", () => { 11 describe("Recent Documents Block Component", () => {
12 12
  13 + let settingsObj = {};
  14 + let mockedArticleService = {
  15 + getByProfile: (profile: noosfero.Profile, filters: any): any => {
  16 + return Promise.resolve({ data: [{ name: "article1" }], headers: (name: string) => { return name; } });
  17 + }
  18 + };
  19 + let profile = { name: 'profile-name' };
13 beforeEach(angular.mock.module("templates")); 20 beforeEach(angular.mock.module("templates"));
14 21
15 let state = jasmine.createSpyObj("state", ["go"]); 22 let state = jasmine.createSpyObj("state", ["go"]);
16 - let providers = [  
17 - new Provider('$state', { useValue: state }),  
18 - new Provider('ArticleService', {  
19 - useValue: {  
20 - getByProfile: (profileId: number, filters: any): any => {  
21 - return Promise.resolve({ data: [{ name: "article1" }] , headers: (name: string) => {return name;}});  
22 - } 23 +
  24 +
  25 + function getProviders() {
  26 + return [
  27 + new Provider('$state', { useValue: state }),
  28 + new Provider('ArticleService', {
  29 + useValue: mockedArticleService
  30 + }),
  31 + ].concat(provideFilters("truncateFilter", "stripTagsFilter"));
  32 + }
  33 + let componentClass: any = null;
  34 +
  35 + function getComponent() {
  36 + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlock], providers: getProviders() })
  37 + class BlockContainerComponent {
  38 + block = { type: 'Block', settings: settingsObj };
  39 + owner = profile;
  40 + constructor() {
23 } 41 }
24 - }),  
25 - ].concat(provideFilters("truncateFilter", "stripTagsFilter"));  
26 -  
27 - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlock], providers: providers })  
28 - class BlockContainerComponent {  
29 - block = { type: 'Block', settings: {} };  
30 - owner = { name: 'profile-name' };  
31 - constructor() {  
32 } 42 }
  43 + return BlockContainerComponent;
33 } 44 }
34 45
  46 +
35 it("get recent documents from the article service", done => { 47 it("get recent documents from the article service", done => {
36 - tcb.createAsync(BlockContainerComponent).then(fixture => { 48 + tcb.createAsync(getComponent()).then(fixture => {
37 let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance; 49 let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
38 expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]); 50 expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]);
39 done(); 51 done();
@@ -41,7 +53,7 @@ describe(&quot;Components&quot;, () =&gt; { @@ -41,7 +53,7 @@ describe(&quot;Components&quot;, () =&gt; {
41 }); 53 });
42 54
43 it("go to article page when open a document", done => { 55 it("go to article page when open a document", done => {
44 - tcb.createAsync(BlockContainerComponent).then(fixture => { 56 + tcb.createAsync(getComponent()).then(fixture => {
45 let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance; 57 let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
46 recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } }); 58 recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
47 expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" }); 59 expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" });
@@ -49,5 +61,20 @@ describe(&quot;Components&quot;, () =&gt; { @@ -49,5 +61,20 @@ describe(&quot;Components&quot;, () =&gt; {
49 }); 61 });
50 }); 62 });
51 63
  64 + it("it uses default limit 5 if not defined on block", done => {
  65 + settingsObj = null;
  66 + mockedArticleService = jasmine.createSpyObj("mockedArticleService", ["getByProfile"]);
  67 + (<any>mockedArticleService).mocked = true;
  68 + let thenMocked = jasmine.createSpy("then");
  69 + mockedArticleService.getByProfile = jasmine.createSpy("getByProfile").and.returnValue({then: thenMocked});
  70 + let getByProfileFunct = mockedArticleService.getByProfile;
  71 + tcb.createAsync(getComponent()).then(fixture => {
  72 + let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
  73 + recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
  74 + expect(getByProfileFunct).toHaveBeenCalledWith(profile, { content_type: 'TinyMceArticle', per_page: 5 });
  75 + done();
  76 + });
  77 + });
  78 +
52 }); 79 });
53 }); 80 });
54 \ No newline at end of file 81 \ No newline at end of file
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
@@ -23,12 +23,12 @@ export class RecentDocumentsBlock { @@ -23,12 +23,12 @@ export class RecentDocumentsBlock {
23 this.profile = this.owner; 23 this.profile = this.owner;
24 this.documents = []; 24 this.documents = [];
25 25
26 - let limit = (this.block && this.block.settings) ? this.block.settings.limit : null || 5; 26 + let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5;
27 // FIXME get all text articles 27 // FIXME get all text articles
28 // FIXME make the getByProfile a generic method where we tell the type passing a class TinyMceArticle 28 // FIXME make the getByProfile a generic method where we tell the type passing a class TinyMceArticle
29 // and the promise should be of type TinyMceArticle[], per example 29 // and the promise should be of type TinyMceArticle[], per example
30 this.articleService.getByProfile(this.profile, { content_type: 'TinyMceArticle', per_page: limit }) 30 this.articleService.getByProfile(this.profile, { content_type: 'TinyMceArticle', per_page: limit })
31 - .then((result: noosfero.RestResult<noosfero.Article>) => { 31 + .then((result: noosfero.RestResult<noosfero.Article[]>) => {
32 this.documents = <noosfero.Article[]>result.data; 32 this.documents = <noosfero.Article[]>result.data;
33 this.documentsLoaded = true; 33 this.documentsLoaded = true;
34 }); 34 });
src/app/components/noosfero-boxes/boxes.component.spec.ts
@@ -19,8 +19,8 @@ const htmlTemplate: string = &#39;&lt;noosfero-boxes [boxes]=&quot;ctrl.boxes&quot; [owner]=&quot;ctrl @@ -19,8 +19,8 @@ const htmlTemplate: string = &#39;&lt;noosfero-boxes [boxes]=&quot;ctrl.boxes&quot; [owner]=&quot;ctrl
19 describe("Boxes Component", () => { 19 describe("Boxes Component", () => {
20 20
21 beforeEach(() => { 21 beforeEach(() => {
22 - angular.mock.module("templates")  
23 - }) 22 + angular.mock.module("templates");
  23 + });
24 24
25 @Component({ 25 @Component({
26 selector: 'test-container-component', 26 selector: 'test-container-component',
@@ -43,8 +43,7 @@ describe(&quot;Boxes Component&quot;, () =&gt; { @@ -43,8 +43,7 @@ describe(&quot;Boxes Component&quot;, () =&gt; {
43 43
44 it("renders boxes into a container", (done: Function) => { 44 it("renders boxes into a container", (done: Function) => {
45 createComponentFromClass(BoxesContainerComponent).then((fixture) => { 45 createComponentFromClass(BoxesContainerComponent).then((fixture) => {
46 -  
47 - var boxesHtml = fixture.debugElement; 46 + let boxesHtml = fixture.debugElement;
48 expect(boxesHtml.query('div.col-md-7').length).toEqual(1); 47 expect(boxesHtml.query('div.col-md-7').length).toEqual(1);
49 expect(boxesHtml.query('div.col-md-2-5').length).toEqual(1); 48 expect(boxesHtml.query('div.col-md-2-5').length).toEqual(1);
50 49
src/app/components/noosfero/noosfero-template.filter.ts
@@ -4,7 +4,7 @@ import {Pipe} from &quot;ng-forward&quot;; @@ -4,7 +4,7 @@ import {Pipe} from &quot;ng-forward&quot;;
4 export class NoosferoTemplate { 4 export class NoosferoTemplate {
5 5
6 transform(text: string, options: any) { 6 transform(text: string, options: any) {
7 - for (var option in options) { 7 + for (let option in options) {
8 text = text.replace('{' + option + '}', options[option]); 8 text = text.replace('{' + option + '}', options[option]);
9 } 9 }
10 return text; 10 return text;
src/app/components/noosfero/profile-image/profile-image.component.spec.ts
@@ -4,42 +4,42 @@ import {Pipe, Input, provide, Component} from &#39;ng-forward&#39;; @@ -4,42 +4,42 @@ import {Pipe, Input, provide, Component} from &#39;ng-forward&#39;;
4 4
5 import * as helpers from "./../../../../spec/helpers"; 5 import * as helpers from "./../../../../spec/helpers";
6 6
7 -import {ProfileImage} from "./profile-image.component" 7 +import {ProfileImage} from "./profile-image.component";
8 8
9 const tcb = new TestComponentBuilder(); 9 const tcb = new TestComponentBuilder();
10 10
11 describe("Components", () => { 11 describe("Components", () => {
12 - 12 +
13 describe("Profile Image Component", () => { 13 describe("Profile Image Component", () => {
14 14
15 beforeEach(angular.mock.module("templates")); 15 beforeEach(angular.mock.module("templates"));
16 - 16 +
17 it("show community users image if profile is not Person", done => { 17 it("show community users image if profile is not Person", done => {
18 helpers.tcb.createAsync(ProfileImage).then(fixture => { 18 helpers.tcb.createAsync(ProfileImage).then(fixture => {
19 - let profileImageComponent : ProfileImage = fixture.componentInstance  
20 - let profile = { id: 1, identifier: "myprofile", type: "Community" }  
21 - profileImageComponent.profile = profile 19 + let profileImageComponent: ProfileImage = fixture.componentInstance;
  20 + let profile = { id: 1, identifier: "myprofile", type: "Community" };
  21 + profileImageComponent.profile = profile;
22 profileImageComponent.ngOnInit(); 22 profileImageComponent.ngOnInit();
23 23
24 // Check the attribute 24 // Check the attribute
25 expect(profileImageComponent.defaultIcon).toBe("fa-users", "The default icon should be community users"); 25 expect(profileImageComponent.defaultIcon).toBe("fa-users", "The default icon should be community users");
26 - //var elProfile = fixture.debugElement.componentViewChildren[0];  
27 - //expect(elProfile.query('div.profile-image-block').length).toEqual(1); 26 + // var elProfile = fixture.debugElement.componentViewChildren[0];
  27 + // expect(elProfile.query('div.profile-image-block').length).toEqual(1);
28 done(); 28 done();
29 }); 29 });
30 }); 30 });
31 - 31 +
32 it("show Person image if profile is Person", done => { 32 it("show Person image if profile is Person", done => {
33 tcb.createAsync(ProfileImage).then(fixture => { 33 tcb.createAsync(ProfileImage).then(fixture => {
34 - let profileImageComponent : ProfileImage = fixture.componentInstance  
35 - let profile = { id: 1, identifier: "myprofile", type: "Person" }  
36 - profileImageComponent.profile = profile 34 + let profileImageComponent: ProfileImage = fixture.componentInstance;
  35 + let profile = { id: 1, identifier: "myprofile", type: "Person" };
  36 + profileImageComponent.profile = profile;
37 profileImageComponent.ngOnInit(); 37 profileImageComponent.ngOnInit();
38 // Check the attribute 38 // Check the attribute
39 expect(profileImageComponent.defaultIcon).toEqual("fa-user", "The default icon should be person user"); 39 expect(profileImageComponent.defaultIcon).toEqual("fa-user", "The default icon should be person user");
40 done(); 40 done();
41 }); 41 });
42 }); 42 });
43 - 43 +
44 }); 44 });
45 }); 45 });
46 \ No newline at end of file 46 \ No newline at end of file
src/app/components/noosfero/profile-image/profile-image.component.ts
@@ -9,7 +9,7 @@ export class ProfileImage { @@ -9,7 +9,7 @@ export class ProfileImage {
9 9
10 @Input() profile: Profile; 10 @Input() profile: Profile;
11 defaultIcon: string; 11 defaultIcon: string;
12 - 12 +
13 ngOnInit() { 13 ngOnInit() {
14 this.defaultIcon = 'fa-users'; 14 this.defaultIcon = 'fa-users';
15 if (this.profile && this.profile.type === 'Person') { 15 if (this.profile && this.profile.type === 'Person') {
src/app/content-viewer/content-viewer.component.spec.ts
@@ -14,7 +14,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; { @@ -14,7 +14,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; {
14 14
15 let stateParamsService: any; 15 let stateParamsService: any;
16 16
17 - //loading the templates 17 + // loading the templates
18 beforeEach(() => { 18 beforeEach(() => {
19 angular.mock.module("templates"); 19 angular.mock.module("templates");
20 20
@@ -32,7 +32,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; { @@ -32,7 +32,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; {
32 provide('$stateParams', { 32 provide('$stateParams', {
33 useValue: stateParamsService 33 useValue: stateParamsService
34 }) 34 })
35 - ] 35 + ];
36 }); 36 });
37 }); 37 });
38 38
@@ -51,7 +51,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; { @@ -51,7 +51,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; {
51 expect(fixture.debugElement.query('content-viewer').length).toEqual(1); 51 expect(fixture.debugElement.query('content-viewer').length).toEqual(1);
52 52
53 done(); 53 done();
54 - }) 54 + });
55 }); 55 });
56 56
57 it('check if article was loaded', (done: Function) => { 57 it('check if article was loaded', (done: Function) => {
@@ -69,7 +69,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; { @@ -69,7 +69,7 @@ describe(&#39;Content Viewer Component&#39;, () =&gt; {
69 return helpers.mocks.promiseResultTemplate(profile); 69 return helpers.mocks.promiseResultTemplate(profile);
70 }; 70 };
71 71
72 - helpers.mocks.articleService.getByProfile = (id: number, params: any) => { 72 + helpers.mocks.articleService.getOneByProfile = (id: number, params: any) => {
73 return helpers.mocks.promiseResultTemplate({ 73 return helpers.mocks.promiseResultTemplate({
74 data: article 74 data: article
75 }); 75 });
src/app/content-viewer/content-viewer.component.ts
@@ -30,7 +30,7 @@ export class ContentViewer { @@ -30,7 +30,7 @@ export class ContentViewer {
30 activate() { 30 activate() {
31 this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { 31 this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
32 this.profile = profile; 32 this.profile = profile;
33 - return this.articleService.getByProfile(<any>this.profile, { path: this.$stateParams["page"] }); 33 + return this.articleService.getOneByProfile(<any>this.profile, { path: this.$stateParams["page"] });
34 }).then((result: noosfero.RestResult<noosfero.Article>) => { 34 }).then((result: noosfero.RestResult<noosfero.Article>) => {
35 this.article = <noosfero.Article>result.data; 35 this.article = <noosfero.Article>result.data;
36 }); 36 });
src/lib/ng-noosfero-api/http/article.service.ts
@@ -36,12 +36,17 @@ export class ArticleService extends RestangularService&lt;noosfero.Article&gt; { @@ -36,12 +36,17 @@ export class ArticleService extends RestangularService&lt;noosfero.Article&gt; {
36 return rootElement.one(path, id).get<C>(queryParams, headers); 36 return rootElement.one(path, id).get<C>(queryParams, headers);
37 } 37 }
38 38
39 - getByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { 39 + getByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article[]>> {
40 let profileElement = this.profileService.get(<number>profile.id); 40 let profileElement = this.profileService.get(<number>profile.id);
41 return this.list(profileElement, params); 41 return this.list(profileElement, params);
42 } 42 }
43 43
44 - getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { 44 + getOneByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> {
  45 + let profileElement = this.profileService.get(<number>profile.id);
  46 + return this.get(profile.id, params);
  47 + }
  48 +
  49 + getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article[]>> {
45 return this.listSubElements(article, "children", params); 50 return this.listSubElements(article, "children", params);
46 } 51 }
47 52
src/lib/ng-noosfero-api/http/restangular_service.spec.ts
@@ -19,7 +19,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; { @@ -19,7 +19,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; {
19 return { 19 return {
20 singular: "object", 20 singular: "object",
21 plural: "objects" 21 plural: "objects"
22 - } 22 + };
23 } 23 }
24 24
25 public getResourcePath() { 25 public getResourcePath() {
@@ -32,7 +32,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; { @@ -32,7 +32,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; {
32 return { 32 return {
33 singular: "rootObject", 33 singular: "rootObject",
34 plural: "rootObjects" 34 plural: "rootObjects"
35 - } 35 + };
36 } 36 }
37 37
38 public getResourcePath() { 38 public getResourcePath() {
@@ -59,7 +59,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; { @@ -59,7 +59,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; {
59 it("list() calls GET /objects", (done) => { 59 it("list() calls GET /objects", (done) => {
60 $httpBackend.expectGET("/api/v1/objects").respond(200, { objects: [{ id: 1 }, { id: 2 }] }); 60 $httpBackend.expectGET("/api/v1/objects").respond(200, { objects: [{ id: 1 }, { id: 2 }] });
61 61
62 - objectRestService.list().then((result: noosfero.RestResult<ObjectModel>) => { 62 + objectRestService.list().then((result: noosfero.RestResult<ObjectModel[]>) => {
63 expect(result.data).toBeDefined(); 63 expect(result.data).toBeDefined();
64 expect((<ObjectModel[]>result.data).length).toEqual(2); 64 expect((<ObjectModel[]>result.data).length).toEqual(2);
65 done(); 65 done();
@@ -75,7 +75,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; { @@ -75,7 +75,7 @@ describe(&quot;Restangular Service - base Class&quot;, () =&gt; {
75 $httpBackend.expectGET("/api/v1/rootObjects/1/objects").respond(200, { objects: [{ id: 1 }, { id: 2 }] }); 75 $httpBackend.expectGET("/api/v1/rootObjects/1/objects").respond(200, { objects: [{ id: 1 }, { id: 2 }] });
76 let rootObj: RootObjectModel = rootObjectRestService.getElement(1); 76 let rootObj: RootObjectModel = rootObjectRestService.getElement(1);
77 77
78 - objectRestService.list(rootObj).then((result: noosfero.RestResult<ObjectModel>) => { 78 + objectRestService.list(rootObj).then((result: noosfero.RestResult<ObjectModel[]>) => {
79 expect(result.data).toBeDefined(); 79 expect(result.data).toBeDefined();
80 expect((<ObjectModel[]>result.data).length).toEqual(2); 80 expect((<ObjectModel[]>result.data).length).toEqual(2);
81 done(); 81 done();
src/lib/ng-noosfero-api/http/restangular_service.ts
@@ -104,8 +104,8 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; { @@ -104,8 +104,8 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; {
104 * @param {number} id (description) 104 * @param {number} id (description)
105 * @returns {ng.IPromise<T>} Returns a Promise to the Generic Type 105 * @returns {ng.IPromise<T>} Returns a Promise to the Generic Type
106 */ 106 */
107 - public list(rootElement?: restangular.IElement, queryParams?: any, headers?: any): ng.IPromise<noosfero.RestResult<T>> {  
108 - let deferred = this.$q.defer<noosfero.RestResult<T>>(); 107 + public list(rootElement?: restangular.IElement, queryParams?: any, headers?: any): ng.IPromise<noosfero.RestResult<T[]>> {
  108 + let deferred = this.$q.defer<noosfero.RestResult<T[]>>();
109 109
110 let restRequest: ng.IPromise<any>; 110 let restRequest: ng.IPromise<any>;
111 111
@@ -133,7 +133,7 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; { @@ -133,7 +133,7 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; {
133 restRequest = obj.all(subElement).get(queryParams, headers); 133 restRequest = obj.all(subElement).get(queryParams, headers);
134 restRequest.then(this.getHandleSuccessFunction(deferred)) 134 restRequest.then(this.getHandleSuccessFunction(deferred))
135 .catch(this.getHandleErrorFunction(deferred)); 135 .catch(this.getHandleErrorFunction(deferred));
136 - return deferred.promise;; 136 + return deferred.promise;
137 } 137 }
138 138
139 /** 139 /**
@@ -146,9 +146,9 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; { @@ -146,9 +146,9 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; {
146 146
147 147
148 if (rootElement) { 148 if (rootElement) {
149 - restangularObj = rootElement.one(this.getResourcePath(), <string>obj.id); 149 + restangularObj = rootElement.one(this.getResourcePath(), obj.id);
150 } else { 150 } else {
151 - restangularObj = this.restangularService.one(this.getResourcePath(), <string>obj.id); 151 + restangularObj = this.restangularService.one(this.getResourcePath(), obj.id);
152 } 152 }
153 153
154 let deferred = this.$q.defer<noosfero.RestResult<T>>(); 154 let deferred = this.$q.defer<noosfero.RestResult<T>>();
@@ -176,9 +176,9 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; { @@ -176,9 +176,9 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; {
176 let restangularObj: restangular.IElement; 176 let restangularObj: restangular.IElement;
177 177
178 if (rootElement) { 178 if (rootElement) {
179 - restangularObj = rootElement.one(this.getResourcePath(), <string>obj.id); 179 + restangularObj = rootElement.one(this.getResourcePath(), obj.id);
180 } else { 180 } else {
181 - restangularObj = this.restangularService.one(this.getResourcePath(), <string>obj.id); 181 + restangularObj = this.restangularService.one(this.getResourcePath(), obj.id);
182 } 182 }
183 183
184 restRequest = restangularObj.put(queryParams, headers); 184 restRequest = restangularObj.put(queryParams, headers);
@@ -235,7 +235,6 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; { @@ -235,7 +235,6 @@ export abstract class RestangularService&lt;T extends noosfero.RestModel&gt; {
235 self.$log.debug("Request successfull executed", response.data, self, response); 235 self.$log.debug("Request successfull executed", response.data, self, response);
236 } 236 }
237 deferred.resolve(<any>this.extractData(response)); 237 deferred.resolve(<any>this.extractData(response));
238 - //deferred.resolve(this.buildResult(response));  
239 }; 238 };
240 return successFunction; 239 return successFunction;
241 } 240 }
src/lib/ng-noosfero-api/interfaces/articles_result.ts
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
1 -  
2 -namespace noosfero {  
3 - export interface ArticlesResult {  
4 - articles: Article[];  
5 - headers: Function;  
6 - }  
7 -  
8 - export interface ArticleResult {  
9 - article: Article;  
10 - headers: Function;  
11 - }  
12 -}  
13 \ No newline at end of file 0 \ No newline at end of file
src/lib/ng-noosfero-api/interfaces/rest_model.ts
1 namespace noosfero { 1 namespace noosfero {
2 export interface RestModel extends restangular.IElement { 2 export interface RestModel extends restangular.IElement {
3 - id: number | string; 3 + id: number;
4 } 4 }
5 } 5 }
6 \ No newline at end of file 6 \ No newline at end of file
src/lib/ng-noosfero-api/interfaces/rest_result.ts
1 1
2 namespace noosfero { 2 namespace noosfero {
3 export interface RestResult<T> { 3 export interface RestResult<T> {
4 - data: T | T[]; 4 + data: T;
5 headers: Function; 5 headers: Function;
6 } 6 }
7 } 7 }
8 \ No newline at end of file 8 \ No newline at end of file
src/spec/mocks.ts
@@ -50,6 +50,17 @@ export var mocks = { @@ -50,6 +50,17 @@ export var mocks = {
50 } 50 }
51 }; 51 };
52 }, 52 },
  53 + getOneByProfile: (profileId: number, params?: any) => {
  54 + return {
  55 + then: (func?: Function) => {
  56 + if (func) func({
  57 + data: {
  58 + article: null
  59 + }
  60 + });
  61 + }
  62 + };
  63 + },
53 getChildren: (articleId: number, params?: any) => { 64 getChildren: (articleId: number, params?: any) => {
54 return { 65 return {
55 then: (func?: Function) => { if (func) func(); } 66 then: (func?: Function) => { if (func) func(); }
@@ -73,7 +84,7 @@ export var mocks = { @@ -73,7 +84,7 @@ export var mocks = {
73 use: (lang?: string) => { 84 use: (lang?: string) => {
74 return lang ? Promise.resolve(lang) : "en"; 85 return lang ? Promise.resolve(lang) : "en";
75 }, 86 },
76 - instant: (text: string) => { return text } 87 + instant: (text: string) => { return text; }
77 }, 88 },
78 tmhDynamicLocale: { 89 tmhDynamicLocale: {
79 get: () => { }, 90 get: () => { },