74606: Search Utils test cases + test fixes

This commit is contained in:
Kristof De Langhe
2020-11-17 15:43:05 +01:00
parent 6f9e8bd3bf
commit 05406e6919
3 changed files with 55 additions and 3 deletions

View File

@@ -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
});
});

View File

@@ -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'
});
});

View 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');
});
});
});