mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Moving taxon filter to ID instead of name
This commit is contained in:
committed by
Rohan Mitchell
parent
8b98c72336
commit
e858c0d434
@@ -1,10 +1,8 @@
|
||||
Darkswarm.filter 'taxons', (Matcher)->
|
||||
# Filter anything that responds to object.taxons, and/or object.primary_taxon
|
||||
(objects, text) ->
|
||||
(objects, id) ->
|
||||
objects ||= []
|
||||
text ?= ""
|
||||
id ?= 0
|
||||
objects.filter (obj)->
|
||||
Matcher.match([obj.primary_taxon?.name || ""], text) || obj.taxons.some (taxon)->
|
||||
Matcher.match [taxon.name], text
|
||||
|
||||
|
||||
obj.primary_taxon?.id == id || obj.taxons.some (taxon)->
|
||||
taxon.id == id
|
||||
|
||||
@@ -5,11 +5,12 @@ describe 'filtering by taxons', ->
|
||||
taxons: []
|
||||
primary_taxon:
|
||||
name: "frogs"
|
||||
id: 1
|
||||
}
|
||||
{
|
||||
taxons: [
|
||||
{name: "kittens"}
|
||||
{name: "puppies"}
|
||||
{name: "kittens", id: 2}
|
||||
{name: "puppies", id: 3}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -21,7 +22,9 @@ describe 'filtering by taxons', ->
|
||||
filterByTaxons = $filter('taxons')
|
||||
|
||||
it "filters by primary taxon", ->
|
||||
expect(filterByTaxons(objects, "frogs")[0]).toBe objects[0]
|
||||
expect(filterByTaxons(objects, 1)[0]).toBe objects[0]
|
||||
|
||||
it "filters by taxons", ->
|
||||
expect(filterByTaxons(objects, "kittens")[0]).toBe objects[1]
|
||||
expect(filterByTaxons(objects, 2)[0]).toBe objects[1]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user