@@ -27,6 +27,7 @@ import { getItemModuleRoute } from '../../item-page/item-page-routing-paths';
2727import { ActivatedRouteStub } from '../testing/active-router.stub' ;
2828import { RouterLinkDirectiveStub } from '../testing/router-link-directive.stub' ;
2929import { FileDownloadLinkComponent } from './file-download-link.component' ;
30+ import { ItemRequest } from '../../core/shared/item-request.model' ;
3031
3132describe ( 'FileDownloadLinkComponent' , ( ) => {
3233 let component : FileDownloadLinkComponent ;
@@ -39,6 +40,13 @@ describe('FileDownloadLinkComponent', () => {
3940 let item : Item ;
4041 let storeMock : any ;
4142
43+ const itemRequestStub = Object . assign ( new ItemRequest ( ) , {
44+ token : 'item-request-token' ,
45+ requestName : 'requester name' ,
46+ accessToken : 'abc123' ,
47+ allfiles : true ,
48+ } ) ;
49+
4250 function init ( ) {
4351 authorizationService = jasmine . createSpyObj ( 'authorizationService' , {
4452 isAuthorized : cold ( '-a' , { a : true } ) ,
@@ -62,7 +70,8 @@ describe('FileDownloadLinkComponent', () => {
6270 } ) ;
6371 }
6472
65- function initTestbed ( ) {
73+ function initTestbed ( itemRequest = null ) {
74+ const activatedRoute = new ActivatedRouteStub ( { } , { itemRequest : itemRequest } ) ;
6675 TestBed . configureTestingModule ( {
6776 imports : [
6877 TranslateModule . forRoot ( ) ,
@@ -71,7 +80,7 @@ describe('FileDownloadLinkComponent', () => {
7180 providers : [
7281 RouterLinkDirectiveStub ,
7382 { provide : AuthorizationDataService , useValue : authorizationService } ,
74- { provide : ActivatedRoute , useValue : new ActivatedRouteStub ( ) } ,
83+ { provide : ActivatedRoute , useValue : activatedRoute } ,
7584 { provide : Store , useValue : storeMock } ,
7685 { provide : APP_DATA_SERVICES_MAP , useValue : { } } ,
7786 ] ,
@@ -85,6 +94,9 @@ describe('FileDownloadLinkComponent', () => {
8594
8695 describe ( 'init' , ( ) => {
8796 describe ( 'getBitstreamPath' , ( ) => {
97+
98+
99+
88100 describe ( 'when the user has download rights' , ( ) => {
89101 beforeEach ( waitForAsync ( ( ) => {
90102 scheduler = getTestScheduler ( ) ;
@@ -113,6 +125,7 @@ describe('FileDownloadLinkComponent', () => {
113125 expect ( lock ) . toBeNull ( ) ;
114126 } ) ;
115127 } ) ;
128+
116129 describe ( 'when the user has no download rights but has the right to request a copy' , ( ) => {
117130 beforeEach ( waitForAsync ( ( ) => {
118131 scheduler = getTestScheduler ( ) ;
@@ -146,6 +159,7 @@ describe('FileDownloadLinkComponent', () => {
146159 expect ( lock ) . toBeTruthy ( ) ;
147160 } ) ;
148161 } ) ;
162+
149163 describe ( 'when the user has no download rights and no request a copy rights' , ( ) => {
150164 beforeEach ( waitForAsync ( ( ) => {
151165 scheduler = getTestScheduler ( ) ;
@@ -165,7 +179,7 @@ describe('FileDownloadLinkComponent', () => {
165179 expect ( component . canDownload$ ) . toBeObservable ( cold ( '--a' , { a : false } ) ) ;
166180
167181 } ) ;
168- it ( 'should init the component' , ( ) => {
182+ it ( 'should init the component and show the locked icon ' , ( ) => {
169183 scheduler . flush ( ) ;
170184 fixture . detectChanges ( ) ;
171185 const link = fixture . debugElement . query ( By . css ( 'a' ) ) ;
@@ -174,6 +188,35 @@ describe('FileDownloadLinkComponent', () => {
174188 expect ( lock ) . toBeTruthy ( ) ;
175189 } ) ;
176190 } ) ;
191+
192+ describe ( 'when the user has no (normal) download rights and request a copy rights via access token' , ( ) => {
193+ beforeEach ( waitForAsync ( ( ) => {
194+ scheduler = getTestScheduler ( ) ;
195+ init ( ) ;
196+ ( authorizationService . isAuthorized as jasmine . Spy ) . and . returnValue ( cold ( '-a' , { a : false } ) ) ;
197+ initTestbed ( itemRequestStub ) ;
198+ } ) ) ;
199+ beforeEach ( ( ) => {
200+ fixture = TestBed . createComponent ( FileDownloadLinkComponent ) ;
201+ component = fixture . componentInstance ;
202+ component . bitstream = bitstream ;
203+ component . item = item ;
204+ fixture . detectChanges ( ) ;
205+ } ) ;
206+ it ( 'should return the bitstreamPath based on the access token and request-a-copy path' , ( ) => {
207+ expect ( component . bitstreamPath$ ) . toBeObservable ( cold ( '-a' , { a : { routerLink : new URLCombiner ( getBitstreamModuleRoute ( ) , bitstream . uuid , 'download' ) . toString ( ) , queryParams : { accessToken : 'abc123' } } } ) ) ;
208+ expect ( component . canDownload$ ) . toBeObservable ( cold ( '--a' , { a : false } ) ) ;
209+
210+ } ) ;
211+ it ( 'should init the component and show an open lock' , ( ) => {
212+ scheduler . flush ( ) ;
213+ fixture . detectChanges ( ) ;
214+ const link = fixture . debugElement . query ( By . css ( 'a' ) ) ;
215+ expect ( link . injector . get ( RouterLinkDirectiveStub ) . routerLink ) . toContain ( new URLCombiner ( getBitstreamModuleRoute ( ) , bitstream . uuid , 'download' ) . toString ( ) ) ;
216+ const lock = fixture . debugElement . query ( By . css ( '.fa-lock-open' ) ) . nativeElement ;
217+ expect ( lock ) . toBeTruthy ( ) ;
218+ } ) ;
219+ } ) ;
177220 } ) ;
178221 } ) ;
179222} ) ;
0 commit comments