mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
@@ -45,6 +45,10 @@ module.exports = function (config) {
|
|||||||
|
|
||||||
// ng2-components
|
// ng2-components
|
||||||
{ pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false },
|
{ 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
|
// paths to support debugging with source maps in dev tools
|
||||||
{pattern: 'src/**/*.ts', included: false, watched: false},
|
{pattern: 'src/**/*.ts', included: false, watched: false},
|
||||||
|
BIN
ng2-components/ng2-alfresco-userinfo/src/assets/anonymous.gif
Normal file
BIN
ng2-components/ng2-alfresco-userinfo/src/assets/anonymous.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
ng2-components/ng2-alfresco-userinfo/src/assets/bpmImg.gif
Normal file
BIN
ng2-components/ng2-alfresco-userinfo/src/assets/bpmImg.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
ng2-components/ng2-alfresco-userinfo/src/assets/ecmImg.gif
Normal file
BIN
ng2-components/ng2-alfresco-userinfo/src/assets/ecmImg.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
@@ -60,7 +60,30 @@ export var fakeBpmUser: BpmUserModel = {
|
|||||||
lastUpdate: 'fake-update-date',
|
lastUpdate: 'fake-update-date',
|
||||||
latestSyncTimeStamp: 'fake-timestamp',
|
latestSyncTimeStamp: 'fake-timestamp',
|
||||||
password: 'fake-password',
|
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',
|
status: 'fake-status',
|
||||||
tenantId: 'fake-tenant-id',
|
tenantId: 'fake-tenant-id',
|
||||||
tenantName: 'fake-tenant-name',
|
tenantName: 'fake-tenant-name',
|
||||||
@@ -70,27 +93,31 @@ export var fakeBpmUser: BpmUserModel = {
|
|||||||
|
|
||||||
export class FakeBpmUserService {
|
export class FakeBpmUserService {
|
||||||
|
|
||||||
lastPromise: Observable<BpmUserModel>;
|
lastPromise: Observable<BpmUserModel>;
|
||||||
public userNeeded = 0;
|
public userNeeded = 0;
|
||||||
usersList = [fakeBpmUser, fakeBpmUserNoImage];
|
usersList = [fakeBpmUser, fakeBpmUserNoImage, fakeBpmEditedUser];
|
||||||
|
|
||||||
getUserInfo(userName: string) {
|
getUserInfo(userName: string) {
|
||||||
return this.lastPromise = Observable.of(this.usersList[this.userNeeded]);
|
return this.lastPromise = Observable.of(this.usersList[this.userNeeded]);
|
||||||
};
|
};
|
||||||
|
|
||||||
getCurrentUserInfo() {
|
getCurrentUserInfo() {
|
||||||
return this.getUserInfo('fake-id');
|
return this.getUserInfo('fake-id');
|
||||||
};
|
};
|
||||||
|
|
||||||
getCurrentUserProfileImage() {
|
getCurrentUserProfileImage() {
|
||||||
return this.usersList[this.userNeeded].pictureId;
|
return Observable.of(this.usersList[this.userNeeded].pictureId);
|
||||||
};
|
};
|
||||||
|
|
||||||
respondWithTheUserWithoutImage() {
|
respondWithTheUserWithoutImage() {
|
||||||
this.userNeeded = 1;
|
this.userNeeded = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
respondWithTheUserWithImage() {
|
respondWithTheUserWithImage() {
|
||||||
this.userNeeded = 0;
|
this.userNeeded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
respondWithEditedUser() {
|
||||||
|
this.userNeeded = 2;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,132 @@
|
|||||||
|
/*!
|
||||||
|
* @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 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<EcmUserModel>;
|
||||||
|
public userNeeded = 0;
|
||||||
|
usersList = [fakeEcmUser, fakeEcmUserNoImage, fakeEcmEditedUser];
|
||||||
|
|
||||||
|
getUserInfo(userName: string) {
|
||||||
|
return this.lastPromise = Observable.of(this.usersList[this.userNeeded]);
|
||||||
|
};
|
||||||
|
|
||||||
|
getCurrentUserInfo() {
|
||||||
|
return this.getUserInfo('fake-id');
|
||||||
|
};
|
||||||
|
|
||||||
|
getUserProfileImage(avatarId: string) {
|
||||||
|
if (avatarId) {
|
||||||
|
return 'src/assets/ecmImg.gif';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
respondWithTheUserWithoutImage() {
|
||||||
|
this.userNeeded = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
respondWithTheUserWithImage() {
|
||||||
|
this.userNeeded = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
respondWithEditedUser() {
|
||||||
|
this.userNeeded = 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@@ -2,6 +2,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
border-radius: 90%;
|
border-radius: 90%;
|
||||||
width: 40px;
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
margin-right: 0%;
|
margin-right: 0%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border: 1px solid #999999;
|
border: 1px solid #999999;
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
|
|
||||||
.detail-user-profile-list-mdl{
|
.detail-user-profile-list-mdl{
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
padding: 0px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-profile-list-mdl{
|
.user-profile-list-mdl{
|
||||||
|
@@ -1,56 +1,58 @@
|
|||||||
<div id="img_container">
|
<div id="userinfo_container">
|
||||||
<span *ngIf="ecmUser">{{ecmUser.firstName || ecmUser.lastName}}</span>
|
<span id="ecm_username" *ngIf="ecmUser">{{ecmUser.firstName || ecmUser.lastName}}</span>
|
||||||
<span *ngIf="bpmUser && !ecmUser">
|
<span id="bpm_username" *ngIf="bpmUser && !ecmUser">
|
||||||
{{ formatValue(bpmUser.firstName) ||
|
{{ formatValue(bpmUser.firstName) ||
|
||||||
formatValue(bpmUser.lastName) ||
|
formatValue(bpmUser.lastName) ||
|
||||||
formatValue(bpmUser.fullName) }}
|
formatValue(bpmUser.fullname) }}
|
||||||
</span>
|
</span>
|
||||||
<div class="button-profile" id="user-profile" data-automation-id="user-profile">
|
<div *ngIf="ecmUser || bpmUser" class="button-profile" id="user-profile" data-automation-id="user-profile">
|
||||||
<img id="logged-user-img"
|
<img id="logged-user-img"
|
||||||
[src]="getUserAvatar()"
|
[src]="getUserAvatar()"
|
||||||
class="profile-image"/>
|
class="profile-image"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-profile-list-mdl
|
<div *ngIf="ecmUser || bpmUser" id="user-profile-lists" class="user-profile-list-mdl
|
||||||
mdl-menu mdl-menu--bottom-right
|
mdl-menu mdl-menu--bottom-right
|
||||||
mdl-js-menu mdl-js-ripple-effect"
|
mdl-js-menu mdl-js-ripple-effect"
|
||||||
for="user-profile">
|
for="user-profile">
|
||||||
<ul class='detail-user-profile-list-mdl mdl-list'>
|
<ul class='detail-user-profile-list-mdl mdl-list'>
|
||||||
<div *ngIf="ecmUser">
|
<div id="ecm-user-detail" *ngIf="ecmUser">
|
||||||
<hr class="title-start">
|
<hr class="title-start">
|
||||||
<span class="header-profile"><b>ECM</b></span>
|
<span id="ecm_title" class="header-profile"><b>ECM</b></span>
|
||||||
<li class="mdl-list__item mdl-list__item--two-line">
|
<li class="mdl-list__item mdl-list__item--two-line">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<i class="mdl-list__item-avatar">
|
<i class="mdl-list__item-avatar">
|
||||||
<img id="logged-user-img"
|
<img id="ecm-user-detail-image"
|
||||||
[src]="getEcmUserDetailAvatarUrl()"
|
[src]="getEcmUserAvatar()"
|
||||||
class="profile-image"/>
|
class="profile-image"/>
|
||||||
</i>
|
</i>
|
||||||
<span class="truncate-long-names">{{ecmUser.firstName}} {{ecmUser.lastName}}</span>
|
<span id="ecm-full-name" class="truncate-long-names">
|
||||||
<span class="mdl-list__item-sub-title">{{ecmUser.email}}</span>
|
{{ecmUser.firstName}} {{ecmUser.lastName}}
|
||||||
|
</span>
|
||||||
|
<span id="ecm-email" class="mdl-list__item-sub-title">{{ecmUser.email}}</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="mdl-list__item-secondary-content custom-role-style">
|
<span id="ecm-job-title" class="mdl-list__item-secondary-content custom-role-style">
|
||||||
<span class="role-label-user">Job Role</span>
|
<span class="role-label-user">Job Role</span>
|
||||||
{{ ecmUser.jobTitle ? ecmUser.jobTitle : 'N/A' }}
|
{{ ecmUser.jobTitle ? ecmUser.jobTitle : 'N/A' }}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
<br>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<div id="bpm-user-detail" *ngIf="bpmUser">
|
||||||
<div *ngIf="bpmUser">
|
|
||||||
<hr class="title-start">
|
<hr class="title-start">
|
||||||
<span class="header-profile"><b>BPM</b></span>
|
<span id="bpm_title" class="header-profile"><b>BPM</b></span>
|
||||||
<li class="mdl-list__item mdl-list__item--two-line">
|
<li class="mdl-list__item mdl-list__item--two-line">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<i class="mdl-list__item-avatar">
|
<i class="mdl-list__item-avatar">
|
||||||
<img id="logged-user-img"
|
<img id="bpm-user-detail-image"
|
||||||
[src]="getBpmUserDetailAvatarUrl()"
|
[src]="getBpmUserAvatar()"
|
||||||
class="profile-image"/>
|
class="profile-image"/>
|
||||||
</i>
|
</i>
|
||||||
<span class="truncate-long-names">
|
<span id="bpm-full-name" class="truncate-long-names">
|
||||||
{{formatValue(bpmUser.firstName) }} {{ formatValue(bpmUser.lastName) }}
|
{{ formatValue(bpmUser.firstName) }} {{ formatValue(bpmUser.lastName) }}
|
||||||
</span>
|
</span>
|
||||||
<span class="mdl-list__item-sub-title">{{bpmUser.email}}</span>
|
<span id="bpm-email" class="mdl-list__item-sub-title">{{bpmUser.email}}</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="mdl-list__item-secondary-content custom-role-style">
|
<span id="bpm-tenant" class="mdl-list__item-secondary-content custom-role-style">
|
||||||
<span class="role-label-user">Tenant</span>
|
<span class="role-label-user">Tenant</span>
|
||||||
{{bpmUser.tenantName}}
|
{{bpmUser.tenantName}}
|
||||||
</span>
|
</span>
|
||||||
|
@@ -18,231 +18,319 @@
|
|||||||
import { UserInfoComponent } from './user-info.component';
|
import { UserInfoComponent } from './user-info.component';
|
||||||
import { EcmUserService } from '../services/ecm-user.service';
|
import { EcmUserService } from '../services/ecm-user.service';
|
||||||
import { BpmUserService } from '../services/bpm-user.service';
|
import { BpmUserService } from '../services/bpm-user.service';
|
||||||
import { FakeEcmUserService } from '../testing/fake-ecm-user.service';
|
import { FakeEcmUserService } from '../assets/fake-ecm-user.service.mock';
|
||||||
import { FakeBpmUserService } from '../testing/fake-bpm-user.service';
|
import { fakeEcmEditedUser } from '../assets/fake-ecm-user.service.mock';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core';
|
import { FakeBpmUserService } from '../assets/fake-bpm-user.service.mock';
|
||||||
|
import { fakeBpmEditedUser } from '../assets/fake-bpm-user.service.mock';
|
||||||
|
import { AlfrescoContentService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
|
|
||||||
class StubAuthentication {
|
class StubSetting {
|
||||||
isEcmConnected: boolean;
|
provider: string;
|
||||||
isBpmConnected: boolean;
|
|
||||||
setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; };
|
setProviders(provider: string) {
|
||||||
setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; };
|
this.provider = provider;
|
||||||
isEcmLoggedIn() { return this.isEcmConnected; };
|
};
|
||||||
isBpmLoggedIn() { return this.isBpmConnected; };
|
|
||||||
|
getProviders() {
|
||||||
|
return this.provider;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class StubAlfrescoContentService {
|
class StubAlfrescoContentService {
|
||||||
getContentUrl() { return 'fake/url/image/for/ecm/user'; } ;
|
getContentUrl() {
|
||||||
|
return 'fake/url/image/for/ecm/user';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('User info component', () => {
|
describe('User info component', () => {
|
||||||
|
|
||||||
let userInfoComp: UserInfoComponent;
|
let userInfoComp: UserInfoComponent;
|
||||||
let fixture: ComponentFixture<UserInfoComponent>;
|
let fixture: ComponentFixture<UserInfoComponent>;
|
||||||
let authStub: StubAuthentication;
|
let stubSetting: StubSetting;
|
||||||
let fakeEcmService: FakeEcmUserService;
|
let fakeEcmService: FakeEcmUserService;
|
||||||
let fakeBpmService: FakeBpmUserService;
|
let fakeBpmService: FakeBpmUserService;
|
||||||
|
let element: HTMLElement;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ UserInfoComponent ],
|
declarations: [UserInfoComponent],
|
||||||
providers: [{ provide: EcmUserService, useClass: FakeEcmUserService},
|
providers: [{provide: EcmUserService, useClass: FakeEcmUserService},
|
||||||
{ provide: BpmUserService, useClass: FakeBpmUserService},
|
{provide: BpmUserService, useClass: FakeBpmUserService},
|
||||||
{ provide: AlfrescoAuthenticationService, useClass: StubAuthentication },
|
{provide: AlfrescoSettingsService, useClass: StubSetting},
|
||||||
{ provide: AlfrescoContentService, useClass: StubAlfrescoContentService }
|
{provide: AlfrescoContentService, useClass: StubAlfrescoContentService}
|
||||||
]
|
]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
fixture = TestBed.createComponent(UserInfoComponent);
|
fixture = TestBed.createComponent(UserInfoComponent);
|
||||||
userInfoComp = fixture.componentInstance;
|
userInfoComp = fixture.componentInstance;
|
||||||
});
|
element = fixture.nativeElement;
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should NOT have users before ngOnInit only anonymous image', () => {
|
it('should not show any image if the user is not logged in', () => {
|
||||||
expect(userInfoComp.ecmUser).toBeUndefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(element.querySelector('#logged-user-img')).toBeNull();
|
||||||
expect(userInfoComp.bpmUser).toBeUndefined();
|
|
||||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
|
||||||
expect(userInfoComp.anonymouseImageUrl).toBeDefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT have users immediately after ngOnInit', () => {
|
it('should NOT have users immediately after ngOnInit', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(userInfoComp.ecmUser).toBeUndefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(element.querySelector('#ecm_username')).toBeNull();
|
||||||
expect(userInfoComp.bpmUser).toBeUndefined();
|
expect(element.querySelector('#bpm_username')).toBeNull();
|
||||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
expect(element.querySelector('#user-profile-lists')).toBeNull();
|
||||||
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', () => {
|
describe('when user is logged on ecm', () => {
|
||||||
|
|
||||||
beforeEach( async(() => {
|
beforeEach(async(() => {
|
||||||
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
stubSetting = fixture.debugElement.injector.get(AlfrescoSettingsService);
|
||||||
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
||||||
|
|
||||||
authStub.setIsEcmLoggedIn(true);
|
stubSetting.setProviders('ECM');
|
||||||
fixture.detectChanges(); // runs ngOnInit -> getUsers
|
fixture.detectChanges();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
} );
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should get the ecm current user image from the service', () => {
|
it('should get the ecm current user image from the service', () => {
|
||||||
expect(userInfoComp.ecmUser).toBeDefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeDefined();
|
expect(element.querySelector('#logged-user-img')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toEqual('fake/url/image/for/ecm/user');
|
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get the ecm user informations from the service', () => {
|
it('should get the ecm user informations from the service', () => {
|
||||||
expect(userInfoComp.ecmUser).toBeDefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUser.firstName).toEqual('fake-first-name');
|
expect(element.querySelector('#ecm_username')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUser.lastName).toEqual('fake-last-name');
|
expect(element.querySelector('#ecm_title')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm-user-detail-image')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm-user-detail-image').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
|
||||||
|
expect(element.querySelector('#ecm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
|
||||||
|
expect(element.querySelector('#ecm-job-title').innerHTML).toContain('test job');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the anonynous user avatar image url when user does not have avatarId', async(() => {
|
it('should return the anonymous user avatar image url when user does not have avatarId', () => {
|
||||||
fakeEcmService.respondWithTheUserWithoutImage();
|
fakeEcmService.respondWithTheUserWithoutImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let res = userInfoComp.getEcmUserDetailAvatarUrl();
|
let res = userInfoComp.getEcmUserAvatar();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(res).toBeDefined();
|
||||||
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(element.querySelector('#logged-user-img').getAttribute('src'))
|
||||||
});
|
.toContain('src/img/anonymous.gif');
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show N/A when the job title is null', () => {
|
||||||
|
fakeEcmEditedUser.jobTitle = null;
|
||||||
|
fakeEcmService.respondWithEditedUser();
|
||||||
|
userInfoComp.ngOnInit();
|
||||||
|
fixture.whenStable()
|
||||||
|
.then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm-job-title')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm-job-title').innerHTML).toContain('N/A');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when user is logged on bpm', () => {
|
describe('when user is logged on bpm', () => {
|
||||||
|
|
||||||
beforeEach( async(() => {
|
beforeEach(async(() => {
|
||||||
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
stubSetting = fixture.debugElement.injector.get(AlfrescoSettingsService);
|
||||||
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
||||||
|
|
||||||
authStub.setIsBpmLoggedIn(true);
|
stubSetting.setProviders('BPM');
|
||||||
fixture.detectChanges(); // runs ngOnInit -> getUsers
|
fixture.detectChanges();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
} );
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should get the bpm current user image from the service', () => {
|
it('should get the bpm current user image from the service', () => {
|
||||||
expect(userInfoComp.bpmUser).toBeDefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(userInfoComp.bpmUserImage).toBeDefined();
|
expect(element.querySelector('#logged-user-img')).toBeDefined();
|
||||||
expect(userInfoComp.bpmUserImage).toEqual('fake-picture-id');
|
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show last name if first name is null', () => {
|
||||||
|
fakeBpmEditedUser.firstName = null;
|
||||||
|
fakeBpmService.respondWithEditedUser();
|
||||||
|
userInfoComp.ngOnInit();
|
||||||
|
fixture.whenStable()
|
||||||
|
.then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm_username')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm_username').innerHTML).toContain('fake-last-name');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show full name if first and last name are null', () => {
|
||||||
|
fakeBpmEditedUser.firstName = null;
|
||||||
|
fakeBpmEditedUser.lastName = null;
|
||||||
|
fakeBpmService.respondWithEditedUser();
|
||||||
|
userInfoComp.ngOnInit();
|
||||||
|
fixture.whenStable()
|
||||||
|
.then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm_username')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm_username').innerHTML).toContain('fake-full-name');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show first name if it is null string', () => {
|
||||||
|
fakeBpmEditedUser.firstName = 'null';
|
||||||
|
fakeBpmEditedUser.lastName = 'fake-last-name';
|
||||||
|
fakeBpmService.respondWithEditedUser();
|
||||||
|
userInfoComp.ngOnInit();
|
||||||
|
fixture.whenStable()
|
||||||
|
.then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm-full-name')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm-full-name').innerHTML).not.toContain('fake-first-name');
|
||||||
|
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-last-name');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show last name if it is null string', () => {
|
||||||
|
fakeBpmEditedUser.lastName = 'null';
|
||||||
|
fakeBpmEditedUser.firstName = 'fake-first-name';
|
||||||
|
fakeBpmService.respondWithEditedUser();
|
||||||
|
userInfoComp.ngOnInit();
|
||||||
|
fixture.whenStable()
|
||||||
|
.then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm-full-name')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-first-name');
|
||||||
|
expect(element.querySelector('#bpm-full-name').innerHTML).not.toContain('fake-last-name');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get the bpm user informations from the service', () => {
|
it('should get the bpm user informations from the service', () => {
|
||||||
expect(userInfoComp.bpmUser).toBeDefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(userInfoComp.bpmUser.firstName).toEqual('fake-first-name');
|
expect(element.querySelector('#bpm_username')).toBeDefined();
|
||||||
expect(userInfoComp.bpmUser.lastName).toEqual('fake-last-name');
|
expect(element.querySelector('#bpm_title')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm-user-detail-image')).toBeDefined();
|
||||||
|
expect(element.querySelector('#bpm-user-detail-image').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
|
||||||
|
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
|
||||||
|
expect(element.querySelector('#bpm-tenant').innerHTML).toContain('fake-tenant-name');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the anonynous user avatar image url when user does not have avatarId', async(() => {
|
it('should return the anonymous user avatar image url when user does not have avatarId', () => {
|
||||||
fakeBpmService.respondWithTheUserWithoutImage();
|
fakeBpmService.respondWithTheUserWithoutImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let res = userInfoComp.getBpmUserDetailAvatarUrl();
|
let res = userInfoComp.getBpmUserAvatar();
|
||||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
expect(res).toBeDefined();
|
||||||
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(element.querySelector('#logged-user-img').getAttribute('src'))
|
||||||
});
|
.toContain('src/img/anonymous.gif');
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when user is logged on bpm and ecm', () => {
|
describe('when user is logged on bpm and ecm', () => {
|
||||||
|
|
||||||
beforeEach( async(() => {
|
beforeEach(async(() => {
|
||||||
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
stubSetting = fixture.debugElement.injector.get(AlfrescoSettingsService);
|
||||||
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
||||||
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
||||||
|
|
||||||
authStub.setIsBpmLoggedIn(true);
|
stubSetting.setProviders('ALL');
|
||||||
authStub.setIsEcmLoggedIn(true);
|
fixture.detectChanges();
|
||||||
fixture.detectChanges(); // runs ngOnInit -> getUsers
|
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
} );
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should get the bpm current user image from the service', () => {
|
|
||||||
expect(userInfoComp.bpmUser).toBeDefined();
|
|
||||||
expect(userInfoComp.bpmUserImage).toBeDefined();
|
|
||||||
expect(userInfoComp.bpmUserImage).toEqual('fake-picture-id');
|
|
||||||
expect(userInfoComp.ecmUser).toBeDefined();
|
|
||||||
expect(userInfoComp.ecmUserImage).toBeDefined();
|
|
||||||
expect(userInfoComp.ecmUserImage).toEqual('fake/url/image/for/ecm/user');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should get the bpm user informations from the service', () => {
|
it('should get the bpm user informations from the service', () => {
|
||||||
expect(userInfoComp.bpmUser).toBeDefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(userInfoComp.bpmUser.firstName).toEqual('fake-first-name');
|
expect(element.querySelector('#bpm_username')).toBeDefined();
|
||||||
expect(userInfoComp.bpmUser.lastName).toEqual('fake-last-name');
|
expect(element.querySelector('#bpm_title')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUser).toBeDefined();
|
expect(element.querySelector('#bpm-user-detail-image')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUser.firstName).toEqual('fake-first-name');
|
expect(element.querySelector('#bpm-user-detail-image').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
|
||||||
expect(userInfoComp.ecmUser.lastName).toEqual('fake-last-name');
|
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
|
||||||
|
expect(element.querySelector('#bpm-tenant').innerHTML).toContain('fake-tenant-name');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the anonynous user avatar image url when user does not have avatarId', async(() => {
|
it('should get the ecm user informations from the service', () => {
|
||||||
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm_username')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm_title')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm-user-detail-image')).toBeDefined();
|
||||||
|
expect(element.querySelector('#ecm-user-detail-image').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
|
||||||
|
expect(element.querySelector('#ecm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
|
||||||
|
expect(element.querySelector('#ecm-job-title').innerHTML).toContain('test job');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the anonymous avatar when users do not have images', () => {
|
||||||
fakeBpmService.respondWithTheUserWithoutImage();
|
fakeBpmService.respondWithTheUserWithoutImage();
|
||||||
fakeEcmService.respondWithTheUserWithoutImage();
|
fakeEcmService.respondWithTheUserWithoutImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let resBpm = userInfoComp.getBpmUserDetailAvatarUrl();
|
let res = userInfoComp.getUserAvatar();
|
||||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
expect(res).toBeDefined();
|
||||||
expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
let resEcm = userInfoComp.getEcmUserDetailAvatarUrl();
|
expect(element.querySelector('#logged-user-img')).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(element.querySelector('#logged-user-img').getAttribute('src')).toContain('src/img/anonymous.gif');
|
||||||
expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl);
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should return the ecm image if exists', async(() => {
|
it('should show the ecm image if exists', () => {
|
||||||
fakeBpmService.respondWithTheUserWithImage();
|
fakeBpmService.respondWithTheUserWithImage();
|
||||||
fakeEcmService.respondWithTheUserWithImage();
|
fakeEcmService.respondWithTheUserWithImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let res = userInfoComp.getUserAvatar();
|
let res = userInfoComp.getUserAvatar();
|
||||||
expect(userInfoComp.bpmUserImage).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeDefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(res).toEqual(userInfoComp.ecmUserImage);
|
expect(element.querySelector('#logged-user-img')).toBeDefined();
|
||||||
});
|
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the bpm image if ecm does not have it', async(() => {
|
it('should show the bpm image if ecm does not have it', () => {
|
||||||
fakeBpmService.respondWithTheUserWithImage();
|
fakeBpmService.respondWithTheUserWithImage();
|
||||||
fakeEcmService.respondWithTheUserWithoutImage();
|
fakeEcmService.respondWithTheUserWithoutImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let res = userInfoComp.getUserAvatar();
|
let res = userInfoComp.getUserAvatar();
|
||||||
expect(userInfoComp.bpmUserImage).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(res).toEqual(userInfoComp.bpmUserImage);
|
expect(element.querySelector('#logged-user-img')).toBeDefined();
|
||||||
});
|
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
it('should return the anonynous avatar if no user has it', async(() => {
|
|
||||||
fakeBpmService.respondWithTheUserWithoutImage();
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -20,7 +20,7 @@ import { EcmUserModel } from './../models/ecm-user.model';
|
|||||||
import { BpmUserModel } from './../models/bpm-user.model';
|
import { BpmUserModel } from './../models/bpm-user.model';
|
||||||
import { EcmUserService } from './../services/ecm-user.service';
|
import { EcmUserService } from './../services/ecm-user.service';
|
||||||
import { BpmUserService } from './../services/bpm-user.service';
|
import { BpmUserService } from './../services/bpm-user.service';
|
||||||
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ng2-alfresco-userinfo',
|
selector: 'ng2-alfresco-userinfo',
|
||||||
@@ -35,58 +35,58 @@ export class UserInfoComponent implements OnInit {
|
|||||||
|
|
||||||
ecmUser: EcmUserModel;
|
ecmUser: EcmUserModel;
|
||||||
bpmUser: BpmUserModel;
|
bpmUser: BpmUserModel;
|
||||||
anonymouseImageUrl: string = this.baseComponentPath + 'img/anonymous.gif';
|
anonymousImageUrl: string = this.baseComponentPath + 'img/anonymous.gif';
|
||||||
bpmUserImage: any;
|
bpmUserImage: any;
|
||||||
ecmUserImage: any;
|
ecmUserImage: any;
|
||||||
|
|
||||||
constructor(private ecmUserService: EcmUserService,
|
constructor(private ecmUserService: EcmUserService,
|
||||||
private bpmUserService: BpmUserService,
|
private bpmUserService: BpmUserService,
|
||||||
public authService: AlfrescoAuthenticationService) {
|
public setting: AlfrescoSettingsService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if ( this.authService.isEcmLoggedIn() ) {
|
if (this.setting.getProviders() === 'ECM' ||
|
||||||
|
this.setting.getProviders() === 'ALL') {
|
||||||
this.ecmUserService.getCurrentUserInfo()
|
this.ecmUserService.getCurrentUserInfo()
|
||||||
.subscribe(
|
.subscribe((res) => {
|
||||||
(res) => {
|
this.ecmUser = <EcmUserModel> res;
|
||||||
this.ecmUser = <EcmUserModel> res;
|
this.getEcmAvatar();
|
||||||
this.getEcmUserProfileImage();
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if ( this.authService.isBpmLoggedIn() ) {
|
|
||||||
|
if (this.setting.getProviders() === 'BPM' ||
|
||||||
|
this.setting.getProviders() === 'ALL') {
|
||||||
this.bpmUserService.getCurrentUserInfo()
|
this.bpmUserService.getCurrentUserInfo()
|
||||||
|
.subscribe((res) => {
|
||||||
|
this.bpmUser = <BpmUserModel> res;
|
||||||
|
});
|
||||||
|
this.bpmUserService.getCurrentUserProfileImage()
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
this.bpmUser = <BpmUserModel> res;
|
this.bpmUserImage = res;
|
||||||
this.getBpmUserProfileImage();
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getBpmUserProfileImage() {
|
private getEcmAvatar() {
|
||||||
this.bpmUserImage = this.bpmUserService.getCurrentUserProfileImage();
|
this.ecmUserImage = this.ecmUserService.getUserProfileImage(this.ecmUser.avatarId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getEcmUserProfileImage() {
|
getUserAvatar() {
|
||||||
this.ecmUserImage = this.ecmUserService.getCurrentUserProfileImageUrl(this.ecmUser.avatarId);
|
return this.ecmUserImage || this.bpmUserImage || this.anonymousImageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserAvatar() {
|
getBpmUserAvatar() {
|
||||||
return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl;
|
return this.bpmUserImage || this.anonymousImageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBpmUserDetailAvatarUrl() {
|
getEcmUserAvatar() {
|
||||||
return this.bpmUserImage || this.anonymouseImageUrl;
|
return this.ecmUserImage || this.anonymousImageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getEcmUserDetailAvatarUrl() {
|
formatValue(value: string) {
|
||||||
return this.ecmUserImage || this.anonymouseImageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public formatValue(value: string) {
|
|
||||||
return value === 'null' ? null : value;
|
return value === 'null' ? null : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -15,132 +15,92 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
import { BpmUserService } from '../services/bpm-user.service';
|
import { BpmUserService } from '../services/bpm-user.service';
|
||||||
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
// import { BpmUserModel } from '../models/bpm-user.model';
|
||||||
import { TestBed, async, inject } from '@angular/core/testing';
|
import { AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { BpmUserModel } from '../models/bpm-user.model';
|
import { fakeBpmUser } from '../assets/fake-bpm-user.service.mock';
|
||||||
|
|
||||||
export var fakeBpmUser: BpmUserModel = {
|
declare let jasmine: any;
|
||||||
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); };
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('Bpm User service', () => {
|
describe('Bpm User service', () => {
|
||||||
|
|
||||||
beforeEach( async(() => {
|
let service, injector, authService;
|
||||||
TestBed.configureTestingModule({
|
|
||||||
providers: [ BpmUserService,
|
|
||||||
{ provide: AlfrescoAuthenticationService, useClass: StubAuthentication }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('can instantiate service when inject service',
|
beforeEach(() => {
|
||||||
inject([BpmUserService], (service: BpmUserService) => {
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
expect(service instanceof BpmUserService).toBe(true);
|
AlfrescoSettingsService,
|
||||||
}));
|
AlfrescoApiService,
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
BpmUserService
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('can instantiate service with authorization', inject([AlfrescoAuthenticationService],
|
beforeEach(() => {
|
||||||
(auth: AlfrescoAuthenticationService) => {
|
service = injector.get(BpmUserService);
|
||||||
expect(auth).not.toBeNull('authorization should be provided');
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
let service = new BpmUserService(auth);
|
jasmine.Ajax.install();
|
||||||
expect(service instanceof BpmUserService).toBe(true, 'new service should be ok');
|
});
|
||||||
}));
|
|
||||||
|
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', () => {
|
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) => {
|
it('should be able to retrieve current user info', (done) => {
|
||||||
spyOn(service, 'callApiGetProfile').and.returnValue(Promise.resolve(fakeBpmUser));
|
service.getCurrentUserInfo().subscribe(
|
||||||
service.getCurrentUserInfo().subscribe(
|
(user) => {
|
||||||
(user) => {
|
expect(user.fakeBpmUser).toBeDefined();
|
||||||
expect(user).toBeDefined();
|
expect(user.fakeBpmUser.firstName).toEqual('fake-first-name');
|
||||||
expect(user.firstName).toEqual('fake-first-name');
|
expect(user.fakeBpmUser.lastName).toEqual('fake-last-name');
|
||||||
expect(user.lastName).toEqual('fake-last-name');
|
expect(user.fakeBpmUser.email).toEqual('fakeBpm@fake.com');
|
||||||
expect(user.email).toEqual('fakeBpm@fake.com');
|
done();
|
||||||
done();
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should retrieve current logged user information via js api', () => {
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
spyOn(service, 'callApiGetProfile');
|
status: 200,
|
||||||
service.getCurrentUserInfo();
|
contentType: 'json',
|
||||||
expect(service.callApiGetProfile).toHaveBeenCalled();
|
responseText: {fakeBpmUser}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve avatar url for current user', (done) => {
|
it('should retrieve avatar url for current user', (done) => {
|
||||||
spyOn(service, 'callApiGetProfilePicture').and.returnValue(Promise.resolve('fake/img/path'));
|
spyOn(service, 'callGetProfilePictureApi').and.returnValue(Promise.resolve('fake/img/path'));
|
||||||
service.getCurrentUserProfileImage().subscribe(
|
service.getCurrentUserProfileImage().subscribe(
|
||||||
(path) => {
|
(path) => {
|
||||||
expect(path).toBeDefined();
|
expect(path).toBeDefined();
|
||||||
expect(path).toEqual('fake/img/path');
|
expect(path).toEqual('fake/img/path');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should not retrieve the user information', () => {
|
|
||||||
spyOn(service, 'callApiGetProfile');
|
|
||||||
service.getCurrentUserInfo();
|
|
||||||
expect(service.callApiGetProfile).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not retrieve the user avatar', () => {
|
it('should catch errors on call for profile', (done) => {
|
||||||
spyOn(service, 'callApiGetProfilePicture');
|
service.getCurrentUserInfo().subscribe(() => {
|
||||||
service.getCurrentUserInfo();
|
}, () => {
|
||||||
expect(service.callApiGetProfilePicture).not.toHaveBeenCalled();
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should catch errors on call for profile picture', (done) => {
|
||||||
|
service.getCurrentUserProfileImage().subscribe(() => {
|
||||||
|
}, () => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -37,42 +37,19 @@ export class BpmUserService {
|
|||||||
* @param userName - the user name
|
* @param userName - the user name
|
||||||
*/
|
*/
|
||||||
getCurrentUserInfo(): Observable<BpmUserModel> {
|
getCurrentUserInfo(): Observable<BpmUserModel> {
|
||||||
if ( this.authService.isBpmLoggedIn() ) {
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile())
|
||||||
return Observable.fromPromise(this.callApiGetProfile())
|
.map((data) => <BpmUserModel> data)
|
||||||
.map(
|
.catch(this.handleError);
|
||||||
(data) => <BpmUserModel> data
|
|
||||||
)
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentUserProfileImage(): any {
|
getCurrentUserProfileImage(): Observable<any> {
|
||||||
if ( this.authService.isBpmLoggedIn() ) {
|
return Observable.fromPromise(this.callGetProfilePictureApi())
|
||||||
return Observable.fromPromise(this.callApiGetProfilePicture())
|
.map((data) => data)
|
||||||
.map(
|
.catch(this.handleError);
|
||||||
(data) => data
|
|
||||||
)
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private callGetProfilePictureApi() {
|
||||||
* Call js api to get current user profile picture
|
return this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture();
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -15,165 +15,111 @@
|
|||||||
* limitations under the License.
|
* 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 { EcmUserService } from '../services/ecm-user.service';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core';
|
import { fakeEcmUser } from '../assets/fake-ecm-user.service.mock';
|
||||||
import { TestBed, async, inject } from '@angular/core/testing';
|
|
||||||
import { EcmUserModel } from '../models/ecm-user.model';
|
|
||||||
import { EcmCompanyModel } from '../models/ecm-company.model';
|
|
||||||
|
|
||||||
export var fakeEcmCompany: EcmCompanyModel = {
|
declare let jasmine: any;
|
||||||
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'; } ;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Ecm User service', () => {
|
describe('Ecm User service', () => {
|
||||||
|
|
||||||
beforeEach( async(() => {
|
let service, injector, authService, contentService;
|
||||||
TestBed.configureTestingModule({
|
|
||||||
providers: [ EcmUserService,
|
|
||||||
{ provide: AlfrescoAuthenticationService, useClass: StubAuthentication },
|
|
||||||
{ provide: AlfrescoContentService, useClass: StubAlfrescoContentService }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('can instantiate service when inject service',
|
beforeEach(() => {
|
||||||
inject([EcmUserService], (service: EcmUserService) => {
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
expect(service instanceof EcmUserService).toBe(true);
|
AlfrescoSettingsService,
|
||||||
}));
|
AlfrescoApiService,
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoContentService,
|
||||||
|
EcmUserService
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('can instantiate service with authorization', inject([AlfrescoAuthenticationService],
|
beforeEach(() => {
|
||||||
(auth: AlfrescoAuthenticationService) => {
|
service = injector.get(EcmUserService);
|
||||||
expect(auth).not.toBeNull('authorization should be provided');
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
let service = new EcmUserService(auth, null);
|
contentService = injector.get(AlfrescoContentService);
|
||||||
expect(service instanceof EcmUserService).toBe(true, 'new service should be ok');
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('can instantiate service with content service', inject([AlfrescoContentService],
|
it('can instantiate service with authorization', () => {
|
||||||
(content: AlfrescoContentService) => {
|
expect(authService).not.toBeNull('authorization should be provided');
|
||||||
expect(content).not.toBeNull('contentService should be provided');
|
let serviceAuth = new EcmUserService(authService, null);
|
||||||
let service = new EcmUserService(null, content);
|
|
||||||
expect(service instanceof EcmUserService).toBe(true, 'new service should be ok');
|
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', () => {
|
describe('when user is logged in', () => {
|
||||||
let service: EcmUserService;
|
|
||||||
let authServiceForTest: AlfrescoAuthenticationService;
|
|
||||||
let contentServiceForTest: AlfrescoContentService;
|
|
||||||
|
|
||||||
beforeEach(
|
beforeEach(() => {
|
||||||
inject(
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
||||||
[AlfrescoAuthenticationService, AlfrescoContentService],
|
jasmine.Ajax.install();
|
||||||
(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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve current logged user information', () => {
|
afterEach(() => {
|
||||||
spyOn(service, 'getUserInfo');
|
jasmine.Ajax.uninstall();
|
||||||
spyOn(service, 'callApiGetPersonInfo').and.callThrough();
|
});
|
||||||
service.getCurrentUserInfo();
|
|
||||||
expect(service.getUserInfo).toHaveBeenCalledWith('-me-');
|
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 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', () => {
|
it('should retrieve avatar url for current user', () => {
|
||||||
spyOn(contentServiceForTest, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user');
|
spyOn(contentService, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user');
|
||||||
let urlRs = service.getCurrentUserProfileImageUrl('fake-avatar-id');
|
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', () => {
|
it('should not call content service without avatar id', () => {
|
||||||
spyOn(contentServiceForTest, 'getContentUrl').and.callThrough();
|
spyOn(contentService, 'getContentUrl').and.callThrough();
|
||||||
let urlRs = service.getCurrentUserProfileImageUrl(undefined);
|
let urlRs = service.getUserProfileImage(undefined);
|
||||||
expect(urlRs).toBeUndefined();
|
|
||||||
expect(contentServiceForTest.getContentUrl).not.toHaveBeenCalled();
|
expect(urlRs).toBeUndefined();
|
||||||
|
expect(contentService.getContentUrl).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should build the body for the content service', () => {
|
it('should build the body for the content service', () => {
|
||||||
spyOn(contentServiceForTest, 'getContentUrl').and.callThrough();
|
spyOn(contentService, 'getContentUrl').and.callThrough();
|
||||||
let urlRs = service.getCurrentUserProfileImageUrl('fake-avatar-id');
|
let urlRs = service.getUserProfileImage('fake-avatar-id');
|
||||||
expect(urlRs).toBeDefined();
|
|
||||||
expect(contentServiceForTest.getContentUrl).toHaveBeenCalledWith( {entry: {id: 'fake-avatar-id'} });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when user is not logged in', () => {
|
expect(urlRs).toBeDefined();
|
||||||
let service: EcmUserService;
|
expect(contentService.getContentUrl).toHaveBeenCalledWith({entry: {id: 'fake-avatar-id'}});
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -30,35 +30,34 @@ import { EcmUserModel } from '../models/ecm-user.model';
|
|||||||
export class EcmUserService {
|
export class EcmUserService {
|
||||||
|
|
||||||
constructor(private authService: AlfrescoAuthenticationService,
|
constructor(private authService: AlfrescoAuthenticationService,
|
||||||
private contentService: AlfrescoContentService) {}
|
private contentService: AlfrescoContentService) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get User Information via ECM
|
* get User Information via ECM
|
||||||
* @param userName - the user name
|
* @param userName - the user name
|
||||||
*/
|
*/
|
||||||
getUserInfo(userName: string): Observable<EcmUserModel> {
|
getUserInfo(userName: string): Observable<EcmUserModel> {
|
||||||
if ( this.authService.isEcmLoggedIn() ) {
|
|
||||||
return Observable.fromPromise(this.callApiGetPersonInfo(userName))
|
return Observable.fromPromise(this.callApiGetPersonInfo(userName))
|
||||||
.map(
|
.map(
|
||||||
(data) => <EcmUserModel> data['entry']
|
(data) => <EcmUserModel> data['entry']
|
||||||
)
|
)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentUserInfo() {
|
getCurrentUserInfo() {
|
||||||
return this.getUserInfo('-me-');
|
return this.getUserInfo('-me-');
|
||||||
}
|
}
|
||||||
|
|
||||||
callApiGetPersonInfo(userName: string, opts?: any) {
|
private callApiGetPersonInfo(userName: string, opts?: any) {
|
||||||
return this.authService.getAlfrescoApi().core.peopleApi.getPerson(userName, opts);
|
return this.authService.getAlfrescoApi().core.peopleApi.getPerson(userName, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentUserProfileImageUrl(avatarId: string) {
|
getUserProfileImage(avatarId: string) {
|
||||||
if ( avatarId ) {
|
if (avatarId) {
|
||||||
let nodeObj = {entry: {id: avatarId}};
|
let nodeObj = {entry: {id: avatarId}};
|
||||||
return this.contentService.getContentUrl(nodeObj);
|
return this.contentService.getContentUrl(nodeObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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<EcmUserModel>;
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user