From 3588ad2ac76d3ffa9b20a658c27a5a95cb4158bc Mon Sep 17 00:00:00 2001 From: Dmitriy Tupalov Date: Fri, 17 May 2019 17:00:04 +0300 Subject: [PATCH] fix(search): handle many branches for search --- README.md | 4 ++-- src/utils.js | 4 +++- test/utils.test.js | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2824920..ab967f6 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ This library is under the work. It means, that we can do Breaking Changes during ## Install - npm install react-material-ui-datatable@2.0.0-alpha.17 --save-exact + npm install react-material-ui-datatable@2.0.0-alpha.18 --save-exact or - yarn add react-material-ui-datatable@2.0.0-alpha.17 --exact + yarn add react-material-ui-datatable@2.0.0-alpha.18 --exact ## Demo diff --git a/src/utils.js b/src/utils.js index f4585b0..f9065c5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -27,7 +27,9 @@ export const search = memoizeByArgs((value, columns) => ? get(row, column.name) .toString() .includes(value) - : false + : value + ? false + : true : false ) ) diff --git a/test/utils.test.js b/test/utils.test.js index c5c3cc4..8f2020a 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -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', [ @@ -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); + }); });