mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
fixed wrong tests
This commit is contained in:
parent
c45b3878b7
commit
cc6a685bc4
@ -24,16 +24,30 @@ import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfre
|
|||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
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', () => {
|
||||||
@ -45,17 +59,17 @@ describe('User info component', () => {
|
|||||||
let fakeBpmService: FakeBpmUserService;
|
let fakeBpmService: FakeBpmUserService;
|
||||||
|
|
||||||
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: AlfrescoAuthenticationService, useClass: StubAuthentication},
|
||||||
{ 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;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should NOT have users before ngOnInit only anonymous image', () => {
|
it('should NOT have users before ngOnInit only anonymous image', () => {
|
||||||
@ -75,18 +89,33 @@ 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(() => {
|
||||||
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
||||||
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
||||||
|
|
||||||
authStub.setIsEcmLoggedIn(true);
|
authStub.setIsEcmLoggedIn(true);
|
||||||
fixture.detectChanges(); // runs ngOnInit -> getUsers
|
fixture.detectChanges(); // runs ngOnInit -> getUsers
|
||||||
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', () => {
|
||||||
@ -105,27 +134,27 @@ describe('User info component', () => {
|
|||||||
fakeEcmService.respondWithTheUserWithoutImage();
|
fakeEcmService.respondWithTheUserWithoutImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let res = userInfoComp.getEcmUserAvatar();
|
let res = userInfoComp.getEcmUserAvatar();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
||||||
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when user is logged on bpm', () => {
|
describe('when user is logged on bpm', () => {
|
||||||
|
|
||||||
beforeEach( async(() => {
|
beforeEach(async(() => {
|
||||||
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
||||||
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
||||||
|
|
||||||
authStub.setIsBpmLoggedIn(true);
|
authStub.setIsBpmLoggedIn(true);
|
||||||
fixture.detectChanges(); // runs ngOnInit -> getUsers
|
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', () => {
|
it('should get the bpm current user image from the service', () => {
|
||||||
@ -144,18 +173,18 @@ describe('User info component', () => {
|
|||||||
fakeBpmService.respondWithTheUserWithoutImage();
|
fakeBpmService.respondWithTheUserWithoutImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let res = userInfoComp.getBpmUserAvatar();
|
let res = userInfoComp.getBpmUserAvatar();
|
||||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
||||||
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
|
||||||
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
|
||||||
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
|
||||||
@ -164,9 +193,9 @@ describe('User info component', () => {
|
|||||||
authStub.setIsEcmLoggedIn(true);
|
authStub.setIsEcmLoggedIn(true);
|
||||||
fixture.detectChanges(); // runs ngOnInit -> getUsers
|
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', () => {
|
it('should get the bpm current user image from the service', () => {
|
||||||
@ -192,15 +221,15 @@ describe('User info component', () => {
|
|||||||
fakeEcmService.respondWithTheUserWithoutImage();
|
fakeEcmService.respondWithTheUserWithoutImage();
|
||||||
userInfoComp.ngOnInit();
|
userInfoComp.ngOnInit();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then( () => {
|
.then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let resBpm = userInfoComp.getBpmUserAvatar();
|
let resBpm = userInfoComp.getBpmUserAvatar();
|
||||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
||||||
expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl);
|
||||||
let resEcm = userInfoComp.getEcmUserAvatar();
|
let resEcm = userInfoComp.getEcmUserAvatar();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
||||||
expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return the ecm image if exists', async(() => {
|
it('should return the ecm image if exists', async(() => {
|
||||||
@ -208,13 +237,13 @@ describe('User info component', () => {
|
|||||||
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(userInfoComp.bpmUserImage).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeDefined();
|
expect(userInfoComp.ecmUserImage).toBeDefined();
|
||||||
expect(res).toEqual(userInfoComp.ecmUserImage);
|
expect(res).toEqual(userInfoComp.ecmUserImage);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return the bpm image if ecm does not have it', async(() => {
|
it('should return the bpm image if ecm does not have it', async(() => {
|
||||||
@ -222,13 +251,13 @@ describe('User info component', () => {
|
|||||||
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(userInfoComp.bpmUserImage).toBeDefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
||||||
expect(res).toEqual(userInfoComp.bpmUserImage);
|
expect(res).toEqual(userInfoComp.bpmUserImage);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return the anonynous avatar if no user has it', async(() => {
|
it('should return the anonynous avatar if no user has it', async(() => {
|
||||||
@ -236,13 +265,13 @@ describe('User info component', () => {
|
|||||||
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).toBeUndefined();
|
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
||||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
||||||
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,22 +71,39 @@ describe('Bpm User service', () => {
|
|||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
status: 200,
|
status: 200,
|
||||||
contentType: 'json',
|
contentType: 'json',
|
||||||
responseText: { fakeBpmUser }
|
responseText: {fakeBpmUser}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -37,23 +37,23 @@ export class BpmUserService {
|
|||||||
* @param userName - the user name
|
* @param userName - the user name
|
||||||
*/
|
*/
|
||||||
getCurrentUserInfo(): Observable<BpmUserModel> {
|
getCurrentUserInfo(): Observable<BpmUserModel> {
|
||||||
if ( this.authService.isBpmLoggedIn() ) {
|
if (this.authService.isBpmLoggedIn()) {
|
||||||
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile())
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile())
|
||||||
.map(
|
.map(
|
||||||
(data) => <BpmUserModel> data
|
(data) => <BpmUserModel> data
|
||||||
)
|
)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentUserProfileImage(): Observable<any> {
|
getCurrentUserProfileImage(): Observable<any> {
|
||||||
if ( this.authService.isBpmLoggedIn() ) {
|
if (this.authService.isBpmLoggedIn()) {
|
||||||
return Observable.fromPromise(this.callGetProfilePictureApi())
|
return Observable.fromPromise(this.callGetProfilePictureApi())
|
||||||
.map(
|
.map(
|
||||||
(data) => data
|
(data) => data
|
||||||
)
|
)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callGetProfilePictureApi() {
|
callGetProfilePictureApi() {
|
||||||
|
@ -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();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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
|
||||||
@ -39,8 +40,8 @@ export class EcmUserService {
|
|||||||
getUserInfo(userName: string): Observable<EcmUserModel> {
|
getUserInfo(userName: string): Observable<EcmUserModel> {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,10 +54,10 @@ export class EcmUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getUserProfileImage(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user