diff --git a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts index 79070db9c7..03e346c5a9 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/assets/fake-ecm-user.service.mock.ts @@ -34,16 +34,16 @@ export let fakeEcmCompany: EcmCompanyModel = { export let fakeEcmUser = { id: 'fake-id', - firstName: 'fake-first-name', - lastName: 'fake-last-name', + firstName: 'fake-ecm-first-name', + lastName: 'fake-ecm-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', + company: null, + jobTitle: 'job-ecm-test', location: 'fake location', mobile: '000000000', telephone: '11111111', @@ -58,13 +58,13 @@ export let fakeEcmUserNoImage = { firstName: 'fake-first-name', lastName: 'fake-last-name', description: 'i am a fake user for test', - avatarId: undefined, + avatarId: null, email: 'fakeEcm@ecmUser.com', skypeId: 'fake-skype-id', googleId: 'fake-googleId-id', instantMessageId: 'fake-instantMessageId-id', - company: fakeEcmCompany, - jobTitle: 'test job', + company: null, + jobTitle: null, location: 'fake location', mobile: '000000000', telephone: '11111111', @@ -76,7 +76,7 @@ export let fakeEcmUserNoImage = { export let fakeEcmEditedUser = { id: 'fake-id', - firstName: 'fake-first-name', + firstName: null, lastName: 'fake-last-name', description: 'i am a fake user for test', avatarId: 'fake-avatar-id', @@ -84,7 +84,7 @@ export let fakeEcmEditedUser = { skypeId: 'fake-skype-id', googleId: 'fake-googleId-id', instantMessageId: 'fake-instantMessageId-id', - company: fakeEcmCompany, + company: null, jobTitle: 'test job', location: 'fake location', mobile: '000000000', diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts index af97ce373e..ce3c8ad328 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.spec.ts @@ -28,6 +28,7 @@ import { } from 'ng2-alfresco-core'; import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { BpmUserModel } from './../models/bpm-user.model'; +import { fakeEcmUser, fakeEcmEditedUser, fakeEcmUserNoImage } from '../assets/fake-ecm-user.service.mock'; declare let jasmine: any; @@ -65,11 +66,6 @@ describe('User info component', () => { }); })); - afterEach(() => { - fixture.destroy(); - TestBed.resetTestingModule(); - }); - it('should not show any image if the user is not logged in', () => { expect(element.querySelector('#userinfo_container')).toBeDefined(); expect(element.querySelector('#logged-user-img')).toBeNull(); @@ -97,9 +93,6 @@ describe('User info component', () => { beforeEach(() => { spyOn(stubAuthService, 'isEcmLoggedIn').and.returnValue(true); spyOn(stubAuthService, 'isLoggedIn').and.returnValue(true); - }); - - beforeEach(() => { jasmine.Ajax.install(); }); @@ -111,17 +104,8 @@ describe('User info component', () => { fixture.detectChanges(); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, - contentType: 'json', - responseText: { - 'entry': { - 'id': 'fake-id', - 'firstName': null, - 'lastName': 'fake-ecm-last-name', - 'description': 'i am a fake user for test', - 'avatarId': 'fake-avatar-id', - 'email': 'fakeEcm@ecmUser.com' - } - } + contentType: 'application/json', + responseText: JSON.stringify({ entry: fakeEcmEditedUser }) }); fixture.whenStable().then(() => { @@ -140,58 +124,43 @@ describe('User info component', () => { fixture.detectChanges(); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, - contentType: 'json', - responseText: { - 'entry': { - 'id': 'fake-id', - 'firstName': 'fake-ecm-first-name', - 'lastName': 'fake-ecm-last-name', - 'description': 'i am a fake user for test', - 'avatarId': 'fake-avatar-id', - 'email': 'fakeEcm@ecmUser.com' - } - } - }); - fixture.whenStable().then(() => { - fixture.detectChanges(); + contentType: 'application/json', + responseText: JSON.stringify({ entry: fakeEcmUser }) }); })); it('should get the ecm current user image from the service', async(() => { - expect(element.querySelector('#userinfo_container')).toBeDefined(); - expect(element.querySelector('#logged-user-img')).toBeDefined(); - expect(element.querySelector('#logged-user-img').getAttribute('src')).toContain('assets/images/ecmImg.gif'); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(element.querySelector('#userinfo_container')).toBeDefined(); + expect(element.querySelector('#logged-user-img')).toBeDefined(); + expect(element.querySelector('#logged-user-img').getAttribute('src')).toContain('assets/images/ecmImg.gif'); + }); })); - it('should get the ecm user informations from the service', async(() => { - 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')).toContain('assets/images/ecmImg.gif'); - expect(element.querySelector('#ecm-full-name').textContent).toContain('fake-ecm-first-name fake-ecm-last-name'); - expect(element.querySelector('#ecm-job-title').textContent).toContain('USER_PROFILE.LABELS.ECM.JOB_TITLE'); - })); + it('should get the ecm user informations from the service', () => { + fixture.whenStable().then(() => { + fixture.detectChanges(); + 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')).toContain('assets/images/ecmImg.gif'); + expect(element.querySelector('#ecm-full-name').textContent).toContain('fake-ecm-first-name fake-ecm-last-name'); + expect(element.querySelector('#ecm-job-title').textContent).toContain('USER_PROFILE.LABELS.ECM.JOB_TITLE'); + }); + }); }); describe('and has no image', () => { beforeEach(async(() => { userInfoComp.anonymousImageUrl = userInfoComp.anonymousImageUrl.replace('/base/dist', ''); - spyOn(stubContent, 'getContentUrl').and.returnValue('wrongImage.gif'); fixture.detectChanges(); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, - contentType: 'json', - responseText: { - 'entry': { - 'id': 'fake-id', - 'firstName': 'fake-first-name', - 'lastName': 'fake-last-name', - 'description': 'i am a fake user for test', - 'email': 'fakeEcm@ecmUser.com' - } - } + contentType: 'application/json', + responseText: JSON.stringify({ entry: fakeEcmUserNoImage }) }); })); @@ -306,26 +275,14 @@ describe('User info component', () => { spyOn(stubContent, 'getContentUrl').and.returnValue('src/assets/images/ecmImg.gif'); userInfoComp.anonymousImageUrl = userInfoComp.anonymousImageUrl.replace('/base/dist', ''); jasmine.Ajax.install(); - fakeBpmUser.firstName = 'fake-bpm-first-name'; - fakeBpmUser.lastName = 'fake-bpm-last-name'; })); beforeEach(async(() => { fixture.detectChanges(); jasmine.Ajax.requests.first().respondWith({ status: 200, - contentType: 'json', - responseText: { - 'entry': { - 'id': 'fake-id', - 'firstName': 'fake-ecm-first-name', - 'lastName': 'fake-ecm-last-name', - 'description': 'i am a fake user for test', - 'avatarId': 'fake-ecm-avatar-id', - 'email': 'fakeEcm@ecmUser.com', - 'jobTitle': 'job-ecm-test' - } - } + contentType: 'application/json', + responseText: JSON.stringify({ entry: fakeEcmUser }) }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts index d3641596b2..f615ef8642 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.spec.ts @@ -71,8 +71,8 @@ describe('EcmUserService', () => { service.getCurrentUserInfo().subscribe( (user) => { expect(user).toBeDefined(); - expect(user.firstName).toEqual('fake-first-name'); - expect(user.lastName).toEqual('fake-last-name'); + expect(user.firstName).toEqual('fake-ecm-first-name'); + expect(user.lastName).toEqual('fake-ecm-last-name'); expect(user.email).toEqual('fakeEcm@ecmUser.com'); done(); });