mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
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:
@@ -22,7 +22,7 @@ import { DownloadZipDialogComponent } from './download-zip.dialog';
|
|||||||
import { setupTestBed } from '../testing/setupTestBed';
|
import { setupTestBed } from '../testing/setupTestBed';
|
||||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||||
import { DownloadZipService } from '../services/download-zip.service';
|
import { DownloadZipService } from '../services/download-zip.service';
|
||||||
import { of } from 'rxjs';
|
import { Observable } from 'rxjs/index';
|
||||||
|
|
||||||
describe('DownloadZipDialogComponent', () => {
|
describe('DownloadZipDialogComponent', () => {
|
||||||
|
|
||||||
@@ -40,17 +40,6 @@ describe('DownloadZipDialogComponent', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const pendingDownloadEntry = {
|
|
||||||
entry: {
|
|
||||||
bytesAdded: 0,
|
|
||||||
filesAdded: 0,
|
|
||||||
id: '5bfb0907',
|
|
||||||
status: 'PENDING',
|
|
||||||
totalBytes: 0,
|
|
||||||
totalFiles: 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [CoreTestingModule],
|
imports: [CoreTestingModule],
|
||||||
providers: [
|
providers: [
|
||||||
@@ -101,6 +90,13 @@ describe('DownloadZipDialogComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call cancelDownload when CANCEL button is clicked', () => {
|
it('should call cancelDownload when CANCEL button is clicked', () => {
|
||||||
|
spyOn(downloadZipService, 'createDownload').and.callFake(() => {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.next();
|
||||||
|
observer.complete();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
spyOn(component, 'cancelDownload');
|
spyOn(component, 'cancelDownload');
|
||||||
|
|
||||||
@@ -111,12 +107,25 @@ describe('DownloadZipDialogComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call createDownload when component is initialize', () => {
|
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();
|
fixture.detectChanges();
|
||||||
expect(createDownloadSpy).toHaveBeenCalled();
|
expect(createDownloadSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close dialog when download is completed', () => {
|
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');
|
component.download('fakeUrl', 'fileName');
|
||||||
spyOn(component, 'cancelDownload');
|
spyOn(component, 'cancelDownload');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -124,6 +133,13 @@ describe('DownloadZipDialogComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should close dialog when download is cancelled', () => {
|
it('should close dialog when download is cancelled', () => {
|
||||||
|
spyOn(downloadZipService, 'createDownload').and.callFake(() => {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.next();
|
||||||
|
observer.complete();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.download('url', 'filename');
|
component.download('url', 'filename');
|
||||||
spyOn(downloadZipService, 'cancelDownload');
|
spyOn(downloadZipService, 'cancelDownload');
|
||||||
|
@@ -12,8 +12,10 @@ module.exports = function (config) {
|
|||||||
{pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false},
|
{pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false},
|
||||||
|
|
||||||
// pdf-js
|
// 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.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', 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/build/pdf.worker.min.js', included: true, watched: false, served: true},
|
||||||
{pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false},
|
{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/i18n/**/en.json', included: false, served: true, watched: false},
|
||||||
{pattern: 'lib/core/**/*.ts', 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/**/*.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/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.pdf', included: false, served: true, watched: false},
|
||||||
{pattern: 'lib/core/viewer/assets/fake-test-file.txt', 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.min.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.min.js',
|
||||||
'/pdf.worker.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.js',
|
'/pdf.worker.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.js',
|
||||||
'/fake-url-file.png' :'/base/lib/core/assets/images/logo.png',
|
'/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/': '/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',
|
'/content.bin': '/base/lib/core/viewer/assets/fake-test-file.pdf',
|
||||||
'/base/assets/' :'/base/lib/core/assets/',
|
'/base/assets/' :'/base/lib/core/assets/',
|
||||||
'/assets/adf-core/i18n/en.json': '/base/lib/core/i18n/en.json',
|
'/assets/adf-core/i18n/en.json': '/base/lib/core/i18n/en.json',
|
||||||
|
@@ -99,6 +99,9 @@ describe('User info component', () => {
|
|||||||
bpmUserService = TestBed.get(BpmUserService);
|
bpmUserService = TestBed.get(BpmUserService);
|
||||||
contentService = TestBed.get(ContentService);
|
contentService = TestBed.get(ContentService);
|
||||||
identityUserService = TestBed.get(IdentityUserService);
|
identityUserService = TestBed.get(IdentityUserService);
|
||||||
|
|
||||||
|
spyOn(bpmUserService, 'getCurrentUserProfileImage').and.returnValue('');
|
||||||
|
spyOn(contentService, 'getContentUrl').and.returnValue('alfresco-logo.svg');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -203,7 +206,6 @@ describe('User info component', () => {
|
|||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
||||||
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||||
spyOn(ecmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeEcmUser));
|
spyOn(ecmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeEcmUser));
|
||||||
spyOn(contentService, 'getContentUrl').and.returnValue('assets/images/ecmImg.gif');
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -217,7 +219,7 @@ describe('User info component', () => {
|
|||||||
|
|
||||||
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||||
expect(loggedImage).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(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||||
expect(loggedImage).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.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -253,7 +255,7 @@ describe('User info component', () => {
|
|||||||
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||||
expect(fixture.debugElement.query(By.css('#ecm-username'))).not.toBeNull();
|
expect(fixture.debugElement.query(By.css('#ecm-username'))).not.toBeNull();
|
||||||
expect(ecmImage).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(ecmFullName.nativeElement.textContent).toContain('fake-ecm-first-name fake-ecm-last-name');
|
||||||
expect(ecmJobTitle.nativeElement.textContent).toContain('USER_PROFILE.LABELS.ECM.JOB_TITLE');
|
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, 'isEcmLoggedIn').and.returnValue(true);
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
||||||
spyOn(authService, 'isLoggedIn').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));
|
ecmUserInfoSpy = spyOn(ecmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeEcmUser));
|
||||||
spyOn(bpmUserService, 'getCurrentUserInfo').and.returnValue(of(fakeBpmUser));
|
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();
|
openUserInfo();
|
||||||
const bpmTab = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'))[1];
|
const bpmTab = fixture.debugElement.queryAll(By.css('#tab-group-env .mat-tab-labels .mat-tab-label'))[1];
|
||||||
bpmTab.triggerEventHandler('click', null);
|
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();
|
openUserInfo();
|
||||||
const ecmUsername = fixture.debugElement.query(By.css('#ecm-username'));
|
const ecmUsername = fixture.debugElement.query(By.css('#ecm-username'));
|
||||||
const ecmImage = fixture.debugElement.query(By.css('#ecm-user-detail-image'));
|
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(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(ecmUsername).not.toBeNull();
|
expect(ecmUsername).not.toBeNull();
|
||||||
expect(ecmImage).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-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');
|
expect(fixture.debugElement.query(By.css('#ecm-job-title')).nativeElement.textContent).toContain('job-ecm-test');
|
||||||
});
|
});
|
||||||
@@ -505,7 +506,7 @@ describe('User info component', () => {
|
|||||||
openUserInfo();
|
openUserInfo();
|
||||||
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||||
expect(element.querySelector('#logged-user-img')).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(() => {
|
it('should show the ecm initials if the ecm user has no image', async(() => {
|
||||||
|
Reference in New Issue
Block a user