diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts index 4f85411d85..ba6eceeede 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter-options/search-facet-option/search-facet-option.component.spec.ts @@ -130,7 +130,7 @@ describe('SearchFacetOptionComponent', () => { comp.addQueryParams = {}; (comp as any).updateAddParams(selectedValues); expect(comp.addQueryParams).toEqual({ - [mockFilterConfig.paramName]: [value1, value.value], + [mockFilterConfig.paramName]: [`${value1},${operator}`, value.value + ',equals'], page: 1 }); }); @@ -145,7 +145,7 @@ describe('SearchFacetOptionComponent', () => { comp.addQueryParams = {}; (comp as any).updateAddParams(selectedValues); expect(comp.addQueryParams).toEqual({ - [mockAuthorityFilterConfig.paramName]: [value1, `${value2},${operator}`], + [mockAuthorityFilterConfig.paramName]: [value1 + ',equals', `${value2},${operator}`], page: 1 }); }); diff --git a/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts b/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts index 376aa7ba3a..54548b0ddf 100644 --- a/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts +++ b/src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts @@ -208,7 +208,7 @@ describe('SearchFacetFilterComponent', () => { it('should call navigate on the router with the right searchlink and parameters', () => { expect(router.navigate).toHaveBeenCalledWith(searchUrl.split('/'), { - queryParams: { [mockFilterConfig.paramName]: [...selectedValues, testValue] }, + queryParams: { [mockFilterConfig.paramName]: [...selectedValues.map((value) => `${value},equals`), testValue] }, queryParamsHandling: 'merge' }); }); diff --git a/src/app/shared/search/search.utils.spec.ts b/src/app/shared/search/search.utils.spec.ts new file mode 100644 index 0000000000..a14085c2d3 --- /dev/null +++ b/src/app/shared/search/search.utils.spec.ts @@ -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'); + }); + }); +});