Skip to content

Commit 02bb7db

Browse files
committed
[CST-5729] Fix issue with undefined link type
1 parent d2dfd0b commit 02bb7db

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/app/bitstream-page/bitstream-download-page/bitstream-download-page.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class BitstreamDownloadPageComponent implements OnInit {
107107
let links = '';
108108

109109
signpostingLinks.forEach((link: SignpostingLink) => {
110+
links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}"` + (isNotEmpty(link.type) ? ` ; type="${link.type}" ` : ' ');
110111
links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}" ; type="${link.type}" `;
111112
});
112113

src/app/item-page/simple/item-page.component.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const mocklink = {
4949
const mocklink2 = {
5050
href: 'http://test2.org',
5151
rel: 'rel2',
52-
type: 'type2'
52+
type: undefined
5353
};
5454

5555
const mockSignpostingLinks: SignpostingLink[] = [mocklink, mocklink2];
@@ -176,13 +176,18 @@ describe('ItemPageComponent', () => {
176176

177177
// Check if linkHeadService.addTag() was called with the correct arguments
178178
expect(linkHeadService.addTag).toHaveBeenCalledTimes(mockSignpostingLinks.length);
179-
expect(linkHeadService.addTag).toHaveBeenCalledWith(mockSignpostingLinks[0] as LinkDefinition);
180-
expect(linkHeadService.addTag).toHaveBeenCalledWith(mockSignpostingLinks[1] as LinkDefinition);
179+
let expected: LinkDefinition = mockSignpostingLinks[0] as LinkDefinition;
180+
expect(linkHeadService.addTag).toHaveBeenCalledWith(expected);
181+
expected = {
182+
href: 'http://test2.org',
183+
rel: 'rel2'
184+
};
185+
expect(linkHeadService.addTag).toHaveBeenCalledWith(expected);
181186
});
182187

183188
it('should set Link header on the server', () => {
184189

185-
expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', '<http://test.org> ; rel="rel1" ; type="type1" , <http://test2.org> ; rel="rel2" ; type="type2" ');
190+
expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', '<http://test.org> ; rel="rel1" ; type="type1" , <http://test2.org> ; rel="rel2" ');
186191
});
187192

188193
});

src/app/item-page/simple/item-page.component.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ServerResponseService } from '../../core/services/server-response.servi
2020
import { SignpostingDataService } from '../../core/data/signposting-data.service';
2121
import { SignpostingLink } from '../../core/data/signposting-links.model';
2222
import { isNotEmpty } from '../../shared/empty.util';
23-
import { LinkHeadService } from '../../core/services/link-head.service';
23+
import { LinkDefinition, LinkHeadService } from '../../core/services/link-head.service';
2424

2525
/**
2626
* This component renders a simple item page.
@@ -111,12 +111,17 @@ export class ItemPageComponent implements OnInit, OnDestroy {
111111
this.signpostingLinks = signpostingLinks;
112112

113113
signpostingLinks.forEach((link: SignpostingLink) => {
114-
links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}" ; type="${link.type}" `;
115-
this.linkHeadService.addTag({
114+
links = links + (isNotEmpty(links) ? ', ' : '') + `<${link.href}> ; rel="${link.rel}"` + (isNotEmpty(link.type) ? ` ; type="${link.type}" ` : ' ');
115+
let tag: LinkDefinition = {
116116
href: link.href,
117-
type: link.type,
118117
rel: link.rel
119-
});
118+
};
119+
if (isNotEmpty(link.type)) {
120+
tag = Object.assign(tag, {
121+
type: link.type
122+
});
123+
}
124+
this.linkHeadService.addTag(tag);
120125
});
121126

122127
if (isPlatformServer(this.platformId)) {

0 commit comments

Comments
 (0)