@@ -8,6 +8,7 @@ import { HardRedirectService } from '@dspace/core/services/hard-redirect.service
88import { DSpaceObject } from '@dspace/core/shared/dspace-object.model' ;
99import { MetadataValueFilter } from '@dspace/core/shared/metadata.models' ;
1010import { AuthServiceStub } from '@dspace/core/testing/auth-service.stub' ;
11+ import { NotificationsServiceStub } from '@dspace/core/testing/notifications-service.stub' ;
1112import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils' ;
1213import { first } from 'rxjs/operators' ;
1314
@@ -35,6 +36,8 @@ describe('itemPageResolver', () => {
3536 let authService : AuthServiceStub ;
3637 let platformId : any ;
3738 let hardRedirectService : any ;
39+ let notificationsService : NotificationsServiceStub ;
40+ let translateService : any ;
3841
3942 const uuid = '1234-65487-12354-1235' ;
4043 let item : DSpaceObject ;
@@ -46,6 +49,8 @@ describe('itemPageResolver', () => {
4649 hardRedirectService = jasmine . createSpyObj ( 'hardRedirectService' , {
4750 redirect : { } ,
4851 } ) ;
52+ notificationsService = new NotificationsServiceStub ( ) ;
53+ translateService = { instant : ( key : string ) => key } as any ;
4954 item = Object . assign ( new DSpaceObject ( ) , {
5055 uuid : uuid ,
5156 firstMetadataValue ( _keyOrKeys : string | string [ ] , _valueFilter ?: MetadataValueFilter ) : string {
@@ -74,6 +79,8 @@ describe('itemPageResolver', () => {
7479 authService ,
7580 platformId ,
7681 hardRedirectService ,
82+ notificationsService ,
83+ translateService ,
7784 ) . pipe ( first ( ) )
7885 . subscribe (
7986 ( ) => {
@@ -83,7 +90,7 @@ describe('itemPageResolver', () => {
8390 ) ;
8491 } ) ;
8592
86- it ( 'should not redirect if we’ re already on the correct route' , ( done ) => {
93+ it ( 'should not redirect if we\' re already on the correct route' , ( done ) => {
8794 spyOn ( item , 'firstMetadataValue' ) . and . returnValue ( entityType ) ;
8895 spyOn ( router , 'navigateByUrl' ) . and . callThrough ( ) ;
8996
@@ -96,6 +103,8 @@ describe('itemPageResolver', () => {
96103 authService ,
97104 platformId ,
98105 hardRedirectService ,
106+ notificationsService ,
107+ translateService ,
99108 ) . pipe ( first ( ) )
100109 . subscribe (
101110 ( ) => {
@@ -129,6 +138,8 @@ describe('itemPageResolver', () => {
129138 let authService : AuthServiceStub ;
130139 let platformId : any ;
131140 let hardRedirectService : any ;
141+ let notificationsService : NotificationsServiceStub ;
142+ let translateService : any ;
132143
133144 const uuid = '1234-65487-12354-1235' ;
134145 let item : DSpaceObject ;
@@ -139,6 +150,8 @@ describe('itemPageResolver', () => {
139150 hardRedirectService = jasmine . createSpyObj ( 'hardRedirectService' , {
140151 redirect : { } ,
141152 } ) ;
153+ notificationsService = new NotificationsServiceStub ( ) ;
154+ translateService = { instant : ( key : string ) => key } as any ;
142155 item = Object . assign ( new DSpaceObject ( ) , {
143156 uuid : uuid ,
144157 id : uuid ,
@@ -168,7 +181,7 @@ describe('itemPageResolver', () => {
168181 const route = { params : { id : uuid } } as any ;
169182 const state = { url : `/entities/person/${ uuid } ` } as any ;
170183
171- resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService )
184+ resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService , notificationsService , translateService )
172185 . pipe ( first ( ) )
173186 . subscribe ( ( rd : any ) => {
174187 const expectedUrl = `/entities/person/${ customUrl } ` ;
@@ -183,7 +196,7 @@ describe('itemPageResolver', () => {
183196 const route = { params : { id : customUrl } } as any ;
184197 const state = { url : `/entities/person/${ customUrl } ` } as any ;
185198
186- resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService )
199+ resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService , notificationsService , translateService )
187200 . pipe ( first ( ) )
188201 . subscribe ( ( rd : any ) => {
189202 expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
@@ -197,7 +210,7 @@ describe('itemPageResolver', () => {
197210 const route = { params : { id : customUrl } } as any ;
198211 const state = { url : `/entities/person/${ customUrl } /edit` } as any ;
199212
200- resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService )
213+ resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService , notificationsService , translateService )
201214 . pipe ( first ( ) )
202215 . subscribe ( ( ) => {
203216 expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( `/entities/person/${ uuid } /edit` ) ;
@@ -211,13 +224,48 @@ describe('itemPageResolver', () => {
211224 const route = { params : { id : customUrl } } as any ;
212225 const state = { url : `/entities/person/${ customUrl } /full` } as any ;
213226
214- resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService )
227+ resolver ( route , state , router , itemService , store , authService , platformId , hardRedirectService , notificationsService , translateService )
215228 . pipe ( first ( ) )
216229 . subscribe ( ( ) => {
217230 expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ; ;
218231 done ( ) ;
219232 } ) ;
220233 } ) ;
234+
235+ it ( 'should fall back to UUID and show a warning notification when dspace.customurl contains invalid characters' , ( done ) => {
236+ const invalidCustomUrl = 'café-测试' ;
237+ const itemWithInvalidUrl = Object . assign ( new DSpaceObject ( ) , {
238+ uuid : uuid ,
239+ id : uuid ,
240+ firstMetadataValue ( _keyOrKeys : string | string [ ] , _valueFilter ?: MetadataValueFilter ) : string {
241+ return _keyOrKeys === 'dspace.entity.type' ? 'person' : invalidCustomUrl ;
242+ } ,
243+ hasMetadata ( _keyOrKeys : string | string [ ] , _valueFilter ?: MetadataValueFilter ) : boolean {
244+ return true ;
245+ } ,
246+ metadata : { 'dspace.customurl' : invalidCustomUrl } ,
247+ } ) ;
248+ const invalidItemService = {
249+ findByIdOrCustomUrl : ( _id : string ) => createSuccessfulRemoteDataObject$ ( itemWithInvalidUrl ) ,
250+ } ;
251+ notificationsService = new NotificationsServiceStub ( ) ;
252+ translateService = { instant : ( key : string ) => key } as any ;
253+
254+ spyOn ( router , 'navigateByUrl' ) . and . callThrough ( ) ;
255+ spyOn ( notificationsService , 'warning' ) . and . callThrough ( ) ;
256+
257+ const encodedInvalidUrl = encodeURIComponent ( invalidCustomUrl ) ;
258+ const route = { params : { id : invalidCustomUrl } } as any ;
259+ const state = { url : `/entities/person/${ encodedInvalidUrl } ` } as any ;
260+
261+ resolver ( route , state , router , invalidItemService , store , authService , platformId , hardRedirectService , notificationsService , translateService )
262+ . pipe ( first ( ) )
263+ . subscribe ( ( ) => {
264+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( `/entities/person/${ uuid } ` ) ;
265+ expect ( notificationsService . warning ) . toHaveBeenCalled ( ) ;
266+ done ( ) ;
267+ } ) ;
268+ } ) ;
221269 } ) ;
222270
223271} ) ;
0 commit comments