diff --git a/src/app/core/metadata/metadata.service.spec.ts b/src/app/core/metadata/metadata.service.spec.ts index 6114f13511..632816d90b 100644 --- a/src/app/core/metadata/metadata.service.spec.ts +++ b/src/app/core/metadata/metadata.service.spec.ts @@ -163,6 +163,22 @@ describe('MetadataService', () => { }); })); + it('route titles should overwrite dso titles', fakeAsync(() => { + (translateService.get as jasmine.Spy).and.returnValues(of('DSpace :: '), of('Translated Route Title')); + (metadataService as any).processRouteChange({ + data: { + value: { + dso: createSuccessfulRemoteDataObject(ItemMock), + title: 'route.title.key', + } + } + }); + tick(); + expect(title.setTitle).toHaveBeenCalledTimes(2); + expect((title.setTitle as jasmine.Spy).calls.argsFor(0)).toEqual(['Test PowerPoint Document']); + expect((title.setTitle as jasmine.Spy).calls.argsFor(1)).toEqual(['DSpace :: Translated Route Title']); + })); + it('other navigation should add title and description', fakeAsync(() => { (translateService.get as jasmine.Spy).and.returnValues(of('DSpace :: '), of('Dummy Title'), of('This is a dummy item component for testing!')); (metadataService as any).processRouteChange({ diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index 570f0f77ca..3a438edab0 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -109,6 +109,11 @@ export class MetadataService { private processRouteChange(routeInfo: any): void { this.clearMetaTags(); + if (hasValue(routeInfo.data.value.dso) && hasValue(routeInfo.data.value.dso.payload)) { + this.currentObject.next(routeInfo.data.value.dso.payload); + this.setDSOMetaTags(); + } + if (routeInfo.data.value.title) { const titlePrefix = this.translate.get('repository.title.prefix'); const title = this.translate.get(routeInfo.data.value.title, routeInfo.data.value); @@ -122,11 +127,6 @@ export class MetadataService { this.addMetaTag('description', translatedDescription); }); } - - if (hasValue(routeInfo.data.value.dso) && hasValue(routeInfo.data.value.dso.payload)) { - this.currentObject.next(routeInfo.data.value.dso.payload); - this.setDSOMetaTags(); - } } private getCurrentRoute(route: ActivatedRoute): ActivatedRoute {