@@ -2,7 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22import { TranslateLoader , TranslateModule } from '@ngx-translate/core' ;
33import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock' ;
44import { ItemDataService } from '../../core/data/item-data.service' ;
5- import { ChangeDetectionStrategy , NO_ERRORS_SCHEMA } from '@angular/core' ;
5+ import { ChangeDetectionStrategy , NO_ERRORS_SCHEMA , PLATFORM_ID } from '@angular/core' ;
66import { ItemPageComponent } from './item-page.component' ;
77import { ActivatedRoute , Router } from '@angular/router' ;
88import { ActivatedRouteStub } from '../../shared/testing/active-router.stub' ;
@@ -24,7 +24,8 @@ import { createPaginatedList } from '../../shared/testing/utils.test';
2424import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service' ;
2525import { ServerResponseService } from '../../core/services/server-response.service' ;
2626import { SignpostingDataService } from '../../core/data/signposting-data.service' ;
27- import { LinkHeadService } from '../../core/services/link-head.service' ;
27+ import { LinkDefinition , LinkHeadService } from '../../core/services/link-head.service' ;
28+ import { SignpostingLink } from '../../core/data/signposting-links.model' ;
2829
2930const mockItem : Item = Object . assign ( new Item ( ) , {
3031 bundles : createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ ] ) ) ,
@@ -41,16 +42,18 @@ const mockWithdrawnItem: Item = Object.assign(new Item(), {
4142
4243const mocklink = {
4344 href : 'http://test.org' ,
44- rel : 'test ' ,
45- type : 'test '
45+ rel : 'rel1 ' ,
46+ type : 'type1 '
4647} ;
4748
4849const mocklink2 = {
4950 href : 'http://test2.org' ,
50- rel : 'test ' ,
51- type : 'test '
51+ rel : 'rel2 ' ,
52+ type : 'type2 '
5253} ;
5354
55+ const mockSignpostingLinks : SignpostingLink [ ] = [ mocklink , mocklink2 ] ;
56+
5457describe ( 'ItemPageComponent' , ( ) => {
5558 let comp : ItemPageComponent ;
5659 let fixture : ComponentFixture < ItemPageComponent > ;
@@ -109,6 +112,7 @@ describe('ItemPageComponent', () => {
109112 { provide : ServerResponseService , useValue : serverResponseService } ,
110113 { provide : SignpostingDataService , useValue : signpostingDataService } ,
111114 { provide : LinkHeadService , useValue : linkHeadService } ,
115+ { provide : PLATFORM_ID , useValue : 'server' } ,
112116 ] ,
113117
114118 schemas : [ NO_ERRORS_SCHEMA ]
@@ -165,6 +169,22 @@ describe('ItemPageComponent', () => {
165169 expect ( linkHeadService . addTag ) . toHaveBeenCalledTimes ( 2 ) ;
166170 } ) ;
167171
172+
173+ it ( 'should add link tags correctly' , ( ) => {
174+
175+ expect ( comp . signpostingLinks ) . toEqual ( [ mocklink , mocklink2 ] ) ;
176+
177+ // Check if linkHeadService.addTag() was called with the correct arguments
178+ expect ( linkHeadService . addTag ) . toHaveBeenCalledTimes ( mockSignpostingLinks . length ) ;
179+ expect ( linkHeadService . addTag ) . toHaveBeenCalledWith ( mockSignpostingLinks [ 0 ] as LinkDefinition ) ;
180+ expect ( linkHeadService . addTag ) . toHaveBeenCalledWith ( mockSignpostingLinks [ 1 ] as LinkDefinition ) ;
181+ } ) ;
182+
183+ it ( 'should set Link header on the server' , ( ) => {
184+
185+ expect ( serverResponseService . setHeader ) . toHaveBeenCalledWith ( 'Link' , '<http://test.org> ; rel="rel1" ; type="type1" , <http://test2.org> ; rel="rel2" ; type="type2" ' ) ;
186+ } ) ;
187+
168188 } ) ;
169189 describe ( 'when the item is withdrawn and the user is not an admin' , ( ) => {
170190 beforeEach ( ( ) => {
0 commit comments