Skip to content

Commit 488958c

Browse files
author
Kuno Vercammen
committed
113904: Added tests for null user handling
1 parent 26c234e commit 488958c

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

src/app/process-page/overview/process-overview.component.spec.ts

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ProcessOverviewComponent } from './process-overview.component';
22
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
33
import { VarDirective } from '../../shared/utils/var.directive';
4-
import { TranslateModule } from '@ngx-translate/core';
4+
import { TranslateModule, TranslateService } from '@ngx-translate/core';
55
import { RouterTestingModule } from '@angular/router/testing';
66
import { NO_ERRORS_SCHEMA } from '@angular/core';
77
import { ProcessDataService } from '../../core/data/processes/process-data.service';
@@ -33,6 +33,8 @@ describe('ProcessOverviewComponent', () => {
3333
let processBulkDeleteService;
3434
let modalService;
3535

36+
let translateServiceSpy: jasmine.SpyObj<TranslateService>;
37+
3638
const pipe = new DatePipe('en-US');
3739

3840
function init() {
@@ -42,24 +44,29 @@ describe('ProcessOverviewComponent', () => {
4244
scriptName: 'script-name',
4345
startTime: '2020-03-19 00:30:00',
4446
endTime: '2020-03-19 23:30:00',
45-
processStatus: ProcessStatus.COMPLETED
47+
processStatus: ProcessStatus.COMPLETED,
48+
userId: 'testid'
4649
}),
4750
Object.assign(new Process(), {
4851
processId: 2,
4952
scriptName: 'script-name',
5053
startTime: '2020-03-20 00:30:00',
5154
endTime: '2020-03-20 23:30:00',
52-
processStatus: ProcessStatus.FAILED
55+
processStatus: ProcessStatus.FAILED,
56+
userId: 'testid'
5357
}),
5458
Object.assign(new Process(), {
5559
processId: 3,
5660
scriptName: 'another-script-name',
5761
startTime: '2020-03-21 00:30:00',
5862
endTime: '2020-03-21 23:30:00',
59-
processStatus: ProcessStatus.RUNNING
63+
processStatus: ProcessStatus.RUNNING,
64+
userId: 'testid'
6065
})
6166
];
6267
ePerson = Object.assign(new EPerson(), {
68+
id: 'testid',
69+
uuid: 'testid',
6370
metadata: {
6471
'eperson.firstname': [
6572
{
@@ -110,6 +117,9 @@ describe('ProcessOverviewComponent', () => {
110117

111118
beforeEach(waitForAsync(() => {
112119
init();
120+
121+
translateServiceSpy = jasmine.createSpyObj('TranslateService', ['get']);
122+
113123
TestBed.configureTestingModule({
114124
declarations: [ProcessOverviewComponent, VarDirective],
115125
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
@@ -249,4 +259,43 @@ describe('ProcessOverviewComponent', () => {
249259
expect(component.setProcesses).toHaveBeenCalled();
250260
});
251261
});
262+
263+
describe('getEPersonName function', () => {
264+
it('should return unknown user when id is null', (done: DoneFn) => {
265+
const id = null;
266+
const expectedTranslation = 'process.overview.unknown.user';
267+
268+
translateServiceSpy.get(expectedTranslation);
269+
270+
component.getEpersonName(id).subscribe((result: string) => {
271+
expect(result).toBe(expectedTranslation);
272+
done();
273+
});
274+
expect(translateServiceSpy.get).toHaveBeenCalledWith('process.overview.unknown.user');
275+
});
276+
277+
it('should return unknown user when id is invalid', (done: DoneFn) => {
278+
const id = '';
279+
const expectedTranslation = 'process.overview.unknown.user';
280+
281+
translateServiceSpy.get(expectedTranslation);
282+
283+
component.getEpersonName(id).subscribe((result: string) => {
284+
expect(result).toBe(expectedTranslation);
285+
done();
286+
});
287+
expect(translateServiceSpy.get).toHaveBeenCalledWith('process.overview.unknown.user');
288+
});
289+
290+
it('should return EPerson name when id is correct', (done: DoneFn) => {
291+
const id = 'testid';
292+
const expectedName = 'John Doe';
293+
294+
component.getEpersonName(id).subscribe((result: string) => {
295+
expect(result).toEqual(expectedName);
296+
done();
297+
});
298+
expect(translateServiceSpy.get).not.toHaveBeenCalled();
299+
});
300+
});
252301
});

src/app/process-page/overview/process-overview.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnDestroy, OnInit } from '@angular/core';
2-
import { Observable, Subscription, from as observableFrom } from 'rxjs';
2+
import { Observable, Subscription } from 'rxjs';
33
import { RemoteData } from '../../core/data/remote-data';
44
import { PaginatedList } from '../../core/data/paginated-list.model';
55
import { Process } from '../processes/process.model';
@@ -90,7 +90,7 @@ export class ProcessOverviewComponent implements OnInit, OnDestroy {
9090
getFirstCompletedRemoteData(),
9191
switchMap((rd: RemoteData<EPerson>) => {
9292
if (rd.hasSucceeded) {
93-
return observableFrom([this.dsoNameService.getName(rd.payload)]);
93+
return [this.dsoNameService.getName(rd.payload)];
9494
} else {
9595
return this.translateService.get('process.overview.unknown.user');
9696
}

0 commit comments

Comments
 (0)