Skip to content

Commit

Permalink
fix for filter and added basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
indirectlylit committed Feb 27, 2021
1 parent 19d8b03 commit 0e55557
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/common/DocsFilter/utils.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import flow from 'lodash/flow';
import words from 'lodash/words';
import lowerCase from 'lodash/lowerCase';
import toLower from 'lodash/toLower';
import deburr from 'lodash/deburr';
import every from 'lodash/every';
import includes from 'lodash/includes';

// normalize a term
const cleanup = flow([lowerCase, deburr]);
const cleanup = flow([toLower, deburr]);

// given an input query string, return a list of search terms
export function termList(filterText) {
return words(filterText).map(cleanup);
return filterText
.split(' ')
.map(cleanup)
.filter(val => val);
}

// given a list of search terms, decide whether to match some section or page
Expand Down
18 changes: 18 additions & 0 deletions docs/common/DocsFilter/utils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { termList, matches } from './utils';

console.log(termList, matches);

test('termList', () => {
expect(termList('Term1 term2')).toEqual(['term1', 'term2']);
expect(termList('lowercase UPPERCASE')).toEqual(['lowercase', 'uppercase']);
expect(termList(' space between')).toEqual(['space', 'between']);
expect(termList(' space between')).toEqual(['space', 'between']);
expect(termList('ĜĚĔĶŜ ĝęėķś')).toEqual(['geeks', 'geeks']);
});

test('matches', () => {
expect(matches(termList('KButton'), 'KButton')).toEqual(true);
expect(matches(termList('KButton'), 'KCheckbox')).toEqual(false);

// TODO - add more complex variations
});

0 comments on commit 0e55557

Please sign in to comment.