mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
74606: Search Utils test cases + test fixes
This commit is contained in:
@@ -130,7 +130,7 @@ describe('SearchFacetOptionComponent', () => {
|
|||||||
comp.addQueryParams = {};
|
comp.addQueryParams = {};
|
||||||
(comp as any).updateAddParams(selectedValues);
|
(comp as any).updateAddParams(selectedValues);
|
||||||
expect(comp.addQueryParams).toEqual({
|
expect(comp.addQueryParams).toEqual({
|
||||||
[mockFilterConfig.paramName]: [value1, value.value],
|
[mockFilterConfig.paramName]: [`${value1},${operator}`, value.value + ',equals'],
|
||||||
page: 1
|
page: 1
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -145,7 +145,7 @@ describe('SearchFacetOptionComponent', () => {
|
|||||||
comp.addQueryParams = {};
|
comp.addQueryParams = {};
|
||||||
(comp as any).updateAddParams(selectedValues);
|
(comp as any).updateAddParams(selectedValues);
|
||||||
expect(comp.addQueryParams).toEqual({
|
expect(comp.addQueryParams).toEqual({
|
||||||
[mockAuthorityFilterConfig.paramName]: [value1, `${value2},${operator}`],
|
[mockAuthorityFilterConfig.paramName]: [value1 + ',equals', `${value2},${operator}`],
|
||||||
page: 1
|
page: 1
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -208,7 +208,7 @@ describe('SearchFacetFilterComponent', () => {
|
|||||||
|
|
||||||
it('should call navigate on the router with the right searchlink and parameters', () => {
|
it('should call navigate on the router with the right searchlink and parameters', () => {
|
||||||
expect(router.navigate).toHaveBeenCalledWith(searchUrl.split('/'), {
|
expect(router.navigate).toHaveBeenCalledWith(searchUrl.split('/'), {
|
||||||
queryParams: { [mockFilterConfig.paramName]: [...selectedValues, testValue] },
|
queryParams: { [mockFilterConfig.paramName]: [...selectedValues.map((value) => `${value},equals`), testValue] },
|
||||||
queryParamsHandling: 'merge'
|
queryParamsHandling: 'merge'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
52
src/app/shared/search/search.utils.spec.ts
Normal file
52
src/app/shared/search/search.utils.spec.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { FacetValue } from './facet-value.model';
|
||||||
|
import { SearchFilterConfig } from './search-filter-config.model';
|
||||||
|
import { addOperatorToFilterValue, getFacetValueForType, stripOperatorFromFilterValue } from './search.utils';
|
||||||
|
|
||||||
|
describe('Search Utils', () => {
|
||||||
|
describe('getFacetValueForType', () => {
|
||||||
|
let facetValueWithSearchHref: FacetValue;
|
||||||
|
let facetValueWithoutSearchHref: FacetValue;
|
||||||
|
let searchFilterConfig: SearchFilterConfig;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
facetValueWithSearchHref = Object.assign(new FacetValue(), {
|
||||||
|
value: 'Value with search href',
|
||||||
|
_links: {
|
||||||
|
search: {
|
||||||
|
href: 'rest/api/search?f.otherFacet=Other facet value,operator&f.facetName=Value with search href,operator'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
facetValueWithoutSearchHref = Object.assign(new FacetValue(), {
|
||||||
|
value: 'Value without search href'
|
||||||
|
});
|
||||||
|
searchFilterConfig = Object.assign(new SearchFilterConfig(), {
|
||||||
|
name: 'facetName'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should retrieve the correct value from the search href', () => {
|
||||||
|
expect(getFacetValueForType(facetValueWithSearchHref, searchFilterConfig)).toEqual('Value with search href,operator');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the facet value with an equals operator by default', () => {
|
||||||
|
expect(getFacetValueForType(facetValueWithoutSearchHref, searchFilterConfig)).toEqual('Value without search href,equals');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('stripOperatorFromFilterValue', () => {
|
||||||
|
it('should strip the operator from the value', () => {
|
||||||
|
expect(stripOperatorFromFilterValue('value,operator')).toEqual('value');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('addOperatorToFilterValue', () => {
|
||||||
|
it('should add the operator to the value', () => {
|
||||||
|
expect(addOperatorToFilterValue('value', 'operator')).toEqual('value,operator');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shouldn\'t add the operator to the value if it already contains the operator', () => {
|
||||||
|
expect(addOperatorToFilterValue('value,operator', 'operator')).toEqual('value,operator');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user