Skip to content

Commit 6675b61

Browse files
100414: test cases
1 parent 540ce4d commit 6675b61

1 file changed

Lines changed: 69 additions & 4 deletions

File tree

src/app/shared/search/search.component.spec.ts

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { PaginationComponentOptions } from '../pagination/pagination-component-o
1313
import { SearchComponent } from './search.component';
1414
import { SearchService } from '../../core/shared/search/search.service';
1515
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
16-
import { ActivatedRoute } from '@angular/router';
16+
import { ActivatedRoute, NavigationStart } from '@angular/router';
1717
import { By } from '@angular/platform-browser';
1818
import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';
1919
import { SidebarService } from '../sidebar/sidebar.service';
@@ -31,6 +31,10 @@ import { SearchObjects } from './models/search-objects.model';
3131
import { DSpaceObject } from '../../core/shared/dspace-object.model';
3232
import { SearchFilterConfig } from './models/search-filter-config.model';
3333
import { FilterType } from './models/filter-type.model';
34+
import { createPaginatedList } from '../testing/utils.test';
35+
import { COMMUNITY_MODULE_PATH, getCommunityPageRoute } from '../../community-page/community-page-routing-paths';
36+
import { getCollectionPageRoute } from '../../collection-page/collection-page-routing-paths';
37+
import { getItemPageRoute } from '../../item-page/item-page-routing-paths';
3438

3539
let comp: SearchComponent;
3640
let fixture: ComponentFixture<SearchComponent>;
@@ -101,8 +105,9 @@ const searchServiceStub = jasmine.createSpyObj('SearchService', {
101105
search: mockResultsRD$,
102106
getSearchLink: '/search',
103107
getScopes: observableOf(['test-scope']),
104-
getSearchConfigurationFor: createSuccessfulRemoteDataObject$(searchConfig)
105-
});
108+
getSearchConfigurationFor: createSuccessfulRemoteDataObject$(searchConfig),
109+
trackSearch: {},
110+
}) as SearchService;
106111
const configurationParam = 'default';
107112
const queryParam = 'test query';
108113
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
@@ -237,7 +242,7 @@ export function configureSearchComponentTestingModule(compType, additionalDeclar
237242
}).compileComponents();
238243
}
239244

240-
describe('SearchComponent', () => {
245+
fdescribe('SearchComponent', () => {
241246
beforeEach(waitForAsync(() => {
242247
configureSearchComponentTestingModule(SearchComponent);
243248
}));
@@ -327,4 +332,64 @@ describe('SearchComponent', () => {
327332
}));
328333

329334
});
335+
336+
describe('getDsoUUIDFromUrl', () => {
337+
let url: string;
338+
let result: string;
339+
340+
describe('when the navigated URL is an entity route', () => {
341+
beforeEach(() => {
342+
url = '/entities/publication/9a364471-3f19-4e7b-916a-a24a44ff48e3';
343+
result = (comp as any).getDsoUUIDFromUrl(url);
344+
});
345+
346+
it('should return the UUID', () => {
347+
expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3');
348+
});
349+
});
350+
351+
describe('when the navigated URL is a community route', () => {
352+
beforeEach(() => {
353+
url = `${getCommunityPageRoute('9a364471-3f19-4e7b-916a-a24a44ff48e3')}`;
354+
result = (comp as any).getDsoUUIDFromUrl(url);
355+
});
356+
357+
it('should return the UUID', () => {
358+
expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3');
359+
});
360+
});
361+
362+
describe('when the navigated URL is a collection route', () => {
363+
beforeEach(() => {
364+
url = `${getCollectionPageRoute('9a364471-3f19-4e7b-916a-a24a44ff48e3')}`;
365+
result = (comp as any).getDsoUUIDFromUrl(url);
366+
});
367+
368+
it('should return the UUID', () => {
369+
expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3');
370+
});
371+
});
372+
373+
describe('when the navigated URL is an item route', () => {
374+
beforeEach(() => {
375+
url = '/items/9a364471-3f19-4e7b-916a-a24a44ff48e3';
376+
result = (comp as any).getDsoUUIDFromUrl(url);
377+
});
378+
379+
it('should return the UUID', () => {
380+
expect(result).toEqual('9a364471-3f19-4e7b-916a-a24a44ff48e3');
381+
});
382+
});
383+
384+
describe('when the navigated URL is an invalid route', () => {
385+
beforeEach(() => {
386+
url = '/invalid/object/route/9a364471-3f19-4e7b-916a-a24a44ff48e3';
387+
result = (comp as any).getDsoUUIDFromUrl(url);
388+
});
389+
390+
it('should return null', () => {
391+
expect(result).toBeNull();
392+
});
393+
});
394+
});
330395
});

0 commit comments

Comments
 (0)