From 02bb7db1190c54be1f2a00608c624fdf67804f23 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 8 Jun 2023 13:15:02 +0200 Subject: [PATCH] [CST-5729] Fix issue with undefined link type --- .../bitstream-download-page.component.ts | 1 + .../item-page/simple/item-page.component.spec.ts | 13 +++++++++---- src/app/item-page/simple/item-page.component.ts | 15 ++++++++++----- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/app/bitstream-page/bitstream-download-page/bitstream-download-page.component.ts b/src/app/bitstream-page/bitstream-download-page/bitstream-download-page.component.ts index 4d05511ca0..cf8d8e7767 100644 --- a/src/app/bitstream-page/bitstream-download-page/bitstream-download-page.component.ts +++ b/src/app/bitstream-page/bitstream-download-page/bitstream-download-page.component.ts @@ -107,6 +107,7 @@ export class BitstreamDownloadPageComponent implements OnInit { let links = ''; signpostingLinks.forEach((link: SignpostingLink) => { + links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}"` + (isNotEmpty(link.type) ? ` ; type="${link.type}" ` : ' '); links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}" ; type="${link.type}" `; }); diff --git a/src/app/item-page/simple/item-page.component.spec.ts b/src/app/item-page/simple/item-page.component.spec.ts index dfba4bd235..b3202108f4 100644 --- a/src/app/item-page/simple/item-page.component.spec.ts +++ b/src/app/item-page/simple/item-page.component.spec.ts @@ -49,7 +49,7 @@ const mocklink = { const mocklink2 = { href: 'http://test2.org', rel: 'rel2', - type: 'type2' + type: undefined }; const mockSignpostingLinks: SignpostingLink[] = [mocklink, mocklink2]; @@ -176,13 +176,18 @@ describe('ItemPageComponent', () => { // Check if linkHeadService.addTag() was called with the correct arguments expect(linkHeadService.addTag).toHaveBeenCalledTimes(mockSignpostingLinks.length); - expect(linkHeadService.addTag).toHaveBeenCalledWith(mockSignpostingLinks[0] as LinkDefinition); - expect(linkHeadService.addTag).toHaveBeenCalledWith(mockSignpostingLinks[1] as LinkDefinition); + let expected: LinkDefinition = mockSignpostingLinks[0] as LinkDefinition; + expect(linkHeadService.addTag).toHaveBeenCalledWith(expected); + expected = { + href: 'http://test2.org', + rel: 'rel2' + }; + expect(linkHeadService.addTag).toHaveBeenCalledWith(expected); }); it('should set Link header on the server', () => { - expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', ' ; rel="rel1" ; type="type1" , ; rel="rel2" ; type="type2" '); + expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', ' ; rel="rel1" ; type="type1" , ; rel="rel2" '); }); }); diff --git a/src/app/item-page/simple/item-page.component.ts b/src/app/item-page/simple/item-page.component.ts index a11cb22883..b9be6bebfb 100644 --- a/src/app/item-page/simple/item-page.component.ts +++ b/src/app/item-page/simple/item-page.component.ts @@ -20,7 +20,7 @@ import { ServerResponseService } from '../../core/services/server-response.servi import { SignpostingDataService } from '../../core/data/signposting-data.service'; import { SignpostingLink } from '../../core/data/signposting-links.model'; import { isNotEmpty } from '../../shared/empty.util'; -import { LinkHeadService } from '../../core/services/link-head.service'; +import { LinkDefinition, LinkHeadService } from '../../core/services/link-head.service'; /** * This component renders a simple item page. @@ -111,12 +111,17 @@ export class ItemPageComponent implements OnInit, OnDestroy { this.signpostingLinks = signpostingLinks; signpostingLinks.forEach((link: SignpostingLink) => { - links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}" ; type="${link.type}" `; - this.linkHeadService.addTag({ + links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}"` + (isNotEmpty(link.type) ? ` ; type="${link.type}" ` : ' '); + let tag: LinkDefinition = { href: link.href, - type: link.type, rel: link.rel - }); + }; + if (isNotEmpty(link.type)) { + tag = Object.assign(tag, { + type: link.type + }); + } + this.linkHeadService.addTag(tag); }); if (isPlatformServer(this.platformId)) {