fixed wrong tests

This commit is contained in:
Vito Albano 2016-10-13 01:42:27 +01:00
parent c45b3878b7
commit cc6a685bc4
6 changed files with 145 additions and 97 deletions

View File

@ -26,14 +26,28 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing';
class StubAuthentication { class StubAuthentication {
isEcmConnected: boolean; isEcmConnected: boolean;
isBpmConnected: boolean; isBpmConnected: boolean;
setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; };
setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; }; setIsEcmLoggedIn(logged: boolean) {
isEcmLoggedIn() { return this.isEcmConnected; }; this.isEcmConnected = logged;
isBpmLoggedIn() { return this.isBpmConnected; }; };
setIsBpmLoggedIn(logged: boolean) {
this.isBpmConnected = logged;
};
isEcmLoggedIn() {
return this.isEcmConnected;
};
isBpmLoggedIn() {
return this.isBpmConnected;
};
} }
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', () => {
@ -75,6 +89,21 @@ describe('User info component', () => {
expect(userInfoComp.anonymouseImageUrl).toBeDefined(); 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(() => {

View File

@ -51,7 +51,7 @@ export class UserInfoComponent implements OnInit {
.subscribe( .subscribe(
(res) => { (res) => {
this.ecmUser = <EcmUserModel> res; this.ecmUser = <EcmUserModel> 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); this.ecmUserImage = this.ecmUserService.getUserProfileImage(this.ecmUser.avatarId);
} }
public getUserAvatar() { getUserAvatar() {
return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl; return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl;
} }
public getBpmUserAvatar() { getBpmUserAvatar() {
return this.bpmUserImage || this.anonymouseImageUrl; return this.bpmUserImage || this.anonymouseImageUrl;
} }
public getEcmUserAvatar() { getEcmUserAvatar() {
return this.ecmUserImage || this.anonymouseImageUrl; return this.ecmUserImage || this.anonymouseImageUrl;
} }
public formatValue(value: string) { formatValue(value: string) {
return value === 'null' ? null : value; return value === 'null' ? null : value;
} }

View File

@ -76,17 +76,34 @@ describe('Bpm User service', () => {
}); });
it('should retrieve avatar url for current user', (done) => { it('should retrieve avatar url for current user', (done) => {
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();
}); });
});
it('should be able to log errors on call for profile', (done) => {
service.getCurrentUserInfo().subscribe(() => {
}, () => {
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 403
contentType: 'json', });
responseText: 'fake/img/path' });
it('should be able to log errors on call for profile picture', (done) => {
service.getCurrentUserProfileImage().subscribe(() => {
}, () => {
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
}); });
}); });
}); });

View File

@ -89,7 +89,8 @@ describe('Ecm User service', () => {
}); });
it('should be able to log errors on call', (done) => { it('should be able to log errors on call', (done) => {
service.getCurrentUserInfo().subscribe(() => {}, () => { service.getCurrentUserInfo().subscribe(() => {
}, () => {
done(); done();
}); });

View File

@ -30,7 +30,8 @@ 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