@@ -25,6 +25,7 @@ import {getBitstreamDownloadRoute} from '../../app-routing-paths';
2525import { PLATFORM_ID } from '@angular/core' ;
2626import { NotificationsService } from '../../shared/notifications/notifications.service' ;
2727import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub' ;
28+ import { APP_CONFIG } from '../../../config/app-config.interface' ;
2829
2930describe ( 'LuckySearchComponent' , ( ) => {
3031 let fixture : ComponentFixture < LuckySearchComponent > ;
@@ -101,6 +102,7 @@ describe('LuckySearchComponent', () => {
101102 { provide : HardRedirectService , useValue : hardRedirectService } ,
102103 { provide : PLATFORM_ID , useValue : 'browser' } ,
103104 { provide : NotificationsService , useValue : new NotificationsServiceStub ( ) } ,
105+ { provide : APP_CONFIG , useValue : { } } ,
104106 ] ,
105107 } )
106108 . compileComponents ( ) ;
@@ -288,30 +290,83 @@ describe('LuckySearchComponent', () => {
288290 component = fixture . componentInstance ;
289291 } ) ;
290292
291- it ( 'should not redirect when no bitstreams are found' , ( ) => {
292- const item = Object . assign ( new Item ( ) , { uuid : 'item-uuid-1' , name : 'Test item 1' } ) ;
293- const data = createSuccessfulRemoteDataObject ( createPaginatedList ( [
294- { indexableObject : item , hitHighlights : { } }
295- ] ) ) as any ;
296- component . resultsRD$ . next ( data ) ;
297- component . bitstreamFilters$ . next ( [ { metadataName : 'dc.title' , metadataValue : 'Non-existent bitstream' } ] ) ;
298- bitstreamDataService . findByItem . and . returnValue ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ ] ) ) ) ;
299- spyOn ( component , 'redirect' ) ;
300- fixture . detectChanges ( ) ;
301- expect ( component . redirect ) . not . toHaveBeenCalled ( ) ;
302- } ) ;
293+ it ( 'should not redirect when no bitstreams are found' , ( ) => {
294+ const item = Object . assign ( new Item ( ) , { uuid : 'item-uuid-1' , name : 'Test item 1' } ) ;
295+ const data = createSuccessfulRemoteDataObject ( createPaginatedList ( [
296+ { indexableObject : item , hitHighlights : { } }
297+ ] ) ) as any ;
298+ component . resultsRD$ . next ( data ) ;
299+ component . bitstreamFilters$ . next ( [ { metadataName : 'dc.title' , metadataValue : 'Non-existent bitstream' } ] ) ;
300+ bitstreamDataService . findByItem . and . returnValue ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ ] ) ) ) ;
301+ spyOn ( component , 'redirect' ) ;
302+ fixture . detectChanges ( ) ;
303+ expect ( component . redirect ) . not . toHaveBeenCalled ( ) ;
304+ } ) ;
303305
304- it ( 'should update showEmptySearchSection$ when no results are found' , ( ) => {
306+ it ( 'should update showEmptySearchSection$ when no results are found' , ( ) => {
305307 fixture . detectChanges ( ) ;
306- const emptyResults = createSuccessfulRemoteDataObject ( createPaginatedList ( [ ] ) ) ;
308+ const emptyResults = createSuccessfulRemoteDataObject ( createPaginatedList ( [ ] ) ) ;
307309
308- spyOn ( component as any , 'getLuckySearchResults' ) . and . returnValue ( observableOf ( emptyResults ) ) ;
309- spyOn ( component as any , 'processSearchResults' ) . and . returnValue ( observableOf ( emptyResults ) ) ;
310+ spyOn ( component as any , 'getLuckySearchResults' ) . and . returnValue ( observableOf ( emptyResults ) ) ;
311+ spyOn ( component as any , 'processSearchResults' ) . and . returnValue ( observableOf ( emptyResults ) ) ;
310312
311- component . getSearchResults ( ) ;
313+ component . getSearchResults ( ) ;
314+
315+ expect ( component . showEmptySearchSection$ . getValue ( ) ) . toBe ( true ) ;
316+ } ) ;
312317
313- expect ( component . showEmptySearchSection$ . getValue ( ) ) . toBe ( true ) ;
314318 } ) ;
315319
320+ describe ( '' , ( ) => {
321+ beforeEach ( ( ) => {
322+ fixture = TestBed . createComponent ( LuckySearchComponent ) ;
323+ component = fixture . componentInstance ;
324+ } ) ;
325+
326+ it ( 'should return default code when no specific identifier is found' , ( ) => {
327+ // @ts -ignore: Accessing private method for testing
328+ component . appConfig = {
329+ luckySearchRedirects : {
330+ default : 301
331+ }
332+ } as any ;
333+ // @ts -ignore: Accessing private method for testing
334+ component . currentFilter = { identifier : 'unknown' } ;
335+
336+ // @ts -ignore: Accessing private method for testing
337+ const result = component . getRedirectCode ( ) ;
338+
339+ expect ( result ) . toBe ( 301 ) ;
340+ } ) ;
341+
342+ it ( 'should return 302 when default is not set and identifier is not found' , ( ) => {
343+ // @ts -ignore: Accessing private method for testing
344+ component . appConfig = {
345+ luckySearchRedirects : { }
346+ } as any ;
347+ // @ts -ignore: Accessing private method for testing
348+ component . currentFilter = { identifier : 'unknown' } ;
349+
350+ // @ts -ignore: Accessing private method for testing
351+ const result = component . getRedirectCode ( ) ;
352+ expect ( result ) . toBe ( 302 ) ;
353+ } ) ;
354+
355+ it ( 'should return specific code for known identifier' , ( ) => {
356+ // @ts -ignore: Accessing private method for testing
357+ component . appConfig = {
358+ luckySearchRedirects : {
359+ default : 302 ,
360+ 'legacy-id' : 301
361+ }
362+ } ;
363+ // @ts -ignore: Accessing private method for testing
364+ component . currentFilter = { identifier : 'legacy-id' } ;
365+
366+ // @ts -ignore: Accessing private method for testing
367+ const result = component . getRedirectCode ( ) ;
368+ expect ( result ) . toBe ( 301 ) ;
369+ } ) ;
370+
316371 } ) ;
317372} ) ;
0 commit comments