mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
test refactoring
This commit is contained in:
parent
90332daa64
commit
c45b3878b7
@ -49,8 +49,6 @@ module.exports = function (config) {
|
|||||||
// 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},
|
||||||
{pattern: 'dist/**/*.js.map', included: false, watched: false}
|
{pattern: 'dist/**/*.js.map', included: false, watched: false}
|
||||||
// fake file path
|
|
||||||
{ pattern: '/base/dist/src/img/anonymous.gif', included: false, watched: true, served: true }
|
|
||||||
],
|
],
|
||||||
|
|
||||||
exclude: [
|
exclude: [
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
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 '../assets/fake-ecm-user.service';
|
import { FakeEcmUserService } from '../assets/fake-ecm-user.service.mock';
|
||||||
import { FakeBpmUserService } from '../assets/fake-bpm-user.service';
|
import { FakeBpmUserService } from '../assets/fake-bpm-user.service.mock';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core';
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
|
|
||||||
import { ReflectiveInjector } from '@angular/core';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
import { BpmUserService } from '../services/bpm-user.service';
|
import { BpmUserService } from '../services/bpm-user.service';
|
||||||
|
// import { BpmUserModel } from '../models/bpm-user.model';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { fakeBpmUser } from '../assets/fake-bpm-user.service';
|
import { fakeBpmUser } from '../assets/fake-bpm-user.service.mock';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
@ -38,9 +39,6 @@ describe('Bpm User service', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service = injector.get(BpmUserService);
|
service = injector.get(BpmUserService);
|
||||||
authService = injector.get(AlfrescoAuthenticationService);
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -61,20 +59,19 @@ describe('Bpm User service', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to retrieve current user info', (done) => {
|
it('should be able to retrieve current user info', (done) => {
|
||||||
spyOn(service, 'getCurrentUserProfileImage').and.callThrough();
|
|
||||||
service.getCurrentUserInfo().subscribe(
|
service.getCurrentUserInfo().subscribe(
|
||||||
(user) => {
|
(user) => {
|
||||||
expect(user).toBeDefined();
|
expect(user.fakeBpmUser).toBeDefined();
|
||||||
expect(user.firstName).toEqual('fake-first-name');
|
expect(user.fakeBpmUser.firstName).toEqual('fake-first-name');
|
||||||
expect(user.lastName).toEqual('fake-last-name');
|
expect(user.fakeBpmUser.lastName).toEqual('fake-last-name');
|
||||||
expect(user.email).toEqual('fakeBpm@fake.com');
|
expect(user.fakeBpmUser.email).toEqual('fakeBpm@fake.com');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
status: 200,
|
status: 200,
|
||||||
contentType: 'json',
|
contentType: 'json',
|
||||||
responseText: fakeBpmUser
|
responseText: { fakeBpmUser }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -85,6 +82,7 @@ describe('Bpm User service', () => {
|
|||||||
expect(path).toEqual('fake/img/path');
|
expect(path).toEqual('fake/img/path');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
status: 200,
|
status: 200,
|
||||||
contentType: 'json',
|
contentType: 'json',
|
||||||
@ -92,23 +90,16 @@ describe('Bpm User service', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
describe('when user is not logged in', () => {
|
|
||||||
|
|
||||||
|
describe('when user is not logged in', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not retrieve the user information', () => {
|
|
||||||
spyOn(service, 'callApiGetProfile');
|
|
||||||
service.getCurrentUserInfo();
|
|
||||||
expect(service.callApiGetProfile).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not retrieve the user avatar', () => {
|
it('should not retrieve the user avatar', () => {
|
||||||
spyOn(service, 'callApiGetProfilePicture');
|
spyOn(service, 'callGetProfilePictureApi');
|
||||||
service.getCurrentUserInfo();
|
service.getCurrentUserInfo();
|
||||||
expect(service.callApiGetProfilePicture).not.toHaveBeenCalled();
|
expect(service.callGetProfilePictureApi).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});*/
|
});
|
||||||
});
|
});
|
||||||
|
@ -38,7 +38,7 @@ export class BpmUserService {
|
|||||||
*/
|
*/
|
||||||
getCurrentUserInfo(): Observable<BpmUserModel> {
|
getCurrentUserInfo(): Observable<BpmUserModel> {
|
||||||
if ( this.authService.isBpmLoggedIn() ) {
|
if ( this.authService.isBpmLoggedIn() ) {
|
||||||
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture())
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile())
|
||||||
.map(
|
.map(
|
||||||
(data) => <BpmUserModel> data
|
(data) => <BpmUserModel> data
|
||||||
)
|
)
|
||||||
@ -48,7 +48,7 @@ export class BpmUserService {
|
|||||||
|
|
||||||
getCurrentUserProfileImage(): Observable<any> {
|
getCurrentUserProfileImage(): Observable<any> {
|
||||||
if ( this.authService.isBpmLoggedIn() ) {
|
if ( this.authService.isBpmLoggedIn() ) {
|
||||||
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile())
|
return Observable.fromPromise(this.callGetProfilePictureApi())
|
||||||
.map(
|
.map(
|
||||||
(data) => data
|
(data) => data
|
||||||
)
|
)
|
||||||
@ -56,6 +56,10 @@ export class BpmUserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callGetProfilePictureApi() {
|
||||||
|
return this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw the error
|
* Throw the error
|
||||||
* @param error
|
* @param error
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
AlfrescoContentService
|
AlfrescoContentService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
import { EcmUserService } from '../services/ecm-user.service';
|
import { EcmUserService } from '../services/ecm-user.service';
|
||||||
import { fakeEcmUser } from '../assets/fake-ecm-user.service';
|
import { fakeEcmUser } from '../assets/fake-ecm-user.service.mock';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
@ -88,6 +88,16 @@ describe('Ecm User service', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to log errors on call', (done) => {
|
||||||
|
service.getCurrentUserInfo().subscribe(() => {}, () => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 403
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should retrieve avatar url for current user', () => {
|
it('should retrieve avatar url for current user', () => {
|
||||||
spyOn(contentService, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user');
|
spyOn(contentService, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user');
|
||||||
let urlRs = service.getUserProfileImage('fake-avatar-id');
|
let urlRs = service.getUserProfileImage('fake-avatar-id');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user