From 90332daa64d6b8a1c059fc566fa28090abbbd45e Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Wed, 12 Oct 2016 17:12:00 +0100 Subject: [PATCH 1/4] Improved test readibility and code --- .../ng2-alfresco-userinfo/karma.conf.js | 2 + .../fake-bpm-user.service.ts | 2 +- .../src/assets/fake-ecm-user.service.ts | 107 +++++++++ .../src/components/user-info.component.css | 2 + .../src/components/user-info.component.html | 6 +- .../components/user-info.component.spec.ts | 12 +- .../src/components/user-info.component.ts | 41 ++-- .../src/services/bpm-user.service.spec.ts | 174 ++++++--------- .../src/services/bpm-user.service.ts | 25 +-- .../src/services/ecm-user.service.spec.ts | 205 ++++++------------ .../src/services/ecm-user.service.ts | 6 +- .../src/testing/fake-ecm-user.service.ts | 107 --------- 12 files changed, 289 insertions(+), 400 deletions(-) rename ng2-components/ng2-alfresco-userinfo/src/{testing => assets}/fake-bpm-user.service.ts (97%) create mode 100644 ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.ts delete mode 100644 ng2-components/ng2-alfresco-userinfo/src/testing/fake-ecm-user.service.ts diff --git a/ng2-components/ng2-alfresco-userinfo/karma.conf.js b/ng2-components/ng2-alfresco-userinfo/karma.conf.js index 8f3adc54b4..4dfc103d4d 100644 --- a/ng2-components/ng2-alfresco-userinfo/karma.conf.js +++ b/ng2-components/ng2-alfresco-userinfo/karma.conf.js @@ -49,6 +49,8 @@ module.exports = function (config) { // paths to support debugging with source maps in dev tools {pattern: 'src/**/*.ts', included: false, watched: false}, {pattern: 'dist/**/*.js.map', included: false, watched: false} + // fake file path + { pattern: '/base/dist/src/img/anonymous.gif', included: false, watched: true, served: true } ], exclude: [ diff --git a/ng2-components/ng2-alfresco-userinfo/src/testing/fake-bpm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.ts similarity index 97% rename from ng2-components/ng2-alfresco-userinfo/src/testing/fake-bpm-user.service.ts rename to ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.ts index c8eaeb2ab1..ffddf85e68 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/testing/fake-bpm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.ts @@ -83,7 +83,7 @@ export class FakeBpmUserService { }; getCurrentUserProfileImage() { - return this.usersList[this.userNeeded].pictureId; + return Observable.of(this.usersList[this.userNeeded].pictureId); }; respondWithTheUserWithoutImage() { diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.ts new file mode 100644 index 0000000000..9024896f7b --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.ts @@ -0,0 +1,107 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// re-export for tester convenience +export { EcmUserModel } from '../models/ecm-user.model'; +export { EcmUserService } from '../services/ecm-user.service'; + +import { EcmUserModel } from '../models/ecm-user.model'; +import { EcmCompanyModel } from '../models/ecm-company.model'; +import { Observable } from 'rxjs/Rx'; + +export var fakeEcmCompany: EcmCompanyModel = { + organization: 'company-fake-name', + address1: 'fake-address-1', + address2: 'fake-address-2', + address3: 'fake-address-3', + postcode: 'fAk1', + telephone: '00000000', + fax: '11111111', + email: 'fakeCompany@fake.com' +}; + +export var fakeEcmUserNoImage: EcmUserModel = { + id: 'fake-id', + firstName: 'fake-first-name', + lastName: 'fake-last-name', + description: 'i am a fake user for test', + avatarId: undefined, + email: 'fakeEcm@ecmUser.com', + skypeId: 'fake-skype-id', + googleId: 'fake-googleId-id', + instantMessageId: 'fake-instantMessageId-id', + company: fakeEcmCompany, + jobTitle: 'test job', + location: 'fake location', + mobile: '000000000', + telephone: '11111111', + statusUpdatedAt: 'fake-date', + userStatus: 'active', + enabled: true, + emailNotificationsEnabled: true +}; + +export var fakeEcmUser: EcmUserModel = { + id: 'fake-id', + firstName: 'fake-first-name', + lastName: 'fake-last-name', + description: 'i am a fake user for test', + avatarId: 'fake-avatar-id', + email: 'fakeEcm@ecmUser.com', + skypeId: 'fake-skype-id', + googleId: 'fake-googleId-id', + instantMessageId: 'fake-instantMessageId-id', + company: fakeEcmCompany, + jobTitle: 'test job', + location: 'fake location', + mobile: '000000000', + telephone: '11111111', + statusUpdatedAt: 'fake-date', + userStatus: 'active', + enabled: true, + emailNotificationsEnabled: true +}; + +export class FakeEcmUserService { + + lastPromise: Observable; + public userNeeded = 0; + usersList = [fakeEcmUser, fakeEcmUserNoImage]; + + getUserInfo(userName: string) { + return this.lastPromise = Observable.of(this.usersList[this.userNeeded]); + }; + + getCurrentUserInfo() { + return this.getUserInfo('fake-id'); + }; + + getUserProfileImage(avatarId: string) { + if (avatarId) { + return 'fake/url/image/for/ecm/user'; + } + }; + + respondWithTheUserWithoutImage() { + this.userNeeded = 1; + }; + + respondWithTheUserWithImage() { + this.userNeeded = 0; + }; + +} diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.css b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.css index 93254d00fa..ddda950182 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.css +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.css @@ -2,6 +2,7 @@ text-align: center; border-radius: 90%; width: 40px; + height: 40px; margin-right: 0%; cursor: pointer; border: 1px solid #999999; @@ -16,6 +17,7 @@ .detail-user-profile-list-mdl{ margin-right: 10px; + padding: 0px 0; } .user-profile-list-mdl{ diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html index 5a8b50db9c..04b7db4e95 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html @@ -22,7 +22,7 @@ {{ecmUser.firstName}} {{ecmUser.lastName}} @@ -33,8 +33,8 @@ {{ ecmUser.jobTitle ? ecmUser.jobTitle : 'N/A' }} +
-

BPM @@ -42,7 +42,7 @@ diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts index 70ef809084..bb86e401f0 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts @@ -18,8 +18,8 @@ import { UserInfoComponent } from './user-info.component'; import { EcmUserService } from '../services/ecm-user.service'; import { BpmUserService } from '../services/bpm-user.service'; -import { FakeEcmUserService } from '../testing/fake-ecm-user.service'; -import { FakeBpmUserService } from '../testing/fake-bpm-user.service'; +import { FakeEcmUserService } from '../assets/fake-ecm-user.service'; +import { FakeBpmUserService } from '../assets/fake-bpm-user.service'; import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core'; import { ComponentFixture, TestBed, async } from '@angular/core/testing'; @@ -107,7 +107,7 @@ describe('User info component', () => { fixture.whenStable() .then( () => { fixture.detectChanges(); - let res = userInfoComp.getEcmUserDetailAvatarUrl(); + let res = userInfoComp.getEcmUserAvatar(); expect(userInfoComp.ecmUserImage).toBeUndefined(); expect(res).toEqual(userInfoComp.anonymouseImageUrl); }); @@ -146,7 +146,7 @@ describe('User info component', () => { fixture.whenStable() .then( () => { fixture.detectChanges(); - let res = userInfoComp.getBpmUserDetailAvatarUrl(); + let res = userInfoComp.getBpmUserAvatar(); expect(userInfoComp.bpmUserImage).toBeUndefined(); expect(res).toEqual(userInfoComp.anonymouseImageUrl); }); @@ -194,10 +194,10 @@ describe('User info component', () => { fixture.whenStable() .then( () => { fixture.detectChanges(); - let resBpm = userInfoComp.getBpmUserDetailAvatarUrl(); + let resBpm = userInfoComp.getBpmUserAvatar(); expect(userInfoComp.bpmUserImage).toBeUndefined(); expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl); - let resEcm = userInfoComp.getEcmUserDetailAvatarUrl(); + let resEcm = userInfoComp.getEcmUserAvatar(); expect(userInfoComp.ecmUserImage).toBeUndefined(); expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl); }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts index 4f8ce3aa3c..063dd42517 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts @@ -45,43 +45,46 @@ export class UserInfoComponent implements OnInit { } ngOnInit() { - if ( this.authService.isEcmLoggedIn() ) { + + if (this.authService.isEcmLoggedIn()) { this.ecmUserService.getCurrentUserInfo() .subscribe( (res) => { - this.ecmUser = res; - this.getEcmUserProfileImage(); - } - ); + this.ecmUser = res; + this.getEcmAvatar(); + } + ); } - if ( this.authService.isBpmLoggedIn() ) { + + if (this.authService.isBpmLoggedIn()) { this.bpmUserService.getCurrentUserInfo() .subscribe( (res) => { - this.bpmUser = res; - this.getBpmUserProfileImage(); - } - ); + this.bpmUser = res; + } + ); + this.bpmUserService.getCurrentUserProfileImage() + .subscribe( + (res) => { + this.bpmUserImage = res; + } + ); } } - private getBpmUserProfileImage() { - this.bpmUserImage = this.bpmUserService.getCurrentUserProfileImage(); - } - - private getEcmUserProfileImage() { - this.ecmUserImage = this.ecmUserService.getCurrentUserProfileImageUrl(this.ecmUser.avatarId); + private getEcmAvatar() { + this.ecmUserImage = this.ecmUserService.getUserProfileImage(this.ecmUser.avatarId); } public getUserAvatar() { - return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl; + return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl; } - public getBpmUserDetailAvatarUrl() { + public getBpmUserAvatar() { return this.bpmUserImage || this.anonymouseImageUrl; } - public getEcmUserDetailAvatarUrl() { + public getEcmUserAvatar() { return this.ecmUserImage || this.anonymouseImageUrl; } diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts index 8899f70daf..422ebbba39 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts @@ -15,132 +15,100 @@ * limitations under the License. */ +import { ReflectiveInjector } from '@angular/core'; import { BpmUserService } from '../services/bpm-user.service'; -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; -import { TestBed, async, inject } from '@angular/core/testing'; -import { BpmUserModel } from '../models/bpm-user.model'; +import { AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { fakeBpmUser } from '../assets/fake-bpm-user.service'; -export var fakeBpmUser: BpmUserModel = { - apps: {}, - capabilities: 'fake-capability', - company: 'fake-company', - created: 'fake-create-date', - email: 'fakeBpm@fake.com', - externalId: 'fake-external-id', - firstName: 'fake-first-name', - lastName: 'fake-last-name', - fullname: 'fake-full-name', - groups: {}, - id: 'fake-id', - lastUpdate: 'fake-update-date', - latestSyncTimeStamp: 'fake-timestamp', - password: 'fake-password', - pictureId: 'fake-picture-id', - status: 'fake-status', - tenantId: 'fake-tenant-id', - tenantName: 'fake-tenant-name', - tenantPictureId: 'fake-tenant-picture-id', - type: 'fake-type' -}; - -class StubAuthentication { - isEcmConnected: boolean; - isBpmConnected: boolean; - setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; }; - setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; }; - isEcmLoggedIn() { return this.isEcmConnected; }; - isBpmLoggedIn() { return this.isBpmConnected; }; - callApiGetPersonInfo() { return Promise.resolve(fakeBpmUser); }; -}; +declare let jasmine: any; describe('Bpm User service', () => { - beforeEach( async(() => { - TestBed.configureTestingModule({ - providers: [ BpmUserService, - { provide: AlfrescoAuthenticationService, useClass: StubAuthentication } - ] - }) - .compileComponents(); - })); + let service, injector, authService; - it('can instantiate service when inject service', - inject([BpmUserService], (service: BpmUserService) => { - expect(service instanceof BpmUserService).toBe(true); - })); + beforeEach(() => { + injector = ReflectiveInjector.resolveAndCreate([ + AlfrescoSettingsService, + AlfrescoApiService, + AlfrescoAuthenticationService, + BpmUserService + ]); + }); - it('can instantiate service with authorization', inject([AlfrescoAuthenticationService], - (auth: AlfrescoAuthenticationService) => { - expect(auth).not.toBeNull('authorization should be provided'); - let service = new BpmUserService(auth); - expect(service instanceof BpmUserService).toBe(true, 'new service should be ok'); - })); + beforeEach(() => { + service = injector.get(BpmUserService); + authService = injector.get(AlfrescoAuthenticationService); + }); + + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('can instantiate service with authorization', () => { + let serviceTest = new BpmUserService(authService); + + expect(serviceTest instanceof BpmUserService).toBe(true, 'new service should be ok'); + }); describe('when user is logged in', () => { - let service: BpmUserService; - let authServiceForTest: AlfrescoAuthenticationService; - beforeEach( - inject( - [AlfrescoAuthenticationService ], - ( authService: AlfrescoAuthenticationService ) => { - authServiceForTest = authService; - service = new BpmUserService(authService); - spyOn(authServiceForTest, 'isBpmLoggedIn').and.returnValue(true); - })); - - it('should be able to retrieve current user info', (done) => { - spyOn(service, 'callApiGetProfile').and.returnValue(Promise.resolve(fakeBpmUser)); - service.getCurrentUserInfo().subscribe( - (user) => { - expect(user).toBeDefined(); - expect(user.firstName).toEqual('fake-first-name'); - expect(user.lastName).toEqual('fake-last-name'); - expect(user.email).toEqual('fakeBpm@fake.com'); - done(); - }); + beforeEach(() => { + spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); }); - it('should retrieve current logged user information via js api', () => { - spyOn(service, 'callApiGetProfile'); - service.getCurrentUserInfo(); - expect(service.callApiGetProfile).toHaveBeenCalled(); + it('should be able to retrieve current user info', (done) => { + spyOn(service, 'getCurrentUserProfileImage').and.callThrough(); + service.getCurrentUserInfo().subscribe( + (user) => { + expect(user).toBeDefined(); + expect(user.firstName).toEqual('fake-first-name'); + expect(user.lastName).toEqual('fake-last-name'); + expect(user.email).toEqual('fakeBpm@fake.com'); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeBpmUser + }); }); it('should retrieve avatar url for current user', (done) => { - spyOn(service, 'callApiGetProfilePicture').and.returnValue(Promise.resolve('fake/img/path')); - service.getCurrentUserProfileImage().subscribe( - (path) => { - expect(path).toBeDefined(); - expect(path).toEqual('fake/img/path'); - done(); - }); + service.getCurrentUserProfileImage().subscribe( + (path) => { + expect(path).toBeDefined(); + expect(path).toEqual('fake/img/path'); + done(); + }); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: 'fake/img/path' + }); }); }); - +/* describe('when user is not logged in', () => { - let service: BpmUserService; - let authServiceForTest: AlfrescoAuthenticationService; - beforeEach( - inject( - [AlfrescoAuthenticationService], - (authService: AlfrescoAuthenticationService) => { - authServiceForTest = authService; - service = new BpmUserService(authService); - spyOn(authServiceForTest, 'isBpmLoggedIn').and.returnValue(false); - })); + beforeEach(() => { + spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); + }); it('should not retrieve the user information', () => { - spyOn(service, 'callApiGetProfile'); - service.getCurrentUserInfo(); - expect(service.callApiGetProfile).not.toHaveBeenCalled(); + spyOn(service, 'callApiGetProfile'); + service.getCurrentUserInfo(); + expect(service.callApiGetProfile).not.toHaveBeenCalled(); }); it('should not retrieve the user avatar', () => { - spyOn(service, 'callApiGetProfilePicture'); - service.getCurrentUserInfo(); - expect(service.callApiGetProfilePicture).not.toHaveBeenCalled(); + spyOn(service, 'callApiGetProfilePicture'); + service.getCurrentUserInfo(); + expect(service.callApiGetProfilePicture).not.toHaveBeenCalled(); }); - }); + });*/ }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts index b2cd97fadb..b20b1362e4 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts @@ -38,7 +38,7 @@ export class BpmUserService { */ getCurrentUserInfo(): Observable { if ( this.authService.isBpmLoggedIn() ) { - return Observable.fromPromise(this.callApiGetProfile()) + return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture()) .map( (data) => data ) @@ -46,9 +46,9 @@ export class BpmUserService { } } - getCurrentUserProfileImage(): any { + getCurrentUserProfileImage(): Observable { if ( this.authService.isBpmLoggedIn() ) { - return Observable.fromPromise(this.callApiGetProfilePicture()) + return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile()) .map( (data) => data ) @@ -56,25 +56,6 @@ export class BpmUserService { } } - /** - * Call js api to get current user profile picture - */ - callApiGetProfilePicture() { - try { - return this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture(); - } catch (exc) { - console.error(exc); - return null; - } - } - - /** - * Call js api to get current user information - */ - callApiGetProfile() { - return this.authService.getAlfrescoApi().activiti.profileApi.getProfile(); - } - /** * Throw the error * @param error diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts index 4d88d66fe9..1f82d78995 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts @@ -15,165 +15,100 @@ * limitations under the License. */ +import { ReflectiveInjector } from '@angular/core'; +import { + AlfrescoAuthenticationService, + AlfrescoApiService, + AlfrescoSettingsService, + AlfrescoContentService +} from 'ng2-alfresco-core'; import { EcmUserService } from '../services/ecm-user.service'; -import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core'; -import { TestBed, async, inject } from '@angular/core/testing'; -import { EcmUserModel } from '../models/ecm-user.model'; -import { EcmCompanyModel } from '../models/ecm-company.model'; +import { fakeEcmUser } from '../assets/fake-ecm-user.service'; -export var fakeEcmCompany: EcmCompanyModel = { - organization: 'company-fake-name', - address1: 'fake-address-1', - address2: 'fake-address-2', - address3: 'fake-address-3', - postcode: 'fAk1', - telephone: '00000000', - fax: '=1111111', - email: 'fakeCompany@fake.com' -}; - -export var fakeEcmUser: EcmUserModel = { - id: 'fake-id', - firstName: 'fake-first-name', - lastName: 'fake-last-name', - description: 'i am a fake user for test', - avatarId: 'fake-avatar-id', - email: 'fakeEcm@ecmUser.com', - skypeId: 'fake-skype-id', - googleId: 'fake-googleId-id', - instantMessageId: 'fake-instantMessageId-id', - company: fakeEcmCompany, - jobTitle: 'test job', - location: 'fake location', - mobile: '000000000', - telephone: '11111111', - statusUpdatedAt: 'fake-date', - userStatus: 'active', - enabled: true, - emailNotificationsEnabled: true -}; - -class StubAuthentication { - isEcmConnected: boolean; - isBpmConnected: boolean; - setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; }; - setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; }; - isEcmLoggedIn() { return this.isEcmConnected; }; - isBpmLoggedIn() { return this.isBpmConnected; }; - callApiGetPersonInfo() { return Promise.resolve(fakeEcmUser); }; -}; - -class StubAlfrescoContentService { - getContentUrl() { return 'fake/url/image/for/ecm/user'; } ; -} +declare let jasmine: any; describe('Ecm User service', () => { - beforeEach( async(() => { - TestBed.configureTestingModule({ - providers: [ EcmUserService, - { provide: AlfrescoAuthenticationService, useClass: StubAuthentication }, - { provide: AlfrescoContentService, useClass: StubAlfrescoContentService } - ] - }) - .compileComponents(); - })); + let service, injector, authService, contentService; - it('can instantiate service when inject service', - inject([EcmUserService], (service: EcmUserService) => { - expect(service instanceof EcmUserService).toBe(true); - })); + beforeEach(() => { + injector = ReflectiveInjector.resolveAndCreate([ + AlfrescoSettingsService, + AlfrescoApiService, + AlfrescoAuthenticationService, + AlfrescoContentService, + EcmUserService + ]); + }); - it('can instantiate service with authorization', inject([AlfrescoAuthenticationService], - (auth: AlfrescoAuthenticationService) => { - expect(auth).not.toBeNull('authorization should be provided'); - let service = new EcmUserService(auth, null); - expect(service instanceof EcmUserService).toBe(true, 'new service should be ok'); - })); + beforeEach(() => { + service = injector.get(EcmUserService); + authService = injector.get(AlfrescoAuthenticationService); + contentService = injector.get(AlfrescoContentService); + }); - it('can instantiate service with content service', inject([AlfrescoContentService], - (content: AlfrescoContentService) => { - expect(content).not.toBeNull('contentService should be provided'); - let service = new EcmUserService(null, content); - expect(service instanceof EcmUserService).toBe(true, 'new service should be ok'); - })); + it('can instantiate service with authorization', () => { + expect(authService).not.toBeNull('authorization should be provided'); + let serviceAuth = new EcmUserService(authService, null); + + expect(serviceAuth instanceof EcmUserService).toBe(true, 'new service should be ok'); + }); + + it('can instantiate service with content service', () => { + expect(contentService).not.toBeNull('contentService should be provided'); + let serviceContent = new EcmUserService(null, contentService); + + expect(serviceContent instanceof EcmUserService).toBe(true, 'new service should be ok'); + }); describe('when user is logged in', () => { - let service: EcmUserService; - let authServiceForTest: AlfrescoAuthenticationService; - let contentServiceForTest: AlfrescoContentService; - beforeEach( - inject( - [AlfrescoAuthenticationService, AlfrescoContentService], - (authService: AlfrescoAuthenticationService, content: AlfrescoContentService) => { - authServiceForTest = authService; - contentServiceForTest = content; - service = new EcmUserService(authService, content); - spyOn(authServiceForTest, 'isEcmLoggedIn').and.returnValue(true); - })); - - it('should be able to retrieve current user info', (done) => { - let userJsApiResponse = {entry: fakeEcmUser}; - spyOn(service, 'callApiGetPersonInfo').and.returnValue(Promise.resolve(userJsApiResponse)); - service.getCurrentUserInfo().subscribe( - (user) => { - expect(user).toBeDefined(); - expect(user.firstName).toEqual('fake-first-name'); - expect(user.lastName).toEqual('fake-last-name'); - expect(user.email).toEqual('fakeEcm@ecmUser.com'); - done(); - }); + beforeEach(() => { + spyOn(authService, 'isEcmLoggedIn').and.returnValue(true); + jasmine.Ajax.install(); }); - it('should retrieve current logged user information', () => { - spyOn(service, 'getUserInfo'); - spyOn(service, 'callApiGetPersonInfo').and.callThrough(); - service.getCurrentUserInfo(); - expect(service.getUserInfo).toHaveBeenCalledWith('-me-'); + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('should be able to retrieve current user info', (done) => { + service.getCurrentUserInfo().subscribe( + (user) => { + expect(user).toBeDefined(); + expect(user.firstName).toEqual('fake-first-name'); + expect(user.lastName).toEqual('fake-last-name'); + expect(user.email).toEqual('fakeEcm@ecmUser.com'); + done(); + }); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: {entry: fakeEcmUser} + }); }); it('should retrieve avatar url for current user', () => { - spyOn(contentServiceForTest, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user'); - let urlRs = service.getCurrentUserProfileImageUrl('fake-avatar-id'); + spyOn(contentService, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user'); + let urlRs = service.getUserProfileImage('fake-avatar-id'); - expect(urlRs).toEqual('fake/url/image/for/ecm/user'); + expect(urlRs).toEqual('fake/url/image/for/ecm/user'); }); it('should not call content service without avatar id', () => { - spyOn(contentServiceForTest, 'getContentUrl').and.callThrough(); - let urlRs = service.getCurrentUserProfileImageUrl(undefined); - expect(urlRs).toBeUndefined(); - expect(contentServiceForTest.getContentUrl).not.toHaveBeenCalled(); + spyOn(contentService, 'getContentUrl').and.callThrough(); + let urlRs = service.getUserProfileImage(undefined); + + expect(urlRs).toBeUndefined(); + expect(contentService.getContentUrl).not.toHaveBeenCalled(); }); it('should build the body for the content service', () => { - spyOn(contentServiceForTest, 'getContentUrl').and.callThrough(); - let urlRs = service.getCurrentUserProfileImageUrl('fake-avatar-id'); - expect(urlRs).toBeDefined(); - expect(contentServiceForTest.getContentUrl).toHaveBeenCalledWith( {entry: {id: 'fake-avatar-id'} }); - }); - }); + spyOn(contentService, 'getContentUrl').and.callThrough(); + let urlRs = service.getUserProfileImage('fake-avatar-id'); - describe('when user is not logged in', () => { - let service: EcmUserService; - let authServiceForTest: AlfrescoAuthenticationService; - let contentServiceForTest: AlfrescoContentService; - - beforeEach( - inject( - [AlfrescoAuthenticationService, AlfrescoContentService], - (authService: AlfrescoAuthenticationService, content: AlfrescoContentService) => { - authServiceForTest = authService; - contentServiceForTest = content; - service = new EcmUserService(authService, content); - spyOn(authServiceForTest, 'isEcmLoggedIn').and.returnValue(false); - })); - - it('should not retrieve the user information', () => { - spyOn(service, 'callApiGetPersonInfo'); - service.getCurrentUserInfo(); - expect(service.callApiGetPersonInfo).not.toHaveBeenCalled(); + expect(urlRs).toBeDefined(); + expect(contentService.getContentUrl).toHaveBeenCalledWith({entry: {id: 'fake-avatar-id'}}); }); }); }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts index 1175af0f1a..7ff3643ef5 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts @@ -37,24 +37,22 @@ export class EcmUserService { * @param userName - the user name */ getUserInfo(userName: string): Observable { - if ( this.authService.isEcmLoggedIn() ) { return Observable.fromPromise(this.callApiGetPersonInfo(userName)) .map( (data) => data['entry'] ) .catch(this.handleError); - } } getCurrentUserInfo() { return this.getUserInfo('-me-'); } - callApiGetPersonInfo(userName: string, opts?: any) { + private callApiGetPersonInfo(userName: string, opts?: any) { return this.authService.getAlfrescoApi().core.peopleApi.getPerson(userName, opts); } - getCurrentUserProfileImageUrl(avatarId: string) { + getUserProfileImage(avatarId: string) { if ( avatarId ) { let nodeObj = {entry: {id: avatarId}}; return this.contentService.getContentUrl(nodeObj); diff --git a/ng2-components/ng2-alfresco-userinfo/src/testing/fake-ecm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/testing/fake-ecm-user.service.ts deleted file mode 100644 index 2133e780b1..0000000000 --- a/ng2-components/ng2-alfresco-userinfo/src/testing/fake-ecm-user.service.ts +++ /dev/null @@ -1,107 +0,0 @@ -/*! - * @license - * Copyright 2016 Alfresco Software, Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// re-export for tester convenience -export { EcmUserModel } from '../models/ecm-user.model'; -export { EcmUserService } from '../services/ecm-user.service'; - -import { EcmUserModel } from '../models/ecm-user.model'; -import { EcmCompanyModel } from '../models/ecm-company.model'; -import { Observable } from 'rxjs/Rx'; - -export var fakeEcmCompany: EcmCompanyModel = { - organization: 'company-fake-name', - address1: 'fake-address-1', - address2: 'fake-address-2', - address3: 'fake-address-3', - postcode: 'fAk1', - telephone: '00000000', - fax: '11111111', - email: 'fakeCompany@fake.com' -}; - -export var fakeEcmUserNoImage: EcmUserModel = { - id: 'fake-id', - firstName: 'fake-first-name', - lastName: 'fake-last-name', - description: 'i am a fake user for test', - avatarId: undefined, - email: 'fakeEcm@ecmUser.com', - skypeId: 'fake-skype-id', - googleId: 'fake-googleId-id', - instantMessageId: 'fake-instantMessageId-id', - company: fakeEcmCompany, - jobTitle: 'test job', - location: 'fake location', - mobile: '000000000', - telephone: '11111111', - statusUpdatedAt: 'fake-date', - userStatus: 'active', - enabled: true, - emailNotificationsEnabled: true -}; - -export var fakeEcmUser: EcmUserModel = { - id: 'fake-id', - firstName: 'fake-first-name', - lastName: 'fake-last-name', - description: 'i am a fake user for test', - avatarId: 'fake-avatar-id', - email: 'fakeEcm@ecmUser.com', - skypeId: 'fake-skype-id', - googleId: 'fake-googleId-id', - instantMessageId: 'fake-instantMessageId-id', - company: fakeEcmCompany, - jobTitle: 'test job', - location: 'fake location', - mobile: '000000000', - telephone: '11111111', - statusUpdatedAt: 'fake-date', - userStatus: 'active', - enabled: true, - emailNotificationsEnabled: true -}; - -export class FakeEcmUserService { - - lastPromise: Observable; - public userNeeded = 0; - usersList = [fakeEcmUser, fakeEcmUserNoImage]; - - getUserInfo(userName: string) { - return this.lastPromise = Observable.of(this.usersList[this.userNeeded]); - }; - - getCurrentUserInfo() { - return this.getUserInfo('fake-id'); - }; - - getCurrentUserProfileImageUrl(avatarId: string) { - if ( avatarId ) { - return 'fake/url/image/for/ecm/user'; - } - }; - - respondWithTheUserWithoutImage() { - this.userNeeded = 1; - }; - - respondWithTheUserWithImage() { - this.userNeeded = 0; - }; - -} From c45b3878b793208b19e6e2ba823b585560b8c896 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 13 Oct 2016 01:29:23 +0100 Subject: [PATCH 2/4] test refactoring --- .../ng2-alfresco-userinfo/karma.conf.js | 2 -- ...rvice.ts => fake-bpm-user.service.mock.ts} | 0 ...rvice.ts => fake-ecm-user.service.mock.ts} | 0 .../components/user-info.component.spec.ts | 4 +-- .../src/services/bpm-user.service.spec.ts | 33 +++++++------------ .../src/services/bpm-user.service.ts | 8 +++-- .../src/services/ecm-user.service.spec.ts | 12 ++++++- 7 files changed, 31 insertions(+), 28 deletions(-) rename ng2-components/ng2-alfresco-userinfo/src/assets/{fake-bpm-user.service.ts => fake-bpm-user.service.mock.ts} (100%) rename ng2-components/ng2-alfresco-userinfo/src/assets/{fake-ecm-user.service.ts => fake-ecm-user.service.mock.ts} (100%) diff --git a/ng2-components/ng2-alfresco-userinfo/karma.conf.js b/ng2-components/ng2-alfresco-userinfo/karma.conf.js index 4dfc103d4d..8f3adc54b4 100644 --- a/ng2-components/ng2-alfresco-userinfo/karma.conf.js +++ b/ng2-components/ng2-alfresco-userinfo/karma.conf.js @@ -49,8 +49,6 @@ module.exports = function (config) { // paths to support debugging with source maps in dev tools {pattern: 'src/**/*.ts', included: false, watched: false}, {pattern: 'dist/**/*.js.map', included: false, watched: false} - // fake file path - { pattern: '/base/dist/src/img/anonymous.gif', included: false, watched: true, served: true } ], exclude: [ diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.mock.ts similarity index 100% rename from ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.ts rename to ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.mock.ts diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts similarity index 100% rename from ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.ts rename to ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts index bb86e401f0..e9fede4d72 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts @@ -18,8 +18,8 @@ import { UserInfoComponent } from './user-info.component'; import { EcmUserService } from '../services/ecm-user.service'; import { BpmUserService } from '../services/bpm-user.service'; -import { FakeEcmUserService } from '../assets/fake-ecm-user.service'; -import { FakeBpmUserService } from '../assets/fake-bpm-user.service'; +import { FakeEcmUserService } from '../assets/fake-ecm-user.service.mock'; +import { FakeBpmUserService } from '../assets/fake-bpm-user.service.mock'; import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core'; import { ComponentFixture, TestBed, async } from '@angular/core/testing'; diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts index 422ebbba39..352935c6e5 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts @@ -17,8 +17,9 @@ import { ReflectiveInjector } from '@angular/core'; import { BpmUserService } from '../services/bpm-user.service'; +// import { BpmUserModel } from '../models/bpm-user.model'; import { AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core'; -import { fakeBpmUser } from '../assets/fake-bpm-user.service'; +import { fakeBpmUser } from '../assets/fake-bpm-user.service.mock'; declare let jasmine: any; @@ -38,9 +39,6 @@ describe('Bpm User service', () => { beforeEach(() => { service = injector.get(BpmUserService); authService = injector.get(AlfrescoAuthenticationService); - }); - - beforeEach(() => { jasmine.Ajax.install(); }); @@ -61,20 +59,19 @@ describe('Bpm User service', () => { }); it('should be able to retrieve current user info', (done) => { - spyOn(service, 'getCurrentUserProfileImage').and.callThrough(); service.getCurrentUserInfo().subscribe( (user) => { - expect(user).toBeDefined(); - expect(user.firstName).toEqual('fake-first-name'); - expect(user.lastName).toEqual('fake-last-name'); - expect(user.email).toEqual('fakeBpm@fake.com'); + expect(user.fakeBpmUser).toBeDefined(); + expect(user.fakeBpmUser.firstName).toEqual('fake-first-name'); + expect(user.fakeBpmUser.lastName).toEqual('fake-last-name'); + expect(user.fakeBpmUser.email).toEqual('fakeBpm@fake.com'); done(); }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: fakeBpmUser + responseText: { fakeBpmUser } }); }); @@ -85,6 +82,7 @@ describe('Bpm User service', () => { expect(path).toEqual('fake/img/path'); done(); }); + jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', @@ -92,23 +90,16 @@ describe('Bpm User service', () => { }); }); }); -/* - describe('when user is not logged in', () => { + describe('when user is not logged in', () => { beforeEach(() => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); }); - it('should not retrieve the user information', () => { - spyOn(service, 'callApiGetProfile'); - service.getCurrentUserInfo(); - expect(service.callApiGetProfile).not.toHaveBeenCalled(); - }); - it('should not retrieve the user avatar', () => { - spyOn(service, 'callApiGetProfilePicture'); + spyOn(service, 'callGetProfilePictureApi'); service.getCurrentUserInfo(); - expect(service.callApiGetProfilePicture).not.toHaveBeenCalled(); + expect(service.callGetProfilePictureApi).not.toHaveBeenCalled(); }); - });*/ + }); }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts index b20b1362e4..3877268b4f 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts @@ -38,7 +38,7 @@ export class BpmUserService { */ getCurrentUserInfo(): Observable { if ( this.authService.isBpmLoggedIn() ) { - return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture()) + return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile()) .map( (data) => data ) @@ -48,7 +48,7 @@ export class BpmUserService { getCurrentUserProfileImage(): Observable { if ( this.authService.isBpmLoggedIn() ) { - return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile()) + return Observable.fromPromise(this.callGetProfilePictureApi()) .map( (data) => data ) @@ -56,6 +56,10 @@ export class BpmUserService { } } + callGetProfilePictureApi() { + return this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture(); + } + /** * Throw the error * @param error diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts index 1f82d78995..2449193f70 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts @@ -23,7 +23,7 @@ import { AlfrescoContentService } from 'ng2-alfresco-core'; import { EcmUserService } from '../services/ecm-user.service'; -import { fakeEcmUser } from '../assets/fake-ecm-user.service'; +import { fakeEcmUser } from '../assets/fake-ecm-user.service.mock'; declare let jasmine: any; @@ -88,6 +88,16 @@ describe('Ecm User service', () => { }); }); + it('should be able to log errors on call', (done) => { + service.getCurrentUserInfo().subscribe(() => {}, () => { + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 403 + }); + }); + it('should retrieve avatar url for current user', () => { spyOn(contentService, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user'); let urlRs = service.getUserProfileImage('fake-avatar-id'); From cc6a685bc4e5d0152dc5ac34c4c4cd62631bff8d Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 13 Oct 2016 01:42:27 +0100 Subject: [PATCH 3/4] fixed wrong tests --- .../components/user-info.component.spec.ts | 173 ++++++++++-------- .../src/components/user-info.component.ts | 12 +- .../src/services/bpm-user.service.spec.ts | 25 ++- .../src/services/bpm-user.service.ts | 18 +- .../src/services/ecm-user.service.spec.ts | 3 +- .../src/services/ecm-user.service.ts | 11 +- 6 files changed, 145 insertions(+), 97 deletions(-) diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts index e9fede4d72..58fa3d5c1d 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts @@ -24,16 +24,30 @@ import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfre import { ComponentFixture, TestBed, async } from '@angular/core/testing'; class StubAuthentication { - isEcmConnected: boolean; - isBpmConnected: boolean; - setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; }; - setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; }; - isEcmLoggedIn() { return this.isEcmConnected; }; - isBpmLoggedIn() { return this.isBpmConnected; }; + isEcmConnected: boolean; + isBpmConnected: boolean; + + setIsEcmLoggedIn(logged: boolean) { + this.isEcmConnected = logged; + }; + + setIsBpmLoggedIn(logged: boolean) { + this.isBpmConnected = logged; + }; + + isEcmLoggedIn() { + return this.isEcmConnected; + }; + + isBpmLoggedIn() { + return this.isBpmConnected; + }; } class StubAlfrescoContentService { - getContentUrl() { return 'fake/url/image/for/ecm/user'; } ; + getContentUrl() { + return 'fake/url/image/for/ecm/user'; + } ; } describe('User info component', () => { @@ -45,17 +59,17 @@ describe('User info component', () => { let fakeBpmService: FakeBpmUserService; beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ UserInfoComponent ], - providers: [{ provide: EcmUserService, useClass: FakeEcmUserService}, - { provide: BpmUserService, useClass: FakeBpmUserService}, - { provide: AlfrescoAuthenticationService, useClass: StubAuthentication }, - { provide: AlfrescoContentService, useClass: StubAlfrescoContentService } - ] - }).compileComponents().then(() => { - fixture = TestBed.createComponent(UserInfoComponent); - userInfoComp = fixture.componentInstance; - }); + TestBed.configureTestingModule({ + declarations: [UserInfoComponent], + providers: [{provide: EcmUserService, useClass: FakeEcmUserService}, + {provide: BpmUserService, useClass: FakeBpmUserService}, + {provide: AlfrescoAuthenticationService, useClass: StubAuthentication}, + {provide: AlfrescoContentService, useClass: StubAlfrescoContentService} + ] + }).compileComponents().then(() => { + fixture = TestBed.createComponent(UserInfoComponent); + userInfoComp = fixture.componentInstance; + }); })); it('should NOT have users before ngOnInit only anonymous image', () => { @@ -75,18 +89,33 @@ describe('User info component', () => { expect(userInfoComp.anonymouseImageUrl).toBeDefined(); }); + it('should format null string values in null value', () => { + let res = userInfoComp.formatValue('null'); + + expect(res).toBeDefined(); + expect(res).toBeNull(); + }); + + it('should return the value when it is not null string', () => { + let res = userInfoComp.formatValue('fake-value'); + + expect(res).toBeDefined(); + expect(res).not.toBeNull(); + expect(res).toEqual('fake-value'); + }); + describe('when user is logged on ecm', () => { - beforeEach( async(() => { + beforeEach(async(() => { authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService); fakeEcmService = fixture.debugElement.injector.get(EcmUserService); authStub.setIsEcmLoggedIn(true); fixture.detectChanges(); // runs ngOnInit -> getUsers fixture.whenStable() - .then( () => { - fixture.detectChanges(); - } ); + .then(() => { + fixture.detectChanges(); + }); })); it('should get the ecm current user image from the service', () => { @@ -105,27 +134,27 @@ describe('User info component', () => { fakeEcmService.respondWithTheUserWithoutImage(); userInfoComp.ngOnInit(); fixture.whenStable() - .then( () => { - fixture.detectChanges(); - let res = userInfoComp.getEcmUserAvatar(); - expect(userInfoComp.ecmUserImage).toBeUndefined(); - expect(res).toEqual(userInfoComp.anonymouseImageUrl); - }); + .then(() => { + fixture.detectChanges(); + let res = userInfoComp.getEcmUserAvatar(); + expect(userInfoComp.ecmUserImage).toBeUndefined(); + expect(res).toEqual(userInfoComp.anonymouseImageUrl); + }); })); }); describe('when user is logged on bpm', () => { - beforeEach( async(() => { + beforeEach(async(() => { authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService); fakeBpmService = fixture.debugElement.injector.get(BpmUserService); authStub.setIsBpmLoggedIn(true); fixture.detectChanges(); // runs ngOnInit -> getUsers fixture.whenStable() - .then( () => { - fixture.detectChanges(); - } ); + .then(() => { + fixture.detectChanges(); + }); })); it('should get the bpm current user image from the service', () => { @@ -144,18 +173,18 @@ describe('User info component', () => { fakeBpmService.respondWithTheUserWithoutImage(); userInfoComp.ngOnInit(); fixture.whenStable() - .then( () => { - fixture.detectChanges(); - let res = userInfoComp.getBpmUserAvatar(); - expect(userInfoComp.bpmUserImage).toBeUndefined(); - expect(res).toEqual(userInfoComp.anonymouseImageUrl); - }); + .then(() => { + fixture.detectChanges(); + let res = userInfoComp.getBpmUserAvatar(); + expect(userInfoComp.bpmUserImage).toBeUndefined(); + expect(res).toEqual(userInfoComp.anonymouseImageUrl); + }); })); }); describe('when user is logged on bpm and ecm', () => { - beforeEach( async(() => { + beforeEach(async(() => { authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService); fakeBpmService = fixture.debugElement.injector.get(BpmUserService); fakeEcmService = fixture.debugElement.injector.get(EcmUserService); @@ -164,9 +193,9 @@ describe('User info component', () => { authStub.setIsEcmLoggedIn(true); fixture.detectChanges(); // runs ngOnInit -> getUsers fixture.whenStable() - .then( () => { - fixture.detectChanges(); - } ); + .then(() => { + fixture.detectChanges(); + }); })); it('should get the bpm current user image from the service', () => { @@ -192,15 +221,15 @@ describe('User info component', () => { fakeEcmService.respondWithTheUserWithoutImage(); userInfoComp.ngOnInit(); fixture.whenStable() - .then( () => { - fixture.detectChanges(); - let resBpm = userInfoComp.getBpmUserAvatar(); - expect(userInfoComp.bpmUserImage).toBeUndefined(); - expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl); - let resEcm = userInfoComp.getEcmUserAvatar(); - expect(userInfoComp.ecmUserImage).toBeUndefined(); - expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl); - }); + .then(() => { + fixture.detectChanges(); + let resBpm = userInfoComp.getBpmUserAvatar(); + expect(userInfoComp.bpmUserImage).toBeUndefined(); + expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl); + let resEcm = userInfoComp.getEcmUserAvatar(); + expect(userInfoComp.ecmUserImage).toBeUndefined(); + expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl); + }); })); it('should return the ecm image if exists', async(() => { @@ -208,13 +237,13 @@ describe('User info component', () => { fakeEcmService.respondWithTheUserWithImage(); userInfoComp.ngOnInit(); fixture.whenStable() - .then( () => { - fixture.detectChanges(); - let res = userInfoComp.getUserAvatar(); - expect(userInfoComp.bpmUserImage).toBeDefined(); - expect(userInfoComp.ecmUserImage).toBeDefined(); - expect(res).toEqual(userInfoComp.ecmUserImage); - }); + .then(() => { + fixture.detectChanges(); + let res = userInfoComp.getUserAvatar(); + expect(userInfoComp.bpmUserImage).toBeDefined(); + expect(userInfoComp.ecmUserImage).toBeDefined(); + expect(res).toEqual(userInfoComp.ecmUserImage); + }); })); it('should return the bpm image if ecm does not have it', async(() => { @@ -222,13 +251,13 @@ describe('User info component', () => { fakeEcmService.respondWithTheUserWithoutImage(); userInfoComp.ngOnInit(); fixture.whenStable() - .then( () => { - fixture.detectChanges(); - let res = userInfoComp.getUserAvatar(); - expect(userInfoComp.bpmUserImage).toBeDefined(); - expect(userInfoComp.ecmUserImage).toBeUndefined(); - expect(res).toEqual(userInfoComp.bpmUserImage); - }); + .then(() => { + fixture.detectChanges(); + let res = userInfoComp.getUserAvatar(); + expect(userInfoComp.bpmUserImage).toBeDefined(); + expect(userInfoComp.ecmUserImage).toBeUndefined(); + expect(res).toEqual(userInfoComp.bpmUserImage); + }); })); it('should return the anonynous avatar if no user has it', async(() => { @@ -236,13 +265,13 @@ describe('User info component', () => { fakeEcmService.respondWithTheUserWithoutImage(); userInfoComp.ngOnInit(); fixture.whenStable() - .then( () => { - fixture.detectChanges(); - let res = userInfoComp.getUserAvatar(); - expect(userInfoComp.bpmUserImage).toBeUndefined(); - expect(userInfoComp.ecmUserImage).toBeUndefined(); - expect(res).toEqual(userInfoComp.anonymouseImageUrl); - }); + .then(() => { + fixture.detectChanges(); + let res = userInfoComp.getUserAvatar(); + expect(userInfoComp.bpmUserImage).toBeUndefined(); + expect(userInfoComp.ecmUserImage).toBeUndefined(); + expect(res).toEqual(userInfoComp.anonymouseImageUrl); + }); })); }); }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts index 063dd42517..9b67109f3e 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts @@ -51,7 +51,7 @@ export class UserInfoComponent implements OnInit { .subscribe( (res) => { this.ecmUser = res; - this.getEcmAvatar(); + this._getEcmAvatar(); } ); } @@ -72,23 +72,23 @@ export class UserInfoComponent implements OnInit { } } - private getEcmAvatar() { + private _getEcmAvatar() { this.ecmUserImage = this.ecmUserService.getUserProfileImage(this.ecmUser.avatarId); } - public getUserAvatar() { + getUserAvatar() { return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl; } - public getBpmUserAvatar() { + getBpmUserAvatar() { return this.bpmUserImage || this.anonymouseImageUrl; } - public getEcmUserAvatar() { + getEcmUserAvatar() { return this.ecmUserImage || this.anonymouseImageUrl; } - public formatValue(value: string) { + formatValue(value: string) { return value === 'null' ? null : value; } diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts index 352935c6e5..7bb8ba1b91 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.spec.ts @@ -71,22 +71,39 @@ describe('Bpm User service', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: { fakeBpmUser } + responseText: {fakeBpmUser} }); }); it('should retrieve avatar url for current user', (done) => { + spyOn(service, 'callGetProfilePictureApi').and.returnValue(Promise.resolve('fake/img/path')); service.getCurrentUserProfileImage().subscribe( (path) => { expect(path).toBeDefined(); expect(path).toEqual('fake/img/path'); done(); }); + }); + + it('should be able to log errors on call for profile', (done) => { + service.getCurrentUserInfo().subscribe(() => { + }, () => { + done(); + }); jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200, - contentType: 'json', - responseText: 'fake/img/path' + status: 403 + }); + }); + + it('should be able to log errors on call for profile picture', (done) => { + service.getCurrentUserProfileImage().subscribe(() => { + }, () => { + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 403 }); }); }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts index 3877268b4f..d666c17178 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts @@ -37,23 +37,23 @@ export class BpmUserService { * @param userName - the user name */ getCurrentUserInfo(): Observable { - if ( this.authService.isBpmLoggedIn() ) { + if (this.authService.isBpmLoggedIn()) { return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile()) .map( - (data) => data - ) + (data) => data + ) .catch(this.handleError); } } getCurrentUserProfileImage(): Observable { - if ( this.authService.isBpmLoggedIn() ) { - return Observable.fromPromise(this.callGetProfilePictureApi()) - .map( + if (this.authService.isBpmLoggedIn()) { + return Observable.fromPromise(this.callGetProfilePictureApi()) + .map( (data) => data - ) - .catch(this.handleError); - } + ) + .catch(this.handleError); + } } callGetProfilePictureApi() { diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts index 2449193f70..2f048d93b4 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts @@ -89,7 +89,8 @@ describe('Ecm User service', () => { }); it('should be able to log errors on call', (done) => { - service.getCurrentUserInfo().subscribe(() => {}, () => { + service.getCurrentUserInfo().subscribe(() => { + }, () => { done(); }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts index 7ff3643ef5..7edeefad40 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts @@ -30,7 +30,8 @@ import { EcmUserModel } from '../models/ecm-user.model'; export class EcmUserService { constructor(private authService: AlfrescoAuthenticationService, - private contentService: AlfrescoContentService) {} + private contentService: AlfrescoContentService) { + } /** * get User Information via ECM @@ -39,8 +40,8 @@ export class EcmUserService { getUserInfo(userName: string): Observable { return Observable.fromPromise(this.callApiGetPersonInfo(userName)) .map( - (data) => data['entry'] - ) + (data) => data['entry'] + ) .catch(this.handleError); } @@ -53,10 +54,10 @@ export class EcmUserService { } getUserProfileImage(avatarId: string) { - if ( avatarId ) { + if (avatarId) { let nodeObj = {entry: {id: avatarId}}; return this.contentService.getContentUrl(nodeObj); - } + } } /** From 0a539e9fdd70c25d299deeed5bebf82f2c7bfe3c Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 13 Oct 2016 18:18:50 +0100 Subject: [PATCH 4/4] Refactor for PR --- .../ng2-alfresco-userinfo/karma.conf.js | 4 + .../src/assets/anonymous.gif | Bin 0 -> 1765 bytes .../src/assets/bpmImg.gif | Bin 0 -> 1765 bytes .../src/assets/ecmImg.gif | Bin 0 -> 1765 bytes .../src/assets/fake-bpm-user.service.mock.ts | 65 +++-- .../src/assets/fake-ecm-user.service.mock.ts | 29 +- .../src/components/user-info.component.html | 40 +-- .../components/user-info.component.spec.ts | 273 +++++++++++------- .../src/components/user-info.component.ts | 35 +-- .../src/services/bpm-user.service.spec.ts | 20 +- .../src/services/bpm-user.service.ts | 22 +- 11 files changed, 289 insertions(+), 199 deletions(-) create mode 100644 ng2-components/ng2-alfresco-userinfo/src/assets/anonymous.gif create mode 100644 ng2-components/ng2-alfresco-userinfo/src/assets/bpmImg.gif create mode 100644 ng2-components/ng2-alfresco-userinfo/src/assets/ecmImg.gif diff --git a/ng2-components/ng2-alfresco-userinfo/karma.conf.js b/ng2-components/ng2-alfresco-userinfo/karma.conf.js index 8f3adc54b4..2b805693c3 100644 --- a/ng2-components/ng2-alfresco-userinfo/karma.conf.js +++ b/ng2-components/ng2-alfresco-userinfo/karma.conf.js @@ -45,6 +45,10 @@ module.exports = function (config) { // ng2-components { pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false }, + // Fake files + { pattern: 'src/assets/ecmImg.gif', included: false, watched: true, served: true }, + { pattern: 'src/assets/bpmImg.gif', included: false, watched: true, served: true }, + { pattern: 'src/img/anonymous.gif', included: false, watched: true, served: true }, // paths to support debugging with source maps in dev tools {pattern: 'src/**/*.ts', included: false, watched: false}, diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/anonymous.gif b/ng2-components/ng2-alfresco-userinfo/src/assets/anonymous.gif new file mode 100644 index 0000000000000000000000000000000000000000..e1b58fa57dfcdfd452ec498c98b930aa905d21d6 GIT binary patch literal 1765 zcmb8pizCyC0|4;vcMq|L=guW!Vi%c59pzQG$YVmt(9<&qUk|0_<~^#dpPrfJR`3LkEhFNwuD*UseB%E9NpnxZIwFun4Gh4>giwRA zc0?x^01y1ne**w~537AIAf!0BrjESujDjDc-khY>t=wMO?<%F(;}2yFR74Dt%}a)P zREJt`!8kwqm|RZoeK}|r3IHK##rgzkWXR z#*`{VI@~f{tInV0ukwK$G*WXf9#@J?Z!6r2$!xjap@7u(QUCMI;#?2#}9bcnDw%MSwt8tuX$>-NEJGdr(T*AtL&uqN~#WT z-g_QP^LsP+c=+}i&ztKwm?_}Wl%Vf);6;vy(fFPKq-Krf{zpQvQICg(?Ug@>Nx&U+ zjC*f3!1kFY4zS~t!;(qN5%NIU3H4v3)8o8SJ&}xYli-Iq9S6HVS;BT^QM6I<7xiew zs43F&{rZ7&()90DAGOE2XC;|(F#99fIapv)+E_ML>o!h2H=U!U*6L3=``J^Qqoo7W zf@~)ZW~T7YOjSR6)Sl9&+Nd*+aNRrksZvj^#`9rO9o8rC1d|21)u|F3inL-f#Wi}R<~|kmHN&5; z3B)yYe%YIv8;IuZpFayGV;%0-^uB2NgFe{gg7ft_xj^TT_Y{uR${^)A3ysIpSs39& z9ijG;m}vnKkiUg2%P?vsYQCJO@$_OV@CO0Hu)t)o;|R^??X%tO1-F=8j*)@eCsBO8 zi%eVFsxw-!Lvd0lwD|S>cPa5}M3u<4Tb}T$Ox;$^a_lM*m{i5Pu{oB{h2Ay`Po(Dx zD#N-MNvdBGX_`Lud8}5idh^1LixlXK&^sCJ@PI-IJn*VhrM|k_W5)x{ zzhbeqUP%h#MU{Oa-7EuT&#~1EiAPO=nPq4Rbk@D@* z6M~fh0C=qA2Fx`k=Mt6^izaq#br)QLk3CvAW9%+&^6yXaFr(JLRl%+P{?WF8(;BaX zE{t!)7R`6~pLq*@-8wtlZL#g$h)*e9)U%B{XxYCXGPN_V;k|Z!l;3$33aB3vZ~j!f z8jhOM^$Qdom4h>-B7!MgsLVCNNk__$82?`QspL*0zwl&CWb!J(Q;GX2gTXNKJLh7b zN8^5=;xVjOqw+n`ziQf<^ritlK&M(Z8LjoT%+`GX4nZhrFaHSbxJOg`KARNhh?nMx zGP`u#0?`@`N33T&?%+eSu$L?L=-+paXBat?0s^Lq(6>66KiD9fJaJdGPrldmp)ES9 zq5Q@w&+dWzairp+mQ9lhlYn@l$-pFQ%6Vm;W0F$S`6)^oDnz!UA}W)wZD#Nf-02yE zSxiRiSbJrnHZpS2^QFqWDWYiJ2_&D4GxJTob6game4Rnp4-a8oK0|uY-oP;ACYJg= zfzq$)JUSkdEEQ-FsXFl0O1;D@^(Svq!Dtb~|zD{Xe%&8EA}t;;Z>bJpL9WgQD_~sHG5(h>mr{Irog}T$u=eqGe-Q&yn=bw z7r-~(&JD^vmmxkz!hBa8Ik(`jlhvudkmrW!#)Y{1Gd3YvBL>qqDmh!%F}{e44g(m3 zaqT=bY?~3aCoJ(;oj;Ql3NL$?!}~e$!?~b?QkCYp)qa#vtFm`QZozZZrH&eTD*&+g E7ZAQxl>h($ literal 0 HcmV?d00001 diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/bpmImg.gif b/ng2-components/ng2-alfresco-userinfo/src/assets/bpmImg.gif new file mode 100644 index 0000000000000000000000000000000000000000..e1b58fa57dfcdfd452ec498c98b930aa905d21d6 GIT binary patch literal 1765 zcmb8pizCyC0|4;vcMq|L=guW!Vi%c59pzQG$YVmt(9<&qUk|0_<~^#dpPrfJR`3LkEhFNwuD*UseB%E9NpnxZIwFun4Gh4>giwRA zc0?x^01y1ne**w~537AIAf!0BrjESujDjDc-khY>t=wMO?<%F(;}2yFR74Dt%}a)P zREJt`!8kwqm|RZoeK}|r3IHK##rgzkWXR z#*`{VI@~f{tInV0ukwK$G*WXf9#@J?Z!6r2$!xjap@7u(QUCMI;#?2#}9bcnDw%MSwt8tuX$>-NEJGdr(T*AtL&uqN~#WT z-g_QP^LsP+c=+}i&ztKwm?_}Wl%Vf);6;vy(fFPKq-Krf{zpQvQICg(?Ug@>Nx&U+ zjC*f3!1kFY4zS~t!;(qN5%NIU3H4v3)8o8SJ&}xYli-Iq9S6HVS;BT^QM6I<7xiew zs43F&{rZ7&()90DAGOE2XC;|(F#99fIapv)+E_ML>o!h2H=U!U*6L3=``J^Qqoo7W zf@~)ZW~T7YOjSR6)Sl9&+Nd*+aNRrksZvj^#`9rO9o8rC1d|21)u|F3inL-f#Wi}R<~|kmHN&5; z3B)yYe%YIv8;IuZpFayGV;%0-^uB2NgFe{gg7ft_xj^TT_Y{uR${^)A3ysIpSs39& z9ijG;m}vnKkiUg2%P?vsYQCJO@$_OV@CO0Hu)t)o;|R^??X%tO1-F=8j*)@eCsBO8 zi%eVFsxw-!Lvd0lwD|S>cPa5}M3u<4Tb}T$Ox;$^a_lM*m{i5Pu{oB{h2Ay`Po(Dx zD#N-MNvdBGX_`Lud8}5idh^1LixlXK&^sCJ@PI-IJn*VhrM|k_W5)x{ zzhbeqUP%h#MU{Oa-7EuT&#~1EiAPO=nPq4Rbk@D@* z6M~fh0C=qA2Fx`k=Mt6^izaq#br)QLk3CvAW9%+&^6yXaFr(JLRl%+P{?WF8(;BaX zE{t!)7R`6~pLq*@-8wtlZL#g$h)*e9)U%B{XxYCXGPN_V;k|Z!l;3$33aB3vZ~j!f z8jhOM^$Qdom4h>-B7!MgsLVCNNk__$82?`QspL*0zwl&CWb!J(Q;GX2gTXNKJLh7b zN8^5=;xVjOqw+n`ziQf<^ritlK&M(Z8LjoT%+`GX4nZhrFaHSbxJOg`KARNhh?nMx zGP`u#0?`@`N33T&?%+eSu$L?L=-+paXBat?0s^Lq(6>66KiD9fJaJdGPrldmp)ES9 zq5Q@w&+dWzairp+mQ9lhlYn@l$-pFQ%6Vm;W0F$S`6)^oDnz!UA}W)wZD#Nf-02yE zSxiRiSbJrnHZpS2^QFqWDWYiJ2_&D4GxJTob6game4Rnp4-a8oK0|uY-oP;ACYJg= zfzq$)JUSkdEEQ-FsXFl0O1;D@^(Svq!Dtb~|zD{Xe%&8EA}t;;Z>bJpL9WgQD_~sHG5(h>mr{Irog}T$u=eqGe-Q&yn=bw z7r-~(&JD^vmmxkz!hBa8Ik(`jlhvudkmrW!#)Y{1Gd3YvBL>qqDmh!%F}{e44g(m3 zaqT=bY?~3aCoJ(;oj;Ql3NL$?!}~e$!?~b?QkCYp)qa#vtFm`QZozZZrH&eTD*&+g E7ZAQxl>h($ literal 0 HcmV?d00001 diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/ecmImg.gif b/ng2-components/ng2-alfresco-userinfo/src/assets/ecmImg.gif new file mode 100644 index 0000000000000000000000000000000000000000..e1b58fa57dfcdfd452ec498c98b930aa905d21d6 GIT binary patch literal 1765 zcmb8pizCyC0|4;vcMq|L=guW!Vi%c59pzQG$YVmt(9<&qUk|0_<~^#dpPrfJR`3LkEhFNwuD*UseB%E9NpnxZIwFun4Gh4>giwRA zc0?x^01y1ne**w~537AIAf!0BrjESujDjDc-khY>t=wMO?<%F(;}2yFR74Dt%}a)P zREJt`!8kwqm|RZoeK}|r3IHK##rgzkWXR z#*`{VI@~f{tInV0ukwK$G*WXf9#@J?Z!6r2$!xjap@7u(QUCMI;#?2#}9bcnDw%MSwt8tuX$>-NEJGdr(T*AtL&uqN~#WT z-g_QP^LsP+c=+}i&ztKwm?_}Wl%Vf);6;vy(fFPKq-Krf{zpQvQICg(?Ug@>Nx&U+ zjC*f3!1kFY4zS~t!;(qN5%NIU3H4v3)8o8SJ&}xYli-Iq9S6HVS;BT^QM6I<7xiew zs43F&{rZ7&()90DAGOE2XC;|(F#99fIapv)+E_ML>o!h2H=U!U*6L3=``J^Qqoo7W zf@~)ZW~T7YOjSR6)Sl9&+Nd*+aNRrksZvj^#`9rO9o8rC1d|21)u|F3inL-f#Wi}R<~|kmHN&5; z3B)yYe%YIv8;IuZpFayGV;%0-^uB2NgFe{gg7ft_xj^TT_Y{uR${^)A3ysIpSs39& z9ijG;m}vnKkiUg2%P?vsYQCJO@$_OV@CO0Hu)t)o;|R^??X%tO1-F=8j*)@eCsBO8 zi%eVFsxw-!Lvd0lwD|S>cPa5}M3u<4Tb}T$Ox;$^a_lM*m{i5Pu{oB{h2Ay`Po(Dx zD#N-MNvdBGX_`Lud8}5idh^1LixlXK&^sCJ@PI-IJn*VhrM|k_W5)x{ zzhbeqUP%h#MU{Oa-7EuT&#~1EiAPO=nPq4Rbk@D@* z6M~fh0C=qA2Fx`k=Mt6^izaq#br)QLk3CvAW9%+&^6yXaFr(JLRl%+P{?WF8(;BaX zE{t!)7R`6~pLq*@-8wtlZL#g$h)*e9)U%B{XxYCXGPN_V;k|Z!l;3$33aB3vZ~j!f z8jhOM^$Qdom4h>-B7!MgsLVCNNk__$82?`QspL*0zwl&CWb!J(Q;GX2gTXNKJLh7b zN8^5=;xVjOqw+n`ziQf<^ritlK&M(Z8LjoT%+`GX4nZhrFaHSbxJOg`KARNhh?nMx zGP`u#0?`@`N33T&?%+eSu$L?L=-+paXBat?0s^Lq(6>66KiD9fJaJdGPrldmp)ES9 zq5Q@w&+dWzairp+mQ9lhlYn@l$-pFQ%6Vm;W0F$S`6)^oDnz!UA}W)wZD#Nf-02yE zSxiRiSbJrnHZpS2^QFqWDWYiJ2_&D4GxJTob6game4Rnp4-a8oK0|uY-oP;ACYJg= zfzq$)JUSkdEEQ-FsXFl0O1;D@^(Svq!Dtb~|zD{Xe%&8EA}t;;Z>bJpL9WgQD_~sHG5(h>mr{Irog}T$u=eqGe-Q&yn=bw z7r-~(&JD^vmmxkz!hBa8Ik(`jlhvudkmrW!#)Y{1Gd3YvBL>qqDmh!%F}{e44g(m3 zaqT=bY?~3aCoJ(;oj;Ql3NL$?!}~e$!?~b?QkCYp)qa#vtFm`QZozZZrH&eTD*&+g E7ZAQxl>h($ literal 0 HcmV?d00001 diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.mock.ts b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.mock.ts index ffddf85e68..eae63e6272 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.mock.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-bpm-user.service.mock.ts @@ -60,7 +60,30 @@ export var fakeBpmUser: BpmUserModel = { lastUpdate: 'fake-update-date', latestSyncTimeStamp: 'fake-timestamp', password: 'fake-password', - pictureId: 'fake-picture-id', + pictureId: 'src/assets/bpmImg.gif', + status: 'fake-status', + tenantId: 'fake-tenant-id', + tenantName: 'fake-tenant-name', + tenantPictureId: 'fake-tenant-picture-id', + type: 'fake-type' +}; + +export var fakeBpmEditedUser: BpmUserModel = { + apps: {}, + capabilities: 'fake-capability', + company: 'fake-company', + created: 'fake-create-date', + email: 'fakeBpm@fake.com', + externalId: 'fake-external-id', + firstName: 'fake-first-name', + lastName: 'fake-last-name', + fullname: 'fake-full-name', + groups: {}, + id: 'fake-id', + lastUpdate: 'fake-update-date', + latestSyncTimeStamp: 'fake-timestamp', + password: 'fake-password', + pictureId: 'src/assets/bpmImg.gif', status: 'fake-status', tenantId: 'fake-tenant-id', tenantName: 'fake-tenant-name', @@ -70,27 +93,31 @@ export var fakeBpmUser: BpmUserModel = { export class FakeBpmUserService { - lastPromise: Observable; - public userNeeded = 0; - usersList = [fakeBpmUser, fakeBpmUserNoImage]; + lastPromise: Observable; + public userNeeded = 0; + usersList = [fakeBpmUser, fakeBpmUserNoImage, fakeBpmEditedUser]; - getUserInfo(userName: string) { - return this.lastPromise = Observable.of(this.usersList[this.userNeeded]); - }; + getUserInfo(userName: string) { + return this.lastPromise = Observable.of(this.usersList[this.userNeeded]); + }; - getCurrentUserInfo() { - return this.getUserInfo('fake-id'); - }; + getCurrentUserInfo() { + return this.getUserInfo('fake-id'); + }; - getCurrentUserProfileImage() { - return Observable.of(this.usersList[this.userNeeded].pictureId); - }; + getCurrentUserProfileImage() { + return Observable.of(this.usersList[this.userNeeded].pictureId); + }; - respondWithTheUserWithoutImage() { - this.userNeeded = 1; - } + respondWithTheUserWithoutImage() { + this.userNeeded = 1; + } - respondWithTheUserWithImage() { - this.userNeeded = 0; - } + respondWithTheUserWithImage() { + this.userNeeded = 0; + } + + respondWithEditedUser() { + this.userNeeded = 2; + } } diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts index 9024896f7b..c2d7a9d040 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts @@ -76,11 +76,32 @@ export var fakeEcmUser: EcmUserModel = { emailNotificationsEnabled: true }; +export var fakeEcmEditedUser: EcmUserModel = { + id: 'fake-id', + firstName: 'fake-first-name', + lastName: 'fake-last-name', + description: 'i am a fake user for test', + avatarId: 'fake-avatar-id', + email: 'fakeEcm@ecmUser.com', + skypeId: 'fake-skype-id', + googleId: 'fake-googleId-id', + instantMessageId: 'fake-instantMessageId-id', + company: fakeEcmCompany, + jobTitle: 'test job', + location: 'fake location', + mobile: '000000000', + telephone: '11111111', + statusUpdatedAt: 'fake-date', + userStatus: 'active', + enabled: true, + emailNotificationsEnabled: true +}; + export class FakeEcmUserService { lastPromise: Observable; public userNeeded = 0; - usersList = [fakeEcmUser, fakeEcmUserNoImage]; + usersList = [fakeEcmUser, fakeEcmUserNoImage, fakeEcmEditedUser]; getUserInfo(userName: string) { return this.lastPromise = Observable.of(this.usersList[this.userNeeded]); @@ -92,7 +113,7 @@ export class FakeEcmUserService { getUserProfileImage(avatarId: string) { if (avatarId) { - return 'fake/url/image/for/ecm/user'; + return 'src/assets/ecmImg.gif'; } }; @@ -104,4 +125,8 @@ export class FakeEcmUserService { this.userNeeded = 0; }; + respondWithEditedUser() { + this.userNeeded = 2; + }; + } diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html index 04b7db4e95..a5cccc1539 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html @@ -1,56 +1,58 @@ -
- {{ecmUser.firstName || ecmUser.lastName}} - +
+ {{ecmUser.firstName || ecmUser.lastName}} + {{ formatValue(bpmUser.firstName) || formatValue(bpmUser.lastName) || - formatValue(bpmUser.fullName) }} + formatValue(bpmUser.fullname) }} -
+
-