diff --git a/__tests__/store/TableDataStore-test.js b/__tests__/store/TableDataStore-test.js index 2504700f3..df7d1f837 100644 --- a/__tests__/store/TableDataStore-test.js +++ b/__tests__/store/TableDataStore-test.js @@ -4,20 +4,16 @@ describe('TableDataStore', function() { var store; - beforeEach(function(){ - store = new TableDataStore(); - }); - - describe('_search()', function() { + describe('search() modes (strictSearch and multiColumnSearch flags)', function() { - var colInfosForModeTest = { + var colInfos = { col1: { searchable: true }, col2: { searchable: true }, col3: { searchable: true }, desc: { searchable: false } }; - var searchTextForModeTest = ' B C '; - var sourceForModeTest = [ + var searchText = ' B C '; + var data = [ { col1: 'A B C D', col2: 'E', col3: 'F', desc: 'part of the content in col1' }, { col1: 'A', col2: ' B C ', col3: 'D E F', desc: 'whole content in col2' }, { col1: 'F E D', col2: ' C B ', col3: 'A', desc: 'whole content in wrong order in col2' }, @@ -28,62 +24,77 @@ describe('TableDataStore', function() { { col1: 'A X', col2: 'X D', col3: 'E F', desc: 'completely absent' } ]; + beforeEach(function(){ + store = new TableDataStore(data); + }); + [ - { colInfos: colInfosForModeTest }, - { colInfos: colInfosForModeTest, multiColumnSearch: false }, - { colInfos: colInfosForModeTest, strictSearch: true }, - { colInfos: colInfosForModeTest, multiColumnSearch: false, strictSearch: true } + { colInfos: colInfos }, + { colInfos: colInfos, multiColumnSearch: false }, + { colInfos: colInfos, strictSearch: true }, + { colInfos: colInfos, multiColumnSearch: false, strictSearch: true } ].forEach(function(props) { it('default strict single column mode - multiColumnSearch: ' + props.multiColumnSearch + ', strictSearch: ' + props.strictSearch, function() { store.setProps(props); - store.searchText = searchTextForModeTest; - store._search(sourceForModeTest); - expect(store.filteredData).toEqual(sourceForModeTest.slice(0, 2)); + store.search(searchText); + expect(store.filteredData).toEqual(data.slice(0, 2)); }); }); [ - { colInfos: colInfosForModeTest, strictSearch: false }, - { colInfos: colInfosForModeTest, multiColumnSearch: false, strictSearch: false } + { colInfos: colInfos, strictSearch: false }, + { colInfos: colInfos, multiColumnSearch: false, strictSearch: false } ].forEach(function(props) { it('non-strict single column mode - multiColumnSearch: ' + props.multiColumnSearch + ', strictSearch: ' + props.strictSearch, function() { store.setProps(props); - store.searchText = searchTextForModeTest; - store._search(sourceForModeTest); - expect(store.filteredData).toEqual(sourceForModeTest.slice(0, 5)); + store.search(searchText); + expect(store.filteredData).toEqual(data.slice(0, 5)); }); }); [ - { colInfos: colInfosForModeTest, multiColumnSearch: true, strictSearch: true } + { colInfos: colInfos, multiColumnSearch: true, strictSearch: true } ].forEach(function(props) { it('strict multi column mode - multiColumnSearch: ' + props.multiColumnSearch + ', strictSearch: ' + props.strictSearch, function() { store.setProps(props); - store.searchText = searchTextForModeTest; - store._search(sourceForModeTest); - expect(store.filteredData).toEqual(sourceForModeTest.slice(0, 6)); + store.search(searchText); + expect(store.filteredData).toEqual(data.slice(0, 6)); }); }); [ - { colInfos: colInfosForModeTest, multiColumnSearch: true }, - { colInfos: colInfosForModeTest, multiColumnSearch: true, strictSearch: false } + { colInfos: colInfos, multiColumnSearch: true }, + { colInfos: colInfos, multiColumnSearch: true, strictSearch: false } ].forEach(function(props) { it('non-strict multi column mode - multiColumnSearch: ' + props.multiColumnSearch + ', strictSearch: ' + props.strictSearch, function() { store.setProps(props); - store.searchText = searchTextForModeTest; - store._search(sourceForModeTest); - expect(store.filteredData).toEqual(sourceForModeTest.slice(0, 7)); + store.search(searchText); + expect(store.filteredData).toEqual(data.slice(0, 7)); }); }); + }); + + describe('search() respecting formated or filter values', function() { + + var undefinedVar; + var data = [ + { col: undefinedVar}, + { col: null }, + { col: 0 }, + { col: 'A' } + ]; + + beforeEach(function(){ + store = new TableDataStore(data); + }); [ { @@ -113,20 +124,13 @@ describe('TableDataStore', function() { format: function() { return '-'; } } ].forEach(function(def) { - it('include non-values with filterValue: ' + (def.filterValue ? 'func' : def.filterValue) - + ', format: ' + (def.format ? 'func' : def.format) + it('include non-values with filterValue: ' + def.filterValue + ', format: ' + def.format + ', filterFormatted: ' + def.filterFormatted, function() { store.setProps({ colInfos: { col: def } }); - store.searchText = 'X'; - var undefinedVar; - - store._search([ - { col: undefinedVar}, - { col: null }, - { col: 0 }, - { col: 'A' } - ]); + + store.search('X'); expect(store.filteredData.length).toBe(4); + expect(store.filteredData).toEqual(data); }); }); });