1
0

[DURACOM-155]

This commit is contained in:
Alisa Ismailati
2023-06-13 18:41:11 +02:00
parent ff85422bb3
commit ec8470de06

View File

@@ -4,7 +4,7 @@ import { SharedModule } from '../../../shared/shared.module';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { CollectionDataService } from '../../../core/data/collection-data.service'; import { CollectionDataService } from '../../../core/data/collection-data.service';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { CollectionMetadataComponent } from './collection-metadata.component'; import { CollectionMetadataComponent } from './collection-metadata.component';
@@ -52,6 +52,11 @@ describe('CollectionMetadataComponent', () => {
setStaleByHrefSubstring: {} setStaleByHrefSubstring: {}
}); });
const routerMock = {
events: observableOf(new NavigationEnd(1, 'url', 'url')),
navigate: jasmine.createSpy('navigate'),
};
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule], imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
@@ -62,6 +67,7 @@ describe('CollectionMetadataComponent', () => {
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: createSuccessfulRemoteDataObject(collection) }) } } }, { provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: createSuccessfulRemoteDataObject(collection) }) } } },
{ provide: NotificationsService, useValue: notificationsService }, { provide: NotificationsService, useValue: notificationsService },
{ provide: RequestService, useValue: requestService }, { provide: RequestService, useValue: requestService },
{ provide: Router, useValue: routerMock}
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();
@@ -70,8 +76,11 @@ describe('CollectionMetadataComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(CollectionMetadataComponent); fixture = TestBed.createComponent(CollectionMetadataComponent);
comp = fixture.componentInstance; comp = fixture.componentInstance;
router = (comp as any).router;
itemTemplateService = (comp as any).itemTemplateService; itemTemplateService = (comp as any).itemTemplateService;
spyOn(comp, 'ngOnInit');
spyOn(comp, 'initTemplateItem');
routerMock.events = observableOf(new NavigationEnd(1, 'url', 'url'));
fixture.detectChanges(); fixture.detectChanges();
}); });
@@ -83,9 +92,8 @@ describe('CollectionMetadataComponent', () => {
describe('addItemTemplate', () => { describe('addItemTemplate', () => {
it('should navigate to the collection\'s itemtemplate page', () => { it('should navigate to the collection\'s itemtemplate page', () => {
spyOn(router, 'navigate');
comp.addItemTemplate(); comp.addItemTemplate();
expect(router.navigate).toHaveBeenCalledWith([getCollectionItemTemplateRoute(collection.uuid)]); expect(routerMock.navigate).toHaveBeenCalledWith([getCollectionItemTemplateRoute(collection.uuid)]);
}); });
}); });