@@ -6,9 +6,12 @@ import {
66} from '@angular/core/testing' ;
77import { By } from '@angular/platform-browser' ;
88import { TranslateModule } from '@ngx-translate/core' ;
9+ import { LinkService } from 'src/app/core/cache/builders/link.service' ;
10+ import { getMockLinkService } from 'src/app/shared/mocks/link-service.mock' ;
11+ import { followLink } from 'src/app/shared/utils/follow-link-config.model' ;
12+ import { APP_DATA_SERVICES_MAP } from 'src/config/app-config.interface' ;
913import { environment } from 'src/environments/environment' ;
1014
11- import { AccessStatusDataService } from '../../../../../core/data/access-status-data.service' ;
1215import { Bitstream } from '../../../../../core/shared/bitstream.model' ;
1316import { Item } from '../../../../../core/shared/item.model' ;
1417import { createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils' ;
@@ -26,7 +29,7 @@ describe('ItemAccessStatusBadgeComponent', () => {
2629 let embargoStatus : AccessStatusObject ;
2730 let restrictedStatus : AccessStatusObject ;
2831
29- let accessStatusDataService : AccessStatusDataService ;
32+ let linkService ;
3033
3134 let item : Item ;
3235 let bitstream : Bitstream ;
@@ -53,9 +56,7 @@ describe('ItemAccessStatusBadgeComponent', () => {
5356 status : 'restricted' ,
5457 } ) ;
5558
56- accessStatusDataService = jasmine . createSpyObj ( 'accessStatusDataService' , {
57- findItemAccessStatusFor : createSuccessfulRemoteDataObject$ ( unknownStatus ) ,
58- } ) ;
59+ linkService = getMockLinkService ( ) ;
5960
6061 item = Object . assign ( new Item ( ) , {
6162 uuid : 'item-uuid' ,
@@ -73,7 +74,8 @@ describe('ItemAccessStatusBadgeComponent', () => {
7374 imports : [ TranslateModule . forRoot ( ) , AccessStatusBadgeComponent , TruncatePipe ] ,
7475 schemas : [ NO_ERRORS_SCHEMA ] ,
7576 providers : [
76- { provide : AccessStatusDataService , useValue : accessStatusDataService } ,
77+ { provide : LinkService , useValue : linkService } ,
78+ { provide : APP_DATA_SERVICES_MAP , useValue : { } } ,
7779 ] ,
7880 } ) . compileComponents ( ) ;
7981 }
@@ -111,36 +113,57 @@ describe('ItemAccessStatusBadgeComponent', () => {
111113 expect ( badge . nativeElement . textContent ) . toEqual ( `` ) ;
112114 }
113115
114- describe ( 'init with Item ' , ( ) => {
116+ describe ( 'init with item ' , ( ) => {
115117 beforeEach ( waitForAsync ( ( ) => {
116118 init ( ) ;
117119 initTestBed ( ) ;
118120 } ) ) ;
119121 beforeEach ( ( ) => {
122+ item . accessStatus = createSuccessfulRemoteDataObject$ ( unknownStatus ) ;
120123 initFixtureAndComponentWithItem ( ) ;
121124 } ) ;
122125 it ( 'should init the component' , ( ) => {
123126 expect ( component ) . toBeTruthy ( ) ;
124127 } ) ;
125128 } ) ;
126129
127- describe ( 'When the findItemAccessStatusFor method returns unknown with Item ' , ( ) => {
130+ describe ( 'When the item have no accessStatus link ' , ( ) => {
128131 beforeEach ( waitForAsync ( ( ) => {
129132 init ( ) ;
130133 initTestBed ( ) ;
131134 } ) ) ;
132135 beforeEach ( ( ) => {
136+ item . accessStatus = null ;
137+ linkService . resolveLink . and . callFake ( ( model : any ) => {
138+ item . accessStatus = createSuccessfulRemoteDataObject$ ( embargoStatus ) ;
139+ return model ;
140+ } ) ;
141+ initFixtureAndComponentWithItem ( ) ;
142+ } ) ;
143+ it ( 'should show the embargo badge' , ( ) => {
144+ expect ( linkService . resolveLink ) . toHaveBeenCalledWith ( item , followLink ( 'accessStatus' ) ) ;
145+ lookForAccessStatusBadgeForItem ( 'embargo' ) ;
146+ } ) ;
147+ } ) ;
148+
149+ describe ( 'When the item accessStatus link returns unknown' , ( ) => {
150+ beforeEach ( waitForAsync ( ( ) => {
151+ init ( ) ;
152+ initTestBed ( ) ;
153+ } ) ) ;
154+ beforeEach ( ( ) => {
155+ item . accessStatus = createSuccessfulRemoteDataObject$ ( unknownStatus ) ;
133156 initFixtureAndComponentWithItem ( ) ;
134157 } ) ;
135158 it ( 'should show the unknown badge' , ( ) => {
136159 lookForAccessStatusBadgeForItem ( 'unknown' ) ;
137160 } ) ;
138161 } ) ;
139162
140- describe ( 'When the findItemAccessStatusFor method returns metadata.only with Item ' , ( ) => {
163+ describe ( 'When the item accessStatus link returns metadata.only' , ( ) => {
141164 beforeEach ( waitForAsync ( ( ) => {
142165 init ( ) ;
143- ( accessStatusDataService . findItemAccessStatusFor as jasmine . Spy ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( metadataOnlyStatus ) ) ;
166+ item . accessStatus = createSuccessfulRemoteDataObject$ ( metadataOnlyStatus ) ;
144167 initTestBed ( ) ;
145168 } ) ) ;
146169 beforeEach ( ( ) => {
@@ -151,10 +174,10 @@ describe('ItemAccessStatusBadgeComponent', () => {
151174 } ) ;
152175 } ) ;
153176
154- describe ( 'When the findItemAccessStatusFor method returns open.access with Item ' , ( ) => {
177+ describe ( 'When the item accessStatus link returns open.access' , ( ) => {
155178 beforeEach ( waitForAsync ( ( ) => {
156179 init ( ) ;
157- ( accessStatusDataService . findItemAccessStatusFor as jasmine . Spy ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( openAccessStatus ) ) ;
180+ item . accessStatus = createSuccessfulRemoteDataObject$ ( openAccessStatus ) ;
158181 initTestBed ( ) ;
159182 } ) ) ;
160183 beforeEach ( ( ) => {
@@ -165,10 +188,10 @@ describe('ItemAccessStatusBadgeComponent', () => {
165188 } ) ;
166189 } ) ;
167190
168- describe ( 'When the findItemAccessStatusFor method returns embargo with Item ' , ( ) => {
191+ describe ( 'When the item accessStatus link returns embargo' , ( ) => {
169192 beforeEach ( waitForAsync ( ( ) => {
170193 init ( ) ;
171- ( accessStatusDataService . findItemAccessStatusFor as jasmine . Spy ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( embargoStatus ) ) ;
194+ item . accessStatus = createSuccessfulRemoteDataObject$ ( embargoStatus ) ;
172195 initTestBed ( ) ;
173196 } ) ) ;
174197 beforeEach ( ( ) => {
@@ -179,10 +202,10 @@ describe('ItemAccessStatusBadgeComponent', () => {
179202 } ) ;
180203 } ) ;
181204
182- describe ( 'When the findItemAccessStatusFor method returns restricted with Item ' , ( ) => {
205+ describe ( 'When the item accessStatus link returns restricted' , ( ) => {
183206 beforeEach ( waitForAsync ( ( ) => {
184207 init ( ) ;
185- ( accessStatusDataService . findItemAccessStatusFor as jasmine . Spy ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( restrictedStatus ) ) ;
208+ item . accessStatus = createSuccessfulRemoteDataObject$ ( restrictedStatus ) ;
186209 initTestBed ( ) ;
187210 } ) ) ;
188211 beforeEach ( ( ) => {
@@ -193,33 +216,40 @@ describe('ItemAccessStatusBadgeComponent', () => {
193216 } ) ;
194217 } ) ;
195218
196- describe ( 'init with Bitstream ' , ( ) => {
219+ describe ( 'init with bitstream ' , ( ) => {
197220 beforeEach ( waitForAsync ( ( ) => {
198221 init ( ) ;
199222 initTestBed ( ) ;
200223 } ) ) ;
201224 beforeEach ( ( ) => {
225+ bitstream . accessStatus = createSuccessfulRemoteDataObject$ ( unknownStatus ) ;
202226 initFixtureAndComponentWithBitstream ( ) ;
203227 } ) ;
204228 it ( 'should init the component' , ( ) => {
205229 expect ( component ) . toBeTruthy ( ) ;
206230 } ) ;
207231 } ) ;
208232
209- describe ( 'When the bitstream have no access status ' , ( ) => {
233+ describe ( 'When the bitstream have no accessStatus link ' , ( ) => {
210234 beforeEach ( waitForAsync ( ( ) => {
211235 init ( ) ;
212236 initTestBed ( ) ;
213237 } ) ) ;
214238 beforeEach ( ( ) => {
239+ bitstream . accessStatus = null ;
240+ linkService . resolveLink . and . callFake ( ( model : any ) => {
241+ bitstream . accessStatus = createSuccessfulRemoteDataObject$ ( embargoStatus ) ;
242+ return model ;
243+ } ) ;
215244 initFixtureAndComponentWithBitstream ( ) ;
216245 } ) ;
217- it ( 'should not show the badge' , ( ) => {
218- lookForNoAccessStatusBadgeForBitstream ( ) ;
246+ it ( 'should show the badge' , ( ) => {
247+ expect ( linkService . resolveLink ) . toHaveBeenCalledWith ( bitstream , followLink ( 'accessStatus' ) ) ;
248+ lookForAccessStatusBadgeForBitstream ( ) ;
219249 } ) ;
220250 } ) ;
221251
222- describe ( 'When the bitstream have an access status with no embargo date' , ( ) => {
252+ describe ( 'When the bitstream have an accessStatus link with no embargo date' , ( ) => {
223253 beforeEach ( waitForAsync ( ( ) => {
224254 init ( ) ;
225255 initTestBed ( ) ;
@@ -233,7 +263,7 @@ describe('ItemAccessStatusBadgeComponent', () => {
233263 } ) ;
234264 } ) ;
235265
236- describe ( 'When the bitstream have an access status with an embargo date' , ( ) => {
266+ describe ( 'When the bitstream have an accessStatus link with an embargo date' , ( ) => {
237267 beforeEach ( waitForAsync ( ( ) => {
238268 init ( ) ;
239269 initTestBed ( ) ;
0 commit comments