diff --git a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts index c19f9c427d3..5e7194fbd56 100644 --- a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts +++ b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.spec.ts @@ -7,6 +7,7 @@ import { import { ActivatedRoute } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; import { of as observableOf } from 'rxjs'; +import { ServerResponseService } from 'src/app/core/services/server-response.service'; import { ActivatedRouteStub } from '../../shared/testing/active-router.stub'; import { ObjectNotFoundComponent } from './objectnotfound.component'; @@ -21,6 +22,10 @@ describe('ObjectNotFoundComponent', () => { const activatedRouteStub = Object.assign(new ActivatedRouteStub(), { params: observableOf({ id: testUUID, idType: uuidType }), }); + const serverResponseServiceStub = jasmine.createSpyObj('ServerResponseService', { + setNotFound: jasmine.createSpy('setNotFound'), + }); + const activatedRouteStubHandle = Object.assign(new ActivatedRouteStub(), { params: observableOf({ id: handleId, idType: handlePrefix }), }); @@ -31,6 +36,7 @@ describe('ObjectNotFoundComponent', () => { TranslateModule.forRoot(), ObjectNotFoundComponent, ], providers: [ + { provide: ServerResponseService, useValue: serverResponseServiceStub } , { provide: ActivatedRoute, useValue: activatedRouteStub }, ], schemas: [NO_ERRORS_SCHEMA], @@ -52,6 +58,10 @@ describe('ObjectNotFoundComponent', () => { expect(comp.idType).toEqual(uuidType); expect(comp.missingItem).toEqual('uuid: ' + testUUID); }); + + it('should call serverResponseService.setNotFound', () => { + expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled(); + }); }); describe( 'legacy handle request', () => { @@ -61,6 +71,7 @@ describe('ObjectNotFoundComponent', () => { TranslateModule.forRoot(), ObjectNotFoundComponent, ], providers: [ + { provide: ServerResponseService, useValue: serverResponseServiceStub }, { provide: ActivatedRoute, useValue: activatedRouteStubHandle }, ], schemas: [NO_ERRORS_SCHEMA], @@ -78,6 +89,10 @@ describe('ObjectNotFoundComponent', () => { expect(comp.idType).toEqual(handlePrefix); expect(comp.missingItem).toEqual('handle: ' + handlePrefix + '/' + handleId); }); + + it('should call serverResponseService.setNotFound', () => { + expect(serverResponseServiceStub.setNotFound).toHaveBeenCalled(); + }); }); }); diff --git a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts index cd54fa39b61..4e67f6e8bf4 100644 --- a/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts +++ b/src/app/lookup-by-id/objectnotfound/objectnotfound.component.ts @@ -9,6 +9,7 @@ import { RouterLink, } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; +import { ServerResponseService } from 'src/app/core/services/server-response.service'; /** * This component representing the `PageNotFound` DSpace page. @@ -35,7 +36,7 @@ export class ObjectNotFoundComponent implements OnInit { * @param {AuthService} authservice * @param {ServerResponseService} responseService */ - constructor(private route: ActivatedRoute) { + constructor(private route: ActivatedRoute, private serverResponseService: ServerResponseService) { route.params.subscribe((params) => { this.idType = params.idType; this.id = params.id; @@ -48,6 +49,7 @@ export class ObjectNotFoundComponent implements OnInit { } else { this.missingItem = 'handle: ' + this.idType + '/' + this.id; } + this.serverResponseService.setNotFound(); } }