@@ -56,11 +56,12 @@ describe('ProcessOverviewTableComponent', () => {
5656 let modalService : NgbModal ;
5757 let authService ; // : AuthService; Not typed as the mock does not fully implement AuthService
5858 let routeService : RouteService ;
59- let translateService : TranslateService ;
6059
6160 let processes : Process [ ] ;
6261 let ePerson : EPerson ;
6362
63+ let translateServiceSpy : jasmine . SpyObj < TranslateService > ;
64+
6465 function init ( ) {
6566 processes = [
6667 Object . assign ( new Process ( ) , {
@@ -69,23 +70,28 @@ describe('ProcessOverviewTableComponent', () => {
6970 startTime : '2020-03-19 00:30:00' ,
7071 endTime : '2020-03-19 23:30:00' ,
7172 processStatus : ProcessStatus . COMPLETED ,
73+ userId : 'testid' ,
7274 } ) ,
7375 Object . assign ( new Process ( ) , {
7476 processId : 2 ,
7577 scriptName : 'script-b' ,
7678 startTime : '2020-03-20 00:30:00' ,
7779 endTime : '2020-03-20 23:30:00' ,
7880 processStatus : ProcessStatus . FAILED ,
81+ userId : 'testid' ,
7982 } ) ,
8083 Object . assign ( new Process ( ) , {
8184 processId : 3 ,
8285 scriptName : 'script-c' ,
8386 startTime : '2020-03-21 00:30:00' ,
8487 endTime : '2020-03-21 23:30:00' ,
8588 processStatus : ProcessStatus . RUNNING ,
89+ userId : 'testid' ,
8690 } ) ,
8791 ] ;
8892 ePerson = Object . assign ( new EPerson ( ) , {
93+ id : 'testid' ,
94+ uuid : 'testid' ,
8995 metadata : {
9096 'eperson.firstname' : [
9197 {
@@ -144,6 +150,8 @@ describe('ProcessOverviewTableComponent', () => {
144150 beforeEach ( waitForAsync ( ( ) => {
145151 init ( ) ;
146152
153+ translateServiceSpy = jasmine . createSpyObj ( 'TranslateService' , [ 'get' ] ) ;
154+
147155 void TestBed . configureTestingModule ( {
148156 declarations : [ NgbCollapse ] ,
149157 imports : [ TranslateModule . forRoot ( ) , RouterTestingModule . withRoutes ( [ ] ) , VarDirective , ProcessOverviewTableComponent ] ,
@@ -228,50 +236,43 @@ describe('ProcessOverviewTableComponent', () => {
228236 } ) ;
229237
230238 } ) ;
231- /*
232- describe('getEPersonName', () => {
233- beforeEach(() => {
234- init();
235- translateService = getMockTranslateService();
236- });
237239
238- it('should return the name when the ID is valid', () => {
239- const id = 'valid_id';
240- const expectedName = 'John Doe';
240+ describe ( 'getEPersonName function' , ( ) => {
241+ it ( 'should return unknown user when id is null' , ( done : DoneFn ) => {
242+ const id = null ;
243+ const expectedTranslation = 'process.overview.unknown.user' ;
241244
242- spyOn(dsoNameService, 'getName').and.returnValue(expectedName );
245+ translateServiceSpy . get ( expectedTranslation ) ;
243246
244- component.getEPersonName(id).subscribe(name => {
245- expect(name).toEqual(expectedName);
247+ component . getEPersonName ( id ) . subscribe ( ( result : string ) => {
248+ expect ( result ) . toBe ( expectedTranslation ) ;
249+ done ( ) ;
246250 } ) ;
247-
248- expect(ePersonService.findById).toHaveBeenCalledWith(id);
251+ expect ( translateServiceSpy . get ) . toHaveBeenCalledWith ( 'process.overview.unknown.user' ) ;
249252 } ) ;
250253
251- fit('should return "Unknown" when the ID is invalid', () => {
252- const id = 'invalid_id';
253- const translationKey = 'unknown_user';
254- const expectedMessage = 'Unknown';
254+ it ( 'should return unknown user when id is invalid' , ( done : DoneFn ) => {
255+ const id = '' ;
256+ const expectedTranslation = 'process.overview.unknown.user' ;
255257
256- spyOn(translateService, 'get').and.returnValue(of(expectedMessage) );
258+ translateServiceSpy . get ( expectedTranslation ) ;
257259
258- component.getEPersonName(id).subscribe(name => {
259- expect(name).toEqual(expectedMessage);
260+ component . getEPersonName ( id ) . subscribe ( ( result : string ) => {
261+ expect ( result ) . toBe ( expectedTranslation ) ;
262+ done ( ) ;
260263 } ) ;
261-
262- expect(ePersonService.findById).toHaveBeenCalledWith(id);
263- expect(translateService.get).toHaveBeenCalledWith(translationKey);
264+ expect ( translateServiceSpy . get ) . toHaveBeenCalledWith ( 'process.overview.unknown.user' ) ;
264265 } ) ;
265266
266- it('should return an empty observable when the ID is null', () => {
267- const id = null;
267+ it ( 'should return EPerson name when id is correct' , ( done : DoneFn ) => {
268+ const id = 'testid' ;
269+ const expectedName = 'John Doe' ;
268270
269- component.getEPersonName(id).subscribe(name => {
270- expect(name).toBeUndefined();
271+ component . getEPersonName ( id ) . subscribe ( ( result : string ) => {
272+ expect ( result ) . toEqual ( expectedName ) ;
273+ done ( ) ;
271274 } ) ;
272-
273- expect(ePersonService.findById).not.toHaveBeenCalled();
275+ expect ( translateServiceSpy . get ) . not . toHaveBeenCalled ( ) ;
274276 } ) ;
275277 } ) ;
276- */
277278} ) ;
0 commit comments