This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(toggleRefinement): keep an empty array when clearing (#738)
* fix(toggleRefinement): keep an empty array when clearing When clearing a refinement using `toggleRefinement` we want to keep the empty refinement object for that attribute, because we use it to override a deeper refinement of that attribute in IS.js with federated search * chore: add additional tests & fix for numeric * consequences * chore: add comment
- Loading branch information
Showing
9 changed files
with
413 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,304 @@ | ||
'use strict'; | ||
|
||
var SearchParameters = require('../../../src/SearchParameters'); | ||
|
||
describe('removeDisjunctiveFacetRefinement', function() { | ||
test('removeDisjunctiveFacetRefinement(attribute)', function() { | ||
var state = new SearchParameters({ | ||
disjunctiveFacets: ['attribute'], | ||
disjunctiveFacetsRefinements: { | ||
attribute: ['value'] | ||
} | ||
}); | ||
|
||
expect(state.removeDisjunctiveFacetRefinement('attribute')).toEqual( | ||
new SearchParameters({ | ||
disjunctiveFacets: ['attribute'], | ||
disjunctiveFacetsRefinements: { | ||
attribute: [] | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeDisjunctiveFacetRefinement(attribute, value)', function() { | ||
var state = new SearchParameters({ | ||
disjunctiveFacets: ['attribute'], | ||
disjunctiveFacetsRefinements: { | ||
attribute: ['value', 'value2'] | ||
} | ||
}); | ||
|
||
expect(state.removeDisjunctiveFacetRefinement('attribute', 'value')).toEqual( | ||
new SearchParameters({ | ||
disjunctiveFacets: ['attribute'], | ||
disjunctiveFacetsRefinements: { | ||
attribute: ['value2'] | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeDisjunctiveFacetRefinement(attribute, lastValue)', function() { | ||
var state = new SearchParameters({ | ||
disjunctiveFacets: ['attribute'], | ||
disjunctiveFacetsRefinements: { | ||
attribute: ['value'] | ||
} | ||
}); | ||
|
||
expect(state.removeDisjunctiveFacetRefinement('attribute', 'value')).toEqual( | ||
new SearchParameters({ | ||
disjunctiveFacets: ['attribute'], | ||
disjunctiveFacetsRefinements: { | ||
attribute: [] | ||
} | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('removeFacetRefinement', function() { | ||
test('removeFacetRefinement(attribute)', function() { | ||
var state = new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsRefinements: { | ||
attribute: ['value'] | ||
} | ||
}); | ||
|
||
expect(state.removeFacetRefinement('attribute')).toEqual( | ||
new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsRefinements: { | ||
attribute: [] | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeFacetRefinement(attribute, value)', function() { | ||
var state = new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsRefinements: { | ||
attribute: ['value', 'value2'] | ||
} | ||
}); | ||
|
||
expect(state.removeFacetRefinement('attribute', 'value')).toEqual( | ||
new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsRefinements: { | ||
attribute: ['value2'] | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeFacetRefinement(attribute, lastValue)', function() { | ||
var state = new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsRefinements: { | ||
attribute: ['value'] | ||
} | ||
}); | ||
|
||
expect(state.removeFacetRefinement('attribute', 'value')).toEqual( | ||
new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsRefinements: { | ||
attribute: [] | ||
} | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('removeExcludeRefinement', function() { | ||
test('removeExcludeRefinement(attribute)', function() { | ||
var state = new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsExcludes: { | ||
attribute: ['value'] | ||
} | ||
}); | ||
|
||
expect(state.removeExcludeRefinement('attribute')).toEqual( | ||
new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsExcludes: { | ||
attribute: [] | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeExcludeRefinement(attribute, value)', function() { | ||
var state = new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsExcludes: { | ||
attribute: ['value', 'value2'] | ||
} | ||
}); | ||
|
||
expect(state.removeExcludeRefinement('attribute', 'value')).toEqual( | ||
new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsExcludes: { | ||
attribute: ['value2'] | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeExcludeRefinement(attribute, lastValue)', function() { | ||
var state = new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsExcludes: { | ||
attribute: ['value'] | ||
} | ||
}); | ||
|
||
expect(state.removeExcludeRefinement('attribute', 'value')).toEqual( | ||
new SearchParameters({ | ||
facets: ['attribute'], | ||
facetsExcludes: { | ||
attribute: [] | ||
} | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('removeTagRefinement', function() { | ||
test('removeTagRefinement(tag)', function() { | ||
var state = new SearchParameters({ | ||
tagRefinements: ['tag', 'tag2'] | ||
}); | ||
|
||
expect(state.removeTagRefinement('tag')).toEqual( | ||
new SearchParameters({ | ||
tagRefinements: ['tag2'] | ||
}) | ||
); | ||
}); | ||
|
||
test('removeTagRefinement(lastTag)', function() { | ||
var state = new SearchParameters({ | ||
tagRefinements: ['lastTag'] | ||
}); | ||
|
||
expect(state.removeTagRefinement('lastTag')).toEqual( | ||
new SearchParameters({ | ||
tagRefinements: [] | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('removeHierarchicalFacetRefinement', function() { | ||
// NOTE: removeHierarchicalFacetRefinement only allows to remove a whole attribute | ||
test('removeHierarchicalFacetRefinement(attribute)', function() { | ||
var state = new SearchParameters({ | ||
hierarchicalFacets: [{name: 'attribute'}], | ||
hierarchicalFacetsRefinements: { | ||
attribute: ['value', 'value2'] | ||
} | ||
}); | ||
|
||
expect(state.removeHierarchicalFacetRefinement('attribute')).toEqual( | ||
new SearchParameters({ | ||
hierarchicalFacets: [{name: 'attribute'}], | ||
hierarchicalFacetsRefinements: { | ||
attribute: [] | ||
} | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('removeNumericRefinement', function() { | ||
test('removeNumericRefinement(attribute)', function() { | ||
var state = new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'>=': [100] | ||
} | ||
} | ||
}); | ||
|
||
expect(state.removeNumericRefinement('attribute')).toEqual( | ||
new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'>=': [] | ||
} | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeNumericRefinement(attribute, operator)', function() { | ||
var state = new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'>=': [100] | ||
} | ||
} | ||
}); | ||
|
||
expect(state.removeNumericRefinement('attribute', '>=')).toEqual( | ||
new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'>=': [] | ||
} | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeNumericRefinement(attribute, operator, value)', function() { | ||
var state = new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'<': [100], | ||
'>=': [100, 200] | ||
} | ||
} | ||
}); | ||
|
||
expect(state.removeNumericRefinement('attribute', '>=', 100)).toEqual( | ||
new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'<': [100], | ||
'>=': [200] | ||
} | ||
} | ||
}) | ||
); | ||
}); | ||
|
||
test('removeNumericRefinement(attribute, operator, lastValue)', function() { | ||
var state = new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'<': [100], | ||
'>=': [100, 200] | ||
} | ||
} | ||
}); | ||
|
||
expect(state.removeNumericRefinement('attribute', '<', 100)).toEqual( | ||
new SearchParameters({ | ||
numericRefinements: { | ||
attribute: { | ||
'<': [], | ||
'>=': [100, 200] | ||
} | ||
} | ||
}) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.