Commit b8ec987c authored by Robert Knight's avatar Robert Knight

Add test case for handling of empty term lists in filter.

A difference between the existing test cases for the viewFilter service
and the actual inputs that are created by
`searchFilter#generateFacetedFilter` is that the actual input filter
object has empty term lists for fields that do not appear in the query.
Fix handling of this and add a test.
parent ed019ad6
......@@ -177,3 +177,17 @@ describe 'viewFilter', ->
result = viewFilter.filter [annotation], filters
assert.equal result.length, 1
assert.equal result[0], 1
it 'ignores filters with no terms in the query', ->
ann = { id: 1, tags: ['foo'] }
filters =
any:
terms: ['foo']
operator: 'and'
tag:
terms: []
operator: 'and'
result = viewFilter.filter [ann], filters
assert.deepEqual result, [1]
......@@ -146,7 +146,9 @@ function viewFilter(unicode) {
// Convert the input filter object into a filter tree, expanding "any"
// filters.
var fieldFilters = Object.entries(filters).map(([field, filter]) => {
var fieldFilters = Object.entries(filters).filter(([, filter]) =>
filter.terms.length > 0)
.map(([field, filter]) => {
var terms = filter.terms.map(normalize);
var termFilters;
if (field === 'any') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment