mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Refactor code by suggestion to use RegExp and add tests coverage
This commit is contained in:
committed by
Rob Harrington
parent
7a07e8fa16
commit
a1ffc869f3
@@ -0,0 +1,54 @@
|
||||
describe 'Matcher service', ->
|
||||
Matcher = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
inject ($injector)->
|
||||
Matcher = $injector.get("Matcher")
|
||||
|
||||
describe '#match', ->
|
||||
it "matches full word", ->
|
||||
expect(Matcher.match ["product_name"], "product_name").toEqual true
|
||||
|
||||
it "matches second word", ->
|
||||
expect(Matcher.match ["product_name", 'variant'], "variant").toEqual true
|
||||
|
||||
it "matches word with underscore", ->
|
||||
expect(Matcher.match ["product_name"], "ct_na").toEqual true
|
||||
|
||||
it "matches word if property has two words", ->
|
||||
expect(Matcher.match ["product name"], "nam").toEqual true
|
||||
|
||||
it "matches word with dash", ->
|
||||
expect(Matcher.match ["product-name"], "ct-na").toEqual true
|
||||
|
||||
it "finds in any part of properties", ->
|
||||
expect(Matcher.match ["keyword"], "word").toEqual true
|
||||
|
||||
it "finds beginning of property", ->
|
||||
expect(Matcher.match ["keyword"], "key").toEqual true
|
||||
|
||||
it "doesn't find non-sense or mistypes", ->
|
||||
expect(Matcher.match ["keyword"], "keywrd").toEqual false
|
||||
|
||||
describe '#matchBeginning', ->
|
||||
it "matches full word", ->
|
||||
expect(Matcher.matchBeginning ["product_name"], "product_name").toEqual true
|
||||
|
||||
it "matches second word", ->
|
||||
expect(Matcher.matchBeginning ["product_name", 'variant'], "variant").toEqual true
|
||||
|
||||
it "matches word if property has two words", ->
|
||||
expect(Matcher.matchBeginning ["product name"], "nam").toEqual true
|
||||
|
||||
it "matches second part of word separated by dash", ->
|
||||
expect(Matcher.matchBeginning ["product-name"], "name").toEqual true
|
||||
|
||||
it "matches beginning of property", ->
|
||||
expect(Matcher.matchBeginning ["keyword"], "key").toEqual true
|
||||
|
||||
it "doesn't match in any part of property", ->
|
||||
expect(Matcher.matchBeginning ["keyword"], "word").toEqual false
|
||||
|
||||
it "doesn't match non-sense or mistypes", ->
|
||||
expect(Matcher.matchBeginning ["keyword"], "keywrd").toEqual false
|
||||
Reference in New Issue
Block a user