Skip to content

Commit

Permalink
fix(search): handle many branches for search
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Tupalov authored and Dmitriy Tupalov committed May 17, 2019
1 parent 240d12b commit 3588ad2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ This library is under the work. It means, that we can do Breaking Changes during

## Install
npm install [email protected].17 --save-exact
npm install [email protected].18 --save-exact

or

yarn add [email protected].17 --exact
yarn add [email protected].18 --exact

## Demo

Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const search = memoizeByArgs((value, columns) =>
? get(row, column.name)
.toString()
.includes(value)
: false
: value
? false
: true
: false
)
)
Expand Down
11 changes: 10 additions & 1 deletion test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { search } from '../src/utils';
const dataStub = [{ a: 1 }, { a: 3 }, { a: 2 }, { a: 5 }, { a: 6 }, { a: 4 }];

describe('utils', () => {
it('should omit unattainable path', () => {
it.only('should omit unattainable path if exists search value', () => {
const expectedData = [{ a: 1 }];
expect(
search('1', [
Expand All @@ -12,4 +12,13 @@ describe('utils', () => {
])(dataStub)
).toEqual(expectedData);
});
it.only('should display all data if exists unattainable path and not exists search value', () => {
const expectedData = dataStub;
expect(
search('', [
{ name: 'a', searchable: true },
{ name: 'b', searchable: true },
])(dataStub)
).toEqual(expectedData);
});
});

0 comments on commit 3588ad2

Please sign in to comment.