Merge branch 'w2p-90951_Fix-Issue#1381-DSO-sub-route-titles-contribute-7.0' into w2p-90951_Fix-Issue#1381-DSO-sub-route-titles-contribute-7.2

This commit is contained in:
Kristof De Langhe
2022-04-26 13:10:01 +02:00
2 changed files with 21 additions and 5 deletions

View File

@@ -157,6 +157,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(() => { 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!')); (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({ (metadataService as any).processRouteChange({

View File

@@ -103,6 +103,11 @@ export class MetadataService {
private processRouteChange(routeInfo: any): void { private processRouteChange(routeInfo: any): void {
this.clearMetaTags(); 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) { if (routeInfo.data.value.title) {
const titlePrefix = this.translate.get('repository.title.prefix'); const titlePrefix = this.translate.get('repository.title.prefix');
const title = this.translate.get(routeInfo.data.value.title, routeInfo.data.value); const title = this.translate.get(routeInfo.data.value.title, routeInfo.data.value);
@@ -116,11 +121,6 @@ export class MetadataService {
this.addMetaTag('description', translatedDescription); 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 { private getCurrentRoute(route: ActivatedRoute): ActivatedRoute {