Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions src/app/core/shared/search/search-configuration.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('SearchConfigurationService', () => {
}));

service = new SearchConfigurationService(routeService, paginationService as any, activatedRoute as any, linkService, halService, requestService, rdb, environment);
service.searchInstanceId = defaults.pagination.id;
});

describe('when the scope is called', () => {
Expand Down Expand Up @@ -181,7 +182,7 @@ describe('SearchConfigurationService', () => {

describe('when subscribeToSearchOptions is called', () => {
beforeEach(() => {
(service as any).subscribeToSearchOptions(defaults);
(service as any).subscribeToSearchOptions(defaults.pagination.id, defaults);
});
it('should call all getters it needs, but not call any others', () => {
expect(service.getCurrentPagination).not.toHaveBeenCalled();
Expand All @@ -198,14 +199,14 @@ describe('SearchConfigurationService', () => {
beforeEach(() => {
(service as any).subscribeToPaginatedSearchOptions(defaults.pagination.id, defaults);
});
it('should call all getters it needs', () => {
it('should call the pagination-specific getters it needs', () => {
expect(service.getCurrentPagination).toHaveBeenCalled();
expect(service.getCurrentSort).toHaveBeenCalled();
expect(service.getCurrentScope).toHaveBeenCalled();
expect(service.getCurrentConfiguration).toHaveBeenCalled();
expect(service.getCurrentQuery).toHaveBeenCalled();
expect(service.getCurrentDSOType).toHaveBeenCalled();
expect(service.getCurrentFilters).toHaveBeenCalled();
expect(service.getCurrentScope).not.toHaveBeenCalled();
expect(service.getCurrentConfiguration).not.toHaveBeenCalled();
expect(service.getCurrentQuery).not.toHaveBeenCalled();
expect(service.getCurrentDSOType).not.toHaveBeenCalled();
expect(service.getCurrentFilters).not.toHaveBeenCalled();
});
});
});
Expand Down Expand Up @@ -299,6 +300,29 @@ describe('SearchConfigurationService', () => {
});
});

describe('isLegacySearchParam', () => {
it('should return true for unprefixed scoped search params', () => {
['configuration', 'scope', 'query', 'dsoType', 'view'].forEach((param: string) => {
expect(service.isLegacySearchParam(param)).toBeTrue();
});
});

it('should return true for unprefixed filter params', () => {
expect(service.isLegacySearchParam('f.author')).toBeTrue();
expect(service.isLegacySearchParam('f.dateIssued.max')).toBeTrue();
});

it('should return false for params that are already prefixed with a search instance id', () => {
expect(service.isLegacySearchParam(`${defaults.pagination.id}.query`)).toBeFalse();
expect(service.isLegacySearchParam(`${defaults.pagination.id}.f.author`)).toBeFalse();
});

it('should return false for unrelated params', () => {
expect(service.isLegacySearchParam('page')).toBeFalse();
expect(service.isLegacySearchParam('spc.page')).toBeFalse();
});
});

describe('unselectAppliedFilterParams', () => {
let appliedFilter: AppliedFilter;

Expand All @@ -314,13 +338,13 @@ describe('SearchConfigurationService', () => {
it('should return all params except the applied filter', () => {
service.unselectAppliedFilterParams(appliedFilter.filter, appliedFilter.value, appliedFilter.operator);

expect(routeService.getParamsExceptValue).toHaveBeenCalledWith('f.author', '1282121b-5394-4689-ab93-78d537764052,authority');
expect(routeService.getParamsExceptValue).toHaveBeenCalledWith(`${defaults.pagination.id}.f.author`, '1282121b-5394-4689-ab93-78d537764052,authority');
});

it('should be able to remove AppliedFilter without operator', () => {
service.unselectAppliedFilterParams('dateIssued.max', '2000');

expect(routeService.getParamsExceptValue).toHaveBeenCalledWith('f.dateIssued.max', '2000');
expect(routeService.getParamsExceptValue).toHaveBeenCalledWith(`${defaults.pagination.id}.f.dateIssued.max`, '2000');
});

it('should reset the page to 1', (done: DoneFn) => {
Expand All @@ -346,13 +370,13 @@ describe('SearchConfigurationService', () => {
it('should return all params with the applied filter', () => {
service.selectNewAppliedFilterParams(appliedFilter.filter, appliedFilter.value, appliedFilter.operator);

expect(routeService.getParamsWithAdditionalValue).toHaveBeenCalledWith('f.author', '1282121b-5394-4689-ab93-78d537764052,authority');
expect(routeService.getParamsWithAdditionalValue).toHaveBeenCalledWith(`${defaults.pagination.id}.f.author`, '1282121b-5394-4689-ab93-78d537764052,authority');
});

it('should be able to add AppliedFilter without operator', () => {
service.selectNewAppliedFilterParams('dateIssued.max', '2000');

expect(routeService.getParamsWithAdditionalValue).toHaveBeenCalledWith('f.dateIssued.max', '2000');
expect(routeService.getParamsWithAdditionalValue).toHaveBeenCalledWith(`${defaults.pagination.id}.f.dateIssued.max`, '2000');
});

it('should reset the page to 1', (done: DoneFn) => {
Expand Down
Loading
Loading