@@ -4,7 +4,7 @@ import { SharedModule } from '../../../shared/shared.module';
44import { CommonModule } from '@angular/common' ;
55import { RouterTestingModule } from '@angular/router/testing' ;
66import { CollectionDataService } from '../../../core/data/collection-data.service' ;
7- import { ActivatedRoute , Router } from '@angular/router' ;
7+ import { ActivatedRoute , NavigationEnd , Router } from '@angular/router' ;
88import { of as observableOf } from 'rxjs' ;
99import { NO_ERRORS_SCHEMA } from '@angular/core' ;
1010import { CollectionMetadataComponent } from './collection-metadata.component' ;
@@ -52,6 +52,11 @@ describe('CollectionMetadataComponent', () => {
5252 setStaleByHrefSubstring : { }
5353 } ) ;
5454
55+ const routerMock = {
56+ events : observableOf ( new NavigationEnd ( 1 , 'url' , 'url' ) ) ,
57+ navigate : jasmine . createSpy ( 'navigate' ) ,
58+ } ;
59+
5560 beforeEach ( waitForAsync ( ( ) => {
5661 TestBed . configureTestingModule ( {
5762 imports : [ TranslateModule . forRoot ( ) , SharedModule , CommonModule , RouterTestingModule ] ,
@@ -62,6 +67,7 @@ describe('CollectionMetadataComponent', () => {
6267 { provide : ActivatedRoute , useValue : { parent : { data : observableOf ( { dso : createSuccessfulRemoteDataObject ( collection ) } ) } } } ,
6368 { provide : NotificationsService , useValue : notificationsService } ,
6469 { provide : RequestService , useValue : requestService } ,
70+ { provide : Router , useValue : routerMock }
6571 ] ,
6672 schemas : [ NO_ERRORS_SCHEMA ]
6773 } ) . compileComponents ( ) ;
@@ -70,8 +76,11 @@ describe('CollectionMetadataComponent', () => {
7076 beforeEach ( ( ) => {
7177 fixture = TestBed . createComponent ( CollectionMetadataComponent ) ;
7278 comp = fixture . componentInstance ;
73- router = ( comp as any ) . router ;
7479 itemTemplateService = ( comp as any ) . itemTemplateService ;
80+ spyOn ( comp , 'ngOnInit' ) ;
81+ spyOn ( comp , 'initTemplateItem' ) ;
82+
83+ routerMock . events = observableOf ( new NavigationEnd ( 1 , 'url' , 'url' ) ) ;
7584 fixture . detectChanges ( ) ;
7685 } ) ;
7786
@@ -83,9 +92,8 @@ describe('CollectionMetadataComponent', () => {
8392
8493 describe ( 'addItemTemplate' , ( ) => {
8594 it ( 'should navigate to the collection\'s itemtemplate page' , ( ) => {
86- spyOn ( router , 'navigate' ) ;
8795 comp . addItemTemplate ( ) ;
88- expect ( router . navigate ) . toHaveBeenCalledWith ( [ getCollectionItemTemplateRoute ( collection . uuid ) ] ) ;
96+ expect ( routerMock . navigate ) . toHaveBeenCalledWith ( [ getCollectionItemTemplateRoute ( collection . uuid ) ] ) ;
8997 } ) ;
9098 } ) ;
9199
0 commit comments