Merge pull request #1623 from atmire/Issue#1381-DSO-sub-route-titles-fix

Issue #1381 - DSO sub route titles fix
This commit is contained in:
Tim Donohue
2022-04-29 11:16:56 -05:00
committed by GitHub
2 changed files with 21 additions and 5 deletions

View File

@@ -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({

View File

@@ -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 {