22/* eslint-disable import-newlines/enforce */
33/* eslint-disable simple-import-sort/imports */
44// End Customization
5- import { CommonModule } from '@angular/common' ;
5+ import {
6+ CommonModule ,
7+ Location ,
8+ } from '@angular/common' ;
69import { PLATFORM_ID } from '@angular/core' ;
710import {
811 ComponentFixture ,
@@ -20,13 +23,15 @@ import { of as observableOf } from 'rxjs';
2023import { RESTRICTED_ACCESS_MODULE_PATH } from '../../app-routing-paths' ;
2124// End UMD Customization
2225import { AuthService } from '../../core/auth/auth.service' ;
26+ import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
2327import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service' ;
2428import { SignpostingDataService } from '../../core/data/signposting-data.service' ;
2529import { HardRedirectService } from '../../core/services/hard-redirect.service' ;
2630import { ServerResponseService } from '../../core/services/server-response.service' ;
2731import { Bitstream } from '../../core/shared/bitstream.model' ;
2832import { FileService } from '../../core/shared/file.service' ;
2933import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils' ;
34+ import { MatomoService } from '../../statistics/matomo.service' ;
3035import { BitstreamDownloadPageComponent } from './bitstream-download-page.component' ;
3136
3237describe ( 'BitstreamDownloadPageComponent' , ( ) => {
@@ -39,10 +44,13 @@ describe('BitstreamDownloadPageComponent', () => {
3944 let hardRedirectService : HardRedirectService ;
4045 let activatedRoute ;
4146 let router ;
47+ let location : Location ;
48+ let dsoNameService : DSONameService ;
4249
4350 let bitstream : Bitstream ;
4451 let serverResponseService : jasmine . SpyObj < ServerResponseService > ;
4552 let signpostingDataService : jasmine . SpyObj < SignpostingDataService > ;
53+ let matomoService : jasmine . SpyObj < MatomoService > ;
4654
4755 const mocklink = {
4856 href : 'http://test.org' ,
@@ -60,6 +68,7 @@ describe('BitstreamDownloadPageComponent', () => {
6068 authService = jasmine . createSpyObj ( 'authService' , {
6169 isAuthenticated : observableOf ( true ) ,
6270 setRedirectUrl : { } ,
71+ getShortlivedToken : observableOf ( 'token' ) ,
6372 } ) ;
6473 authorizationService = jasmine . createSpyObj ( 'authorizationSerivice' , {
6574 isAuthorized : observableOf ( true ) ,
@@ -69,9 +78,18 @@ describe('BitstreamDownloadPageComponent', () => {
6978 retrieveFileDownloadLink : observableOf ( 'content-url-with-headers' ) ,
7079 } ) ;
7180
72- hardRedirectService = jasmine . createSpyObj ( 'fileService ' , {
81+ hardRedirectService = jasmine . createSpyObj ( 'hardRedirectService ' , {
7382 redirect : { } ,
7483 } ) ;
84+
85+ location = jasmine . createSpyObj ( 'location' , {
86+ back : { } ,
87+ } ) ;
88+
89+ dsoNameService = jasmine . createSpyObj ( 'dsoNameService' , {
90+ getName : 'Test Bitstream' ,
91+ } ) ;
92+
7593 bitstream = Object . assign ( new Bitstream ( ) , {
7694 uuid : 'bitstreamUuid' ,
7795 _links : {
@@ -100,6 +118,8 @@ describe('BitstreamDownloadPageComponent', () => {
100118 signpostingDataService = jasmine . createSpyObj ( 'SignpostingDataService' , {
101119 getLinks : observableOf ( [ mocklink , mocklink2 ] ) ,
102120 } ) ;
121+ matomoService = jasmine . createSpyObj ( 'MatomoService' , [ 'appendVisitorId' ] ) ;
122+ matomoService . appendVisitorId . and . callFake ( ( link ) => observableOf ( link ) ) ;
103123 }
104124
105125 function initTestbed ( ) {
@@ -114,7 +134,10 @@ describe('BitstreamDownloadPageComponent', () => {
114134 { provide : HardRedirectService , useValue : hardRedirectService } ,
115135 { provide : ServerResponseService , useValue : serverResponseService } ,
116136 { provide : SignpostingDataService , useValue : signpostingDataService } ,
137+ { provide : MatomoService , useValue : matomoService } ,
117138 { provide : PLATFORM_ID , useValue : 'server' } ,
139+ { provide : Location , useValue : location } ,
140+ { provide : DSONameService , useValue : dsoNameService } ,
118141 ] ,
119142 } )
120143 . compileComponents ( ) ;
@@ -148,9 +171,11 @@ describe('BitstreamDownloadPageComponent', () => {
148171 component = fixture . componentInstance ;
149172 fixture . detectChanges ( ) ;
150173 } ) ;
151- it ( 'should redirect to the content link' , ( ) => {
152- expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( 'bitstream-content-link' ) ;
153- } ) ;
174+ it ( 'should redirect to the content link' , waitForAsync ( ( ) => {
175+ fixture . whenStable ( ) . then ( ( ) => {
176+ expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( 'bitstream-content-link' ) ;
177+ } ) ;
178+ } ) ) ;
154179 it ( 'should add the signposting links' , ( ) => {
155180 expect ( serverResponseService . setHeader ) . toHaveBeenCalled ( ) ;
156181 } ) ;
@@ -165,9 +190,11 @@ describe('BitstreamDownloadPageComponent', () => {
165190 component = fixture . componentInstance ;
166191 fixture . detectChanges ( ) ;
167192 } ) ;
168- it ( 'should redirect to an updated content link' , ( ) => {
169- expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( 'content-url-with-headers' ) ;
170- } ) ;
193+ it ( 'should redirect to an updated content link' , waitForAsync ( ( ) => {
194+ fixture . whenStable ( ) . then ( ( ) => {
195+ expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( 'content-url-with-headers' ) ;
196+ } ) ;
197+ } ) ) ;
171198 } ) ;
172199 describe ( 'when the user is not authorized and logged in' , ( ) => {
173200 beforeEach ( waitForAsync ( ( ) => {
@@ -181,11 +208,13 @@ describe('BitstreamDownloadPageComponent', () => {
181208 fixture . detectChanges ( ) ;
182209 } ) ;
183210 // UMD Customization
184- it ( 'should navigate to the restricted access route' , ( ) => {
185- expect ( router . navigateByUrl ) . toHaveBeenCalledWith (
186- `${ RESTRICTED_ACCESS_MODULE_PATH } /bitstreamUuid` , { replaceUrl : true } ,
187- ) ;
188- } ) ;
211+ it ( 'should navigate to the restricted access route' , waitForAsync ( ( ) => {
212+ fixture . whenStable ( ) . then ( ( ) => {
213+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith (
214+ `${ RESTRICTED_ACCESS_MODULE_PATH } /bitstreamUuid` , { replaceUrl : true } ,
215+ ) ;
216+ } ) ;
217+ } ) ) ;
189218 // End UMD Customization
190219 } ) ;
191220 describe ( 'when the user is not authorized and not logged in' , ( ) => {
@@ -201,11 +230,13 @@ describe('BitstreamDownloadPageComponent', () => {
201230 fixture . detectChanges ( ) ;
202231 } ) ;
203232 // UMD Customization
204- it ( 'should navigate to the restricted access route' , ( ) => {
205- expect ( router . navigateByUrl ) . toHaveBeenCalledWith (
206- `${ RESTRICTED_ACCESS_MODULE_PATH } /bitstreamUuid` , { replaceUrl : true } ,
207- ) ;
208- } ) ;
233+ it ( 'should navigate to the restricted access route' , waitForAsync ( ( ) => {
234+ fixture . whenStable ( ) . then ( ( ) => {
235+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith (
236+ `${ RESTRICTED_ACCESS_MODULE_PATH } /bitstreamUuid` , { replaceUrl : true } ,
237+ ) ;
238+ } ) ;
239+ } ) ) ;
209240 // End UMD Customization
210241 } ) ;
211242 } ) ;
0 commit comments