|
| 1 | +/* eslint-env mocha */ |
| 2 | +import {assert} from 'chai'; |
| 3 | +import AutoComplete from './AutoComplete'; |
| 4 | + |
| 5 | +describe('<AutoComplete />', () => { |
| 6 | + it('search using fuzzy filter', () => { |
| 7 | + assert.strictEqual(AutoComplete.fuzzyFilter('ea', 'Peach'), true, 'should match Peach with ea'); |
| 8 | + assert.strictEqual(AutoComplete.fuzzyFilter('pah', 'Peach'), true, 'should match Peach with pah'); |
| 9 | + assert.strictEqual(AutoComplete.fuzzyFilter('peach', 'Peach'), true, 'should match Peach with peach'); |
| 10 | + |
| 11 | + assert.strictEqual(AutoComplete.fuzzyFilter('phc', 'Peach'), false, 'should not match Peach with phc'); |
| 12 | + assert.strictEqual(AutoComplete.fuzzyFilter('pp', 'Peach'), false, 'should not match Peach with pp'); |
| 13 | + assert.strictEqual(AutoComplete.fuzzyFilter('pb', 'Peach'), false, 'should not match Peach with pb'); |
| 14 | + |
| 15 | + // testing longer string |
| 16 | + const test_string = 'The best thing about a Boolean is even if you are wrong, you are only off by a bit.'; |
| 17 | + |
| 18 | + let search_result = AutoComplete.fuzzyFilter('bOOLEAN', test_string); |
| 19 | + assert.strictEqual(search_result, true, 'should match with case insensitive'); |
| 20 | + |
| 21 | + search_result = AutoComplete.fuzzyFilter('The a Boolean if wrong', test_string); |
| 22 | + assert.strictEqual(search_result, true, 'should match pattern with spaces'); |
| 23 | + |
| 24 | + search_result = AutoComplete.fuzzyFilter(' if ,bit.', test_string); |
| 25 | + assert.strictEqual(search_result, true, 'should match pattern with comma and period'); |
| 26 | + |
| 27 | + search_result = AutoComplete.fuzzyFilter('the best q', test_string); |
| 28 | + assert.strictEqual(search_result, false, 'should not match pattern with letter is not contained in search text'); |
| 29 | + |
| 30 | + search_result = AutoComplete.fuzzyFilter('off bit by', 'off by a bit'); |
| 31 | + assert.strictEqual(search_result, false, 'should not match pattern when can not find letters in order '); |
| 32 | + }); |
| 33 | +}); |
0 commit comments