diff --git a/src/app/shared/search/search.component.spec.ts b/src/app/shared/search/search.component.spec.ts index 3f00cf354f..85d4111b78 100644 --- a/src/app/shared/search/search.component.spec.ts +++ b/src/app/shared/search/search.component.spec.ts @@ -13,7 +13,7 @@ import { PaginationComponentOptions } from '../pagination/pagination-component-o import { SearchComponent } from './search.component'; import { SearchService } from '../../core/shared/search/search.service'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, NavigationStart } from '@angular/router'; import { By } from '@angular/platform-browser'; import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'; import { SidebarService } from '../sidebar/sidebar.service'; @@ -31,6 +31,10 @@ import { SearchObjects } from './models/search-objects.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { SearchFilterConfig } from './models/search-filter-config.model'; import { FilterType } from './models/filter-type.model'; +import { createPaginatedList } from '../testing/utils.test'; +import { COMMUNITY_MODULE_PATH, getCommunityPageRoute } from '../../community-page/community-page-routing-paths'; +import { getCollectionPageRoute } from '../../collection-page/collection-page-routing-paths'; +import { getItemPageRoute } from '../../item-page/item-page-routing-paths'; let comp: SearchComponent; let fixture: ComponentFixture; @@ -101,8 +105,9 @@ const searchServiceStub = jasmine.createSpyObj('SearchService', { search: mockResultsRD$, getSearchLink: '/search', getScopes: observableOf(['test-scope']), - getSearchConfigurationFor: createSuccessfulRemoteDataObject$(searchConfig) -}); + getSearchConfigurationFor: createSuccessfulRemoteDataObject$(searchConfig), + trackSearch: {}, +}) as SearchService; const configurationParam = 'default'; const queryParam = 'test query'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; @@ -237,7 +242,7 @@ export function configureSearchComponentTestingModule(compType, additionalDeclar }).compileComponents(); } -describe('SearchComponent', () => { +fdescribe('SearchComponent', () => { beforeEach(waitForAsync(() => { configureSearchComponentTestingModule(SearchComponent); })); @@ -327,4 +332,64 @@ describe('SearchComponent', () => { })); }); + + describe('getDsoUUIDFromUrl', () => { + let url: string; + let result: string; + + describe('when the navigated URL is an entity route', () => { + beforeEach(() => { + url = '/entities/publication/9a364471-3f19-4e7b-916a-a24a44ff48e3'; + result = (comp as any).getDsoUUIDFromUrl(url); + }); + + it('should return the UUID', () => { + expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3'); + }); + }); + + describe('when the navigated URL is a community route', () => { + beforeEach(() => { + url = `${getCommunityPageRoute('9a364471-3f19-4e7b-916a-a24a44ff48e3')}`; + result = (comp as any).getDsoUUIDFromUrl(url); + }); + + it('should return the UUID', () => { + expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3'); + }); + }); + + describe('when the navigated URL is a collection route', () => { + beforeEach(() => { + url = `${getCollectionPageRoute('9a364471-3f19-4e7b-916a-a24a44ff48e3')}`; + result = (comp as any).getDsoUUIDFromUrl(url); + }); + + it('should return the UUID', () => { + expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3'); + }); + }); + + describe('when the navigated URL is an item route', () => { + beforeEach(() => { + url = '/items/9a364471-3f19-4e7b-916a-a24a44ff48e3'; + result = (comp as any).getDsoUUIDFromUrl(url); + }); + + it('should return the UUID', () => { + expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3'); + }); + }); + + describe('when the navigated URL is an invalid route', () => { + beforeEach(() => { + url = '/invalid/object/route/9a364471-3f19-4e7b-916a-a24a44ff48e3'; + result = (comp as any).getDsoUUIDFromUrl(url); + }); + + it('should return null', () => { + expect(result).toBeNull(); + }); + }); + }); });