From 0b2e89a15fd91ba8723a5a7f0ee986011ee1f19c Mon Sep 17 00:00:00 2001 From: Carlos Purificacao Date: Wed, 9 Mar 2016 08:43:21 -0300 Subject: [PATCH] Moved profile-image to profile-image-block --- src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts | 14 ++++++++++++++ src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html | 6 ++++++ src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss | 5 +++++ src/app/components/noosfero-blocks/profile-image/profile-image.component.spec.ts | 106 ---------------------------------------------------------------------------------------------------------- src/app/components/noosfero-blocks/profile-image/profile-image.component.ts | 27 --------------------------- src/app/components/noosfero-blocks/profile-image/profile-image.html | 6 ------ src/app/components/noosfero-blocks/profile-image/profile-image.scss | 5 ----- src/app/components/noosfero/profile-image/profile-image.component.js | 22 ---------------------- src/app/components/noosfero/profile-image/profile-image.component.spec.ts | 0 src/app/components/noosfero/profile-image/profile-image.component.ts | 36 ++++++++++++++++++------------------ src/app/components/noosfero/profile-image/profile-image.html | 6 +++--- src/app/index.ts | 2 -- src/app/main/main.component.ts | 3 ++- src/app/models/interfaces.ts | 1 + 15 files changed, 131 insertions(+), 190 deletions(-) create mode 100644 src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts create mode 100644 src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts create mode 100644 src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html create mode 100644 src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss delete mode 100644 src/app/components/noosfero-blocks/profile-image/profile-image.component.spec.ts delete mode 100644 src/app/components/noosfero-blocks/profile-image/profile-image.component.ts delete mode 100644 src/app/components/noosfero-blocks/profile-image/profile-image.html delete mode 100644 src/app/components/noosfero-blocks/profile-image/profile-image.scss delete mode 100644 src/app/components/noosfero/profile-image/profile-image.component.js create mode 100644 src/app/components/noosfero/profile-image/profile-image.component.spec.ts diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts new file mode 100644 index 0000000..a3e50ea --- /dev/null +++ b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts @@ -0,0 +1,82 @@ +import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; +import {Pipe, Input, provide, Component} from 'ng-forward'; + +import {ProfileImageBlock} from './profile-image-block.component'; + +import * as helpers from "./../../../../spec/helpers"; + +const tcb = new TestComponentBuilder(); + +const htmlTemplate: string = ''; + +describe("Components", () => { + + describe("Profile Image Block Component", () => { + + beforeEach(angular.mock.module("templates")); + + @Component( + { + selector: 'test-container-component', + template: htmlTemplate, + directives: [ProfileImageBlock] + }) + class BlockContainerComponent { + block = { type: 'Block' }; + owner = { name: 'profile-name' }; + constructor() { + } + } + + + + it("show image if present", () => { + helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { + var elProfile = fixture.debugElement.componentViewChildren[0]; + expect(elProfile.query('div.profile-image-block').length).toEqual(1); + }); + }); + + //TODO + it("not show image if image is missing", () => { + + }); + + it("has link to the profile", () => { + + }); + + it("get activitities from profileService", () => { + + + let profileServiceMock = buildServiceMock(); + + let profileImageBlock = new ProfileImageBlock(profileServiceMock); + + profileImageBlock.ngOnInit(); + expect(profileServiceMock.getActivities).toHaveBeenCalled(); + expect(profileImageBlock.image.name).toEqual("some-thing"); + }); + + // it("render the profile image", done => { + // tcb.createAsync(BlockContainerComponent).then(fixture => { + // expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); + // done(); + // }); + // }); + // + // it("render the settings link", done => { + // tcb.createAsync(BlockContainerComponent).then(fixture => { + // expect(fixture.debugElement.queryAll(".settings-link").length).toEqual(1); + // done(); + // }); + // }); + + it("test dependency", done => { + tcb.createAsync(BlockContainerComponent).then(fixture => { + //let service = mock(Service) + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts new file mode 100644 index 0000000..f33528a --- /dev/null +++ b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts @@ -0,0 +1,14 @@ +import {Inject, Input, Component} from "ng-forward"; +import {ProfileImage} from "./../../../components/noosfero/profile-image/profile-image.component"; + +@Component({ + selector: "noosfero-profile-image-block", + templateUrl: 'app/components/noosfero-blocks/profile-image-block/profile-image-block.html', + directives: [ProfileImage] +}) +export class ProfileImageBlock { + + @Input() block: any; + @Input() owner: any; + +} diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html new file mode 100644 index 0000000..5c20aee --- /dev/null +++ b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html @@ -0,0 +1,6 @@ + diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss new file mode 100644 index 0000000..a609250 --- /dev/null +++ b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss @@ -0,0 +1,5 @@ +.profile-image-block { + .settings-link { + display: block; + } +} diff --git a/src/app/components/noosfero-blocks/profile-image/profile-image.component.spec.ts b/src/app/components/noosfero-blocks/profile-image/profile-image.component.spec.ts deleted file mode 100644 index b20f14a..0000000 --- a/src/app/components/noosfero-blocks/profile-image/profile-image.component.spec.ts +++ /dev/null @@ -1,106 +0,0 @@ -import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; -import {Pipe, Input, provide, Component} from 'ng-forward'; - -import {ProfileImageBlock} from './profile-image.component'; - -import {ProfileService} from "./../../../../lib/ng-noosfero-api/http/profile.service"; - -import * as helpers from "./../../../../spec/helpers"; - -const tcb = new TestComponentBuilder(); - -const htmlTemplate: string = ''; - - - - -describe("Components", () => { - describe("Profile Image Block Component", () => { - - beforeEach(angular.mock.module("templates")); - - //beforeEach(angular.mock.module("restangular")); - - function buildServiceMock() { - let profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getActivities"]); - - let thenObj = jasmine.createSpyObj("thenObj", ["then"]); - - thenObj.then = (func: Function) => { - func({ - data: { - image: { - name: 'some-thing', - url: 'http://image.com' - } - } - }) - } - - profileServiceMock.getActivities = jasmine.createSpy("getActivities").and.returnValue(thenObj); - - return profileServiceMock; - } - - @Component( - { - selector: 'test-container-component', - template: htmlTemplate, - directives: [ProfileImageBlock], - providers: [helpers.createProviderToValue("ProfileService", buildServiceMock())] - - }) - class BlockContainerComponent { - block = { type: 'Block' }; - owner = { name: 'profile-name' }; - constructor() { - } - } - - - - it("show image if present", () => { - let profileServiceMock = buildServiceMock(); - helpers.tcb.createAsync(BlockContainerComponent).then(fixture => { - var elProfile = fixture.debugElement.componentViewChildren[0]; - expect(elProfile.query('div.profile-image-block').length).toEqual(1); - }); - }); - - //TODO - it("not show image if image is missing", () => { - - }); - - it("has link to the profile", () => { - - }); - - it("get activitities from profileService", () => { - - - let profileServiceMock = buildServiceMock(); - - let profileImageBlock = new ProfileImageBlock(profileServiceMock); - - profileImageBlock.ngOnInit(); - expect(profileServiceMock.getActivities).toHaveBeenCalled(); - expect(profileImageBlock.image.name).toEqual("some-thing"); - }) - - // it("render the profile image", done => { - // tcb.createAsync(BlockContainerComponent).then(fixture => { - // expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1); - // done(); - // }); - // }); - // - // it("render the settings link", done => { - // tcb.createAsync(BlockContainerComponent).then(fixture => { - // expect(fixture.debugElement.queryAll(".settings-link").length).toEqual(1); - // done(); - // }); - // }); - - }); -}); \ No newline at end of file diff --git a/src/app/components/noosfero-blocks/profile-image/profile-image.component.ts b/src/app/components/noosfero-blocks/profile-image/profile-image.component.ts deleted file mode 100644 index aa52b41..0000000 --- a/src/app/components/noosfero-blocks/profile-image/profile-image.component.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {Inject, Input, Component} from "ng-forward"; -import {ProfileService} from "./../../../../lib/ng-noosfero-api/http/profile.service"; - -@Component({ - selector: "noosfero-profile-image-block", - templateUrl: 'app/components/noosfero-blocks/profile-image/profile-image.html', - providers: [ProfileService] -}) -@Inject(ProfileService) -export class ProfileImageBlock { - - @Input() block: any; - @Input() owner: any; - - image: any; - - constructor(private profileService: ProfileService) { - - } - - ngOnInit() { - this.profileService.getActivities(null, {}).then((resp:any) => { - this.image = resp.data.image; - }) - } - -} diff --git a/src/app/components/noosfero-blocks/profile-image/profile-image.html b/src/app/components/noosfero-blocks/profile-image/profile-image.html deleted file mode 100644 index b0fbe3c..0000000 --- a/src/app/components/noosfero-blocks/profile-image/profile-image.html +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/src/app/components/noosfero-blocks/profile-image/profile-image.scss b/src/app/components/noosfero-blocks/profile-image/profile-image.scss deleted file mode 100644 index a609250..0000000 --- a/src/app/components/noosfero-blocks/profile-image/profile-image.scss +++ /dev/null @@ -1,5 +0,0 @@ -.profile-image-block { - .settings-link { - display: block; - } -} diff --git a/src/app/components/noosfero/profile-image/profile-image.component.js b/src/app/components/noosfero/profile-image/profile-image.component.js deleted file mode 100644 index c83939f..0000000 --- a/src/app/components/noosfero/profile-image/profile-image.component.js +++ /dev/null @@ -1,22 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('noosferoApp') - .component('noosferoProfileImage', { - restrict: 'E', - templateUrl: 'app/components/noosfero/profile-image/profile-image.html', - bindings: { - profile: '<' - }, - controller: ProfileImageController - }); - - /** @ngInject */ - function ProfileImageController() { - var vm = this; - vm.defaultIcon = 'fa-users'; - if(vm.profile && vm.profile.type==='Person') vm.defaultIcon = 'fa-user'; - } - -})(); diff --git a/src/app/components/noosfero/profile-image/profile-image.component.spec.ts b/src/app/components/noosfero/profile-image/profile-image.component.spec.ts new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/app/components/noosfero/profile-image/profile-image.component.spec.ts diff --git a/src/app/components/noosfero/profile-image/profile-image.component.ts b/src/app/components/noosfero/profile-image/profile-image.component.ts index ac877b6..ff417bc 100644 --- a/src/app/components/noosfero/profile-image/profile-image.component.ts +++ b/src/app/components/noosfero/profile-image/profile-image.component.ts @@ -1,21 +1,21 @@ -(function() { - 'use strict'; +import {Inject, Input, Component} from "ng-forward"; +import {Profile} from "./../../../models/interfaces"; - angular - .module('noosferoApp') - .component('noosferoProfileImage', { - templateUrl: 'app/components/noosfero/profile-image/profile-image.html', - bindings: { - profile: '<' - }, - controller: ProfileImageController - }); +@Component({ + selector: "noosfero-profile-image", + templateUrl: 'app/components/noosfero/profile-image/profile-image.html', +}) +export class ProfileImage { - /** @ngInject */ - function ProfileImageController() { - var vm = this; - vm.defaultIcon = 'fa-users'; - if(vm.profile && vm.profile.type==='Person') vm.defaultIcon = 'fa-user'; - } + @Input() profile: Profile; + defaultIcon: any; + + ngOnInit() { + this.defaultIcon = 'fa-users'; + console.debug("On ProfileImage ngOnInit. Profile: " + this.profile) + if (this.profile && this.profile.type === 'Person') { + this.defaultIcon = 'fa-user'; + } + } +} -})(); diff --git a/src/app/components/noosfero/profile-image/profile-image.html b/src/app/components/noosfero/profile-image/profile-image.html index a166548..b1418b6 100644 --- a/src/app/components/noosfero/profile-image/profile-image.html +++ b/src/app/components/noosfero/profile-image/profile-image.html @@ -1,4 +1,4 @@ - - - + + + diff --git a/src/app/index.ts b/src/app/index.ts index e920bb7..ea8e02c 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -28,6 +28,4 @@ NoosferoApp.addConstants("AUTH_EVENTS", AUTH_EVENTS); NoosferoApp.addConfig(noosferoModuleConfig); NoosferoApp.run(noosferoAngularRunBlock); -require("./components/noosfero/profile-image/profile-image.component.js"); - NoosferoApp.addConfig(routeConfig); diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index abfbe7c..fde107f 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -8,7 +8,8 @@ import {Boxes} from "../components/noosfero-boxes/boxes.component"; import {Block} from "../components/noosfero-blocks/block.component"; import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.component"; import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component"; -import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image/profile-image.component"; +import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image-block/profile-image-block.component"; + import {MembersBlock} from "../components/noosfero-blocks/members-block/members-block.component"; import {NoosferoTemplate} from "../components/noosfero/noosfero-template.filter"; diff --git a/src/app/models/interfaces.ts b/src/app/models/interfaces.ts index 3c5bc5c..02a728f 100644 --- a/src/app/models/interfaces.ts +++ b/src/app/models/interfaces.ts @@ -13,6 +13,7 @@ export interface Article { export interface Profile { id: number; identifier: string; + type: string; } export interface Person extends Profile { -- libgit2 0.21.2