|
| 1 | +import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 2 | + |
| 3 | +import {LuckySearchComponent} from './lucky-search.component'; |
| 4 | +import {LuckySearchService} from '../lucky-search.service'; |
| 5 | +import {SearchConfigurationService} from '../../core/shared/search/search-configuration.service'; |
| 6 | +import {Router, UrlTree} from '@angular/router'; |
| 7 | +import {createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$} from '../../shared/remote-data.utils'; |
| 8 | +import {createPaginatedList} from '../../shared/testing/utils.test'; |
| 9 | +import {Item} from '../../core/shared/item.model'; |
| 10 | +import {of as observableOf} from 'rxjs'; |
| 11 | +import {PaginatedSearchOptions} from '../../shared/search/models/paginated-search-options.model'; |
| 12 | +import {PaginationComponentOptions} from '../../shared/pagination/pagination-component-options.model'; |
| 13 | +import {SortDirection, SortOptions} from '../../core/cache/models/sort-options.model'; |
| 14 | +import {TranslateModule} from '@ngx-translate/core'; |
| 15 | +import {By} from '@angular/platform-browser'; |
| 16 | +import {SearchResult} from '../../shared/search/models/search-result.model'; |
| 17 | +import {DSpaceObject} from '../../core/shared/dspace-object.model'; |
| 18 | +import {BitstreamDataService, MetadataFilter} from '../../core/data/bitstream-data.service'; |
| 19 | +import {Bitstream} from '../../core/shared/bitstream.model'; |
| 20 | +import {RouterMock} from '../../shared/mocks/router.mock'; |
| 21 | +import {MetadataMap, MetadataValue} from '../../core/shared/metadata.models'; |
| 22 | +import {FileSizePipe} from '../../shared/utils/file-size-pipe'; |
| 23 | +import {HardRedirectService} from '../../core/services/hard-redirect.service'; |
| 24 | +import {getBitstreamDownloadRoute} from '../../app-routing-paths'; |
| 25 | +import {PLATFORM_ID} from '@angular/core'; |
| 26 | +import {NotificationsService} from '../../shared/notifications/notifications.service'; |
| 27 | +import {NotificationsServiceStub} from '../../shared/testing/notifications-service.stub'; |
| 28 | +import {APP_CONFIG} from '../../../config/app-config.interface'; |
1 | 29 | import { |
2 | 30 | ChangeDetectionStrategy, |
3 | 31 | PLATFORM_ID, |
@@ -131,6 +159,7 @@ describe('LuckySearchComponent', () => { |
131 | 159 | { provide: HardRedirectService, useValue: hardRedirectService }, |
132 | 160 | { provide: PLATFORM_ID, useValue: 'browser' }, |
133 | 161 | { provide: NotificationsService, useValue: new NotificationsServiceStub() }, |
| 162 | + {provide: APP_CONFIG, useValue: {}}, |
134 | 163 | ], |
135 | 164 | }).overrideComponent(LuckySearchComponent, { |
136 | 165 | remove: { |
@@ -355,4 +384,57 @@ describe('LuckySearchComponent', () => { |
355 | 384 | }); |
356 | 385 |
|
357 | 386 | }); |
| 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 | + }); |
358 | 440 | }); |
0 commit comments