11import { ProcessOverviewComponent } from './process-overview.component' ;
22import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
33import { VarDirective } from '../../shared/utils/var.directive' ;
4- import { TranslateModule } from '@ngx-translate/core' ;
4+ import { TranslateModule , TranslateService } from '@ngx-translate/core' ;
55import { RouterTestingModule } from '@angular/router/testing' ;
66import { NO_ERRORS_SCHEMA } from '@angular/core' ;
77import { 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} ) ;
0 commit comments