From 8ce46b501b1e437d9058023b1509ff678282f2fe Mon Sep 17 00:00:00 2001 From: rosensama Date: Sun, 8 Jan 2017 21:07:41 -0600 Subject: [PATCH 1/3] defaultColumnFilter now tests for a null value before attempting to call .toString() on it fixes GriddleGriddle/Griddle #545 --- scripts/__tests__/griddle-test.js | 21 +++++++++++++++++++++ scripts/griddle.jsx | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/scripts/__tests__/griddle-test.js b/scripts/__tests__/griddle-test.js index 885a80d7..142a3674 100644 --- a/scripts/__tests__/griddle-test.js +++ b/scripts/__tests__/griddle-test.js @@ -13,6 +13,7 @@ var SomeCustomComponent = React.createClass({ describe('Griddle', function() { var fakeData; var fakeData2; + var fakeData3; var grid; var multipleSelectOptions; @@ -109,6 +110,21 @@ describe('Griddle', function() { "favoriteNumber": 2 } ]; + + fakeData3 = [ + { + "id": 2, + "name": null, + "address": { + "city": null, + "state": null + }, + "country": null, + "company": null, + "favoriteNumber": -1 + } + ]; + grid = TestUtils.renderIntoDocument(); }); @@ -154,6 +170,11 @@ describe('Griddle', function() { expect(grid.state.filteredResults.length).toEqual(1); }); + it('correctly handles a null value in defaultColumnFilter', function(){ + const test = grid.defaultColumnFilter(null, 'May'); + expect(test).toEqual(false); + }); + it('sets the filteredResults when filterByColumn called on object field', function(){ grid.filterByColumn('Hawaii', 'address'); expect(grid.state.filteredResults.length).toEqual(1); diff --git a/scripts/griddle.jsx b/scripts/griddle.jsx index 4af18c47..86a327ba 100644 --- a/scripts/griddle.jsx +++ b/scripts/griddle.jsx @@ -166,7 +166,9 @@ var Griddle = React.createClass({ defaultColumnFilter(value, filter) { return _filter(deep.getObjectValues(value), function(value) { - return value.toString().toLowerCase().indexOf(filter.toLowerCase()) >= 0; + if (value !== null && value.toString) { + return value.toString().toLowerCase().indexOf(filter.toLowerCase()) >= 0; + } }).length > 0; }, From 2b1243fe81412f5a2b6f080705d0102e9e21c82d Mon Sep 17 00:00:00 2001 From: rosensama Date: Sun, 8 Jan 2017 21:12:41 -0600 Subject: [PATCH 2/3] remove unnecessary test fixture --- scripts/__tests__/griddle-test.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/scripts/__tests__/griddle-test.js b/scripts/__tests__/griddle-test.js index 142a3674..b839d81e 100644 --- a/scripts/__tests__/griddle-test.js +++ b/scripts/__tests__/griddle-test.js @@ -13,7 +13,6 @@ var SomeCustomComponent = React.createClass({ describe('Griddle', function() { var fakeData; var fakeData2; - var fakeData3; var grid; var multipleSelectOptions; @@ -111,20 +110,6 @@ describe('Griddle', function() { } ]; - fakeData3 = [ - { - "id": 2, - "name": null, - "address": { - "city": null, - "state": null - }, - "country": null, - "company": null, - "favoriteNumber": -1 - } - ]; - grid = TestUtils.renderIntoDocument(); }); From e77e5f1e746e21833f74e31796d7e21a86ed0f85 Mon Sep 17 00:00:00 2001 From: rosensama Date: Sun, 8 Jan 2017 21:13:51 -0600 Subject: [PATCH 3/3] Remove unnecessary new white space --- scripts/__tests__/griddle-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/__tests__/griddle-test.js b/scripts/__tests__/griddle-test.js index b839d81e..a6880eac 100644 --- a/scripts/__tests__/griddle-test.js +++ b/scripts/__tests__/griddle-test.js @@ -109,7 +109,6 @@ describe('Griddle', function() { "favoriteNumber": 2 } ]; - grid = TestUtils.renderIntoDocument(); });