Skip to content

Commit

Permalink
Test search() instead of _search()
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenWickner committed Apr 14, 2017
1 parent f392605 commit 246a7fa
Showing 1 changed file with 44 additions and 40 deletions.
84 changes: 44 additions & 40 deletions __tests__/store/TableDataStore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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);
});

[
{
Expand Down Expand Up @@ -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);
});
});
});
Expand Down

0 comments on commit 246a7fa

Please sign in to comment.