From a58de9e18981388002536bfee20b4b08d4f025c6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 11 Oct 2018 21:04:50 +0100 Subject: [PATCH] Also test the two options while we're at it --- test/autocomplete/QueryMatcher-test.js | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/autocomplete/QueryMatcher-test.js b/test/autocomplete/QueryMatcher-test.js index d461279614..864e1da81d 100644 --- a/test/autocomplete/QueryMatcher-test.js +++ b/test/autocomplete/QueryMatcher-test.js @@ -26,6 +26,11 @@ const OBJECTS = [ { name: "Victoria", nick: "Posh" }, ]; +const NONWORDOBJECTS = [ + { name: "B.O.B" }, + { name: "bob" }, +]; + describe('QueryMatcher', function() { it('Returns results by key', function() { const qm = new QueryMatcher(OBJECTS, {keys: ["name"]}); @@ -133,4 +138,38 @@ describe('QueryMatcher', function() { expect(results[1].name).toBe('Mel C'); expect(results[2].name).toBe('Emma'); }); + + it('Matches words only by default', function() { + const qm = new QueryMatcher(NONWORDOBJECTS, { keys: ["name"] }); + + const results = qm.match('bob'); + expect(results.length).toBe(2); + expect(results[0].name).toBe('B.O.B'); + expect(results[1].name).toBe('bob'); + }); + + it('Matches all chars with words-only off', function() { + const qm = new QueryMatcher(NONWORDOBJECTS, { + keys: ["name"], + shouldMatchWordsOnly: false, + }); + + const results = qm.match('bob'); + expect(results.length).toBe(1); + expect(results[0].name).toBe('bob'); + }); + + it('Matches only by prefix with shouldMatchPrefix on', function() { + const qm = new QueryMatcher([ + {name: "Victoria"}, + {name: "Tori"}, + ], { + keys: ["name"], + shouldMatchPrefix: true, + }); + + const results = qm.match('tori'); + expect(results.length).toBe(1); + expect(results[0].name).toBe('Tori'); + }); });