@@ -52,6 +52,34 @@ import { TruncatablePartComponent } from '../../shared/truncatable/truncatable-p
5252import { FileSizePipe } from '../../shared/utils/file-size-pipe' ;
5353import { LuckySearchService } from '../lucky-search.service' ;
5454import { LuckySearchComponent } from './lucky-search.component' ;
55+ import { ComponentFixture , TestBed } from '@angular/core/testing' ;
56+
57+ import { LuckySearchComponent } from './lucky-search.component' ;
58+ import { LuckySearchService } from '../lucky-search.service' ;
59+ import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service' ;
60+ import { Router , UrlTree } from '@angular/router' ;
61+ import { createSuccessfulRemoteDataObject , createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils' ;
62+ import { createPaginatedList } from '../../shared/testing/utils.test' ;
63+ import { Item } from '../../core/shared/item.model' ;
64+ import { of as observableOf } from 'rxjs' ;
65+ import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model' ;
66+ import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model' ;
67+ import { SortDirection , SortOptions } from '../../core/cache/models/sort-options.model' ;
68+ import { TranslateModule } from '@ngx-translate/core' ;
69+ import { By } from '@angular/platform-browser' ;
70+ import { SearchResult } from '../../shared/search/models/search-result.model' ;
71+ import { DSpaceObject } from '../../core/shared/dspace-object.model' ;
72+ import { BitstreamDataService , MetadataFilter } from '../../core/data/bitstream-data.service' ;
73+ import { Bitstream } from '../../core/shared/bitstream.model' ;
74+ import { RouterMock } from '../../shared/mocks/router.mock' ;
75+ import { MetadataMap , MetadataValue } from '../../core/shared/metadata.models' ;
76+ import { FileSizePipe } from '../../shared/utils/file-size-pipe' ;
77+ import { HardRedirectService } from '../../core/services/hard-redirect.service' ;
78+ import { getBitstreamDownloadRoute } from '../../app-routing-paths' ;
79+ import { PLATFORM_ID } from '@angular/core' ;
80+ import { NotificationsService } from '../../shared/notifications/notifications.service' ;
81+ import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub' ;
82+ import { APP_CONFIG } from '../../../config/app-config.interface' ;
5583
5684describe ( 'LuckySearchComponent' , ( ) => {
5785 let fixture : ComponentFixture < LuckySearchComponent > ;
@@ -131,6 +159,7 @@ describe('LuckySearchComponent', () => {
131159 { provide : HardRedirectService , useValue : hardRedirectService } ,
132160 { provide : PLATFORM_ID , useValue : 'browser' } ,
133161 { provide : NotificationsService , useValue : new NotificationsServiceStub ( ) } ,
162+ { provide : APP_CONFIG , useValue : { } } ,
134163 ] ,
135164 } ) . overrideComponent ( LuckySearchComponent , {
136165 remove : {
@@ -355,4 +384,57 @@ describe('LuckySearchComponent', () => {
355384 } ) ;
356385
357386 } ) ;
387+
388+ describe ( '' , ( ) => {
389+ beforeEach ( ( ) => {
390+ fixture = TestBed . createComponent ( LuckySearchComponent ) ;
391+ component = fixture . componentInstance ;
392+ } ) ;
393+
394+ it ( 'should return default code when no specific identifier is found' , ( ) => {
395+ // @ts -ignore: Accessing private method for testing
396+ component . appConfig = {
397+ luckySearchRedirects : {
398+ default : 301
399+ }
400+ } as any ;
401+ // @ts -ignore: Accessing private method for testing
402+ component . currentFilter = { identifier : 'unknown' } ;
403+
404+ // @ts -ignore: Accessing private method for testing
405+ const result = component . getRedirectCode ( ) ;
406+
407+ expect ( result ) . toBe ( 301 ) ;
408+ } ) ;
409+
410+ it ( 'should return 302 when default is not set and identifier is not found' , ( ) => {
411+ // @ts -ignore: Accessing private method for testing
412+ component . appConfig = {
413+ luckySearchRedirects : { }
414+ } as any ;
415+ // @ts -ignore: Accessing private method for testing
416+ component . currentFilter = { identifier : 'unknown' } ;
417+
418+ // @ts -ignore: Accessing private method for testing
419+ const result = component . getRedirectCode ( ) ;
420+ expect ( result ) . toBe ( 302 ) ;
421+ } ) ;
422+
423+ it ( 'should return specific code for known identifier' , ( ) => {
424+ // @ts -ignore: Accessing private method for testing
425+ component . appConfig = {
426+ luckySearchRedirects : {
427+ default : 302 ,
428+ 'legacy-id' : 301
429+ }
430+ } ;
431+ // @ts -ignore: Accessing private method for testing
432+ component . currentFilter = { identifier : 'legacy-id' } ;
433+
434+ // @ts -ignore: Accessing private method for testing
435+ const result = component . getRedirectCode ( ) ;
436+ expect ( result ) . toBe ( 301 ) ;
437+ } ) ;
438+
439+ } ) ;
358440} ) ;
0 commit comments