Fix user info unit test (#4887)

* fix unit test user info component

* fix unit test user info component

* replace download call with spy

* fix karma conf
This commit is contained in:
Eugenio Romano
2019-07-01 11:35:27 +01:00
committed by GitHub
parent 43f08441cd
commit 028916e386
3 changed files with 46 additions and 23 deletions

View File

@@ -22,7 +22,7 @@ import { DownloadZipDialogComponent } from './download-zip.dialog';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
import { DownloadZipService } from '../services/download-zip.service';
import { of } from 'rxjs';
import { Observable } from 'rxjs/index';
describe('DownloadZipDialogComponent', () => {
@@ -40,17 +40,6 @@ describe('DownloadZipDialogComponent', () => {
]
};
const pendingDownloadEntry = {
entry: {
bytesAdded: 0,
filesAdded: 0,
id: '5bfb0907',
status: 'PENDING',
totalBytes: 0,
totalFiles: 0
}
};
setupTestBed({
imports: [CoreTestingModule],
providers: [
@@ -101,6 +90,13 @@ describe('DownloadZipDialogComponent', () => {
});
it('should call cancelDownload when CANCEL button is clicked', () => {
spyOn(downloadZipService, 'createDownload').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.complete();
});
});
fixture.detectChanges();
spyOn(component, 'cancelDownload');
@@ -111,12 +107,25 @@ describe('DownloadZipDialogComponent', () => {
});
it('should call createDownload when component is initialize', () => {
const createDownloadSpy = spyOn(downloadZipService, 'createDownload').and.returnValue(of(pendingDownloadEntry));
const createDownloadSpy = spyOn(downloadZipService, 'createDownload').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.complete();
});
});
fixture.detectChanges();
expect(createDownloadSpy).toHaveBeenCalled();
});
it('should close dialog when download is completed', () => {
spyOn(downloadZipService, 'createDownload').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.complete();
});
});
component.download('fakeUrl', 'fileName');
spyOn(component, 'cancelDownload');
fixture.detectChanges();
@@ -124,6 +133,13 @@ describe('DownloadZipDialogComponent', () => {
});
it('should close dialog when download is cancelled', () => {
spyOn(downloadZipService, 'createDownload').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.complete();
});
});
fixture.detectChanges();
component.download('url', 'filename');
spyOn(downloadZipService, 'cancelDownload');

View File

@@ -12,8 +12,10 @@ module.exports = function (config) {
{pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false},
// pdf-js
{pattern: 'node_modules/pdfjs-dist/build/pdf.js.map', included: false, watched: false},
{pattern: 'node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false},
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false, served: true},
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js.map', included: false, watched: false},
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.min.js', included: true, watched: false, served: true},
{pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false},
@@ -28,6 +30,7 @@ module.exports = function (config) {
{pattern: 'lib/core/i18n/**/en.json', included: false, served: true, watched: false},
{pattern: 'lib/core/**/*.ts', included: false, served: true, watched: false},
{pattern: 'lib/core/assets/**/*.svg', included: false, served: true, watched: false},
{pattern: 'lib/core/assets/**/*.png', included: false, served: true, watched: false},
{pattern: 'lib/config/app.config.json', included: false, served: true, watched: false},
{pattern: 'lib/core/viewer/assets/fake-test-file.pdf', included: false, served: true, watched: false},
{pattern: 'lib/core/viewer/assets/fake-test-file.txt', included: false, served: true, watched: false},
@@ -45,7 +48,10 @@ module.exports = function (config) {
'/pdf.worker.min.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.min.js',
'/pdf.worker.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.js',
'/fake-url-file.png' :'/base/lib/core/assets/images/logo.png',
'/alfresco-logo.svg' :'/base/lib/core/assets/images/alfresco-logo.svg',
'/assets/images/': '/base/lib/core/assets/images/',
'/assets/images/ecm-background.png': '/base/lib/core/assets/images/ecm-background.png',
'/assets/images/bpm-background.png': '/base/lib/core/assets/images/bpm-background.png',
'/content.bin': '/base/lib/core/viewer/assets/fake-test-file.pdf',
'/base/assets/' :'/base/lib/core/assets/',
'/assets/adf-core/i18n/en.json': '/base/lib/core/i18n/en.json',

View File

@@ -99,6 +99,9 @@ describe('User info component', () => {
bpmUserService = TestBed.get(BpmUserService);
contentService = TestBed.get(ContentService);
identityUserService = TestBed.get(IdentityUserService);
spyOn(bpmUserService, 'getCurrentUserProfileImage').and.returnValue('');
spyOn(contentService, 'getContentUrl').and.returnValue('alfresco-logo.svg');
}));
afterEach(() => {
@@ -203,7 +206,6 @@ describe('User info component', () => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
spyOn(authService, 'isLoggedIn').and.returnValue(true);
spyOn(ecmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeEcmUser));
spyOn(contentService, 'getContentUrl').and.returnValue('assets/images/ecmImg.gif');
fixture.detectChanges();
}));
@@ -217,7 +219,7 @@ describe('User info component', () => {
expect(element.querySelector('#userinfo_container')).not.toBeNull();
expect(loggedImage).not.toBeNull();
expect(loggedImage.properties.src).toContain('assets/images/ecmImg.gif');
expect(loggedImage.properties.src).toContain('alfresco-logo.svg');
});
}));
@@ -235,11 +237,11 @@ describe('User info component', () => {
});
expect(element.querySelector('#userinfo_container')).not.toBeNull();
expect(loggedImage).not.toBeNull();
expect(loggedImage.properties.src).toContain('assets/images/ecmImg.gif');
expect(loggedImage.properties.src).toContain('alfresco-logo.svg');
});
}));
it('should get the ecm user informations from the service', async(() => {
it('should get the ecm user information from the service', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
@@ -253,7 +255,7 @@ describe('User info component', () => {
expect(element.querySelector('#userinfo_container')).not.toBeNull();
expect(fixture.debugElement.query(By.css('#ecm-username'))).not.toBeNull();
expect(ecmImage).not.toBeNull();
expect(ecmImage.properties.src).toContain('assets/images/ecmImg.gif');
expect(ecmImage.properties.src).toContain('alfresco-logo.svg');
expect(ecmFullName.nativeElement.textContent).toContain('fake-ecm-first-name fake-ecm-last-name');
expect(ecmJobTitle.nativeElement.textContent).toContain('USER_PROFILE.LABELS.ECM.JOB_TITLE');
});
@@ -436,7 +438,6 @@ describe('User info component', () => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
spyOn(authService, 'isLoggedIn').and.returnValue(true);
spyOn(contentService, 'getContentUrl').and.returnValue('src/assets/images/ecmImg.gif');
ecmUserInfoSpy = spyOn(ecmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeEcmUser));
spyOn(bpmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeBpmUser));
@@ -468,7 +469,7 @@ describe('User info component', () => {
});
}));
it('should get the bpm user informations from the service', async(() => {
it('should get the bpm user information from the service', async(() => {
openUserInfo();
const bpmTab = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'))[1];
bpmTab.triggerEventHandler('click', null);
@@ -485,7 +486,7 @@ describe('User info component', () => {
});
}));
it('should get the ecm user informations from the service', async(() => {
it('should get the ecm user information from the service', async(() => {
openUserInfo();
const ecmUsername = fixture.debugElement.query(By.css('#ecm-username'));
const ecmImage = fixture.debugElement.query(By.css('#ecm-user-detail-image'));
@@ -495,7 +496,7 @@ describe('User info component', () => {
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(ecmUsername).not.toBeNull();
expect(ecmImage).not.toBeNull();
expect(ecmImage.properties.src).toContain('assets/images/ecmImg.gif');
expect(ecmImage.properties.src).toContain('alfresco-logo.svg');
expect(fixture.debugElement.query(By.css('#ecm-full-name')).nativeElement.textContent).toContain('fake-ecm-first-name fake-ecm-last-name');
expect(fixture.debugElement.query(By.css('#ecm-job-title')).nativeElement.textContent).toContain('job-ecm-test');
});
@@ -505,7 +506,7 @@ describe('User info component', () => {
openUserInfo();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/images/ecmImg.gif');
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('alfresco-logo.svg');
}));
it('should show the ecm initials if the ecm user has no image', async(() => {