});
describe('test search', () => {
- const doSearch = (search: string, expectedLength: number, firstObject: object) => {
+ const doSearch = (search: string, expectedLength: number, firstObject?: object) => {
component.search = search;
component.updateFilter();
expect(component.rows.length).toBe(expectedLength);
- expect(component.rows[0]).toEqual(firstObject);
+ if (firstObject) {
+ expect(component.rows[0]).toEqual(firstObject);
+ }
};
it('should search for 13', () => {
doSearch('poker+array:score21', 6, { a: 15, b: 225, c: [-5, 'score21'], d: false });
});
- it('should not search if column name is incomplete', () => {
- doSearch(`'poker array'`, 100, { a: 0, b: 0, c: [-0, 'score6'], d: true });
- doSearch('pok', 100, { a: 0, b: 0, c: [-0, 'score6'], d: true });
- doSearch('pok:', 100, { a: 0, b: 0, c: [-0, 'score6'], d: true });
+ it('should search if column name is incomplete', () => {
+ doSearch(`'poker array'`, 0);
+ doSearch('pok', 0);
+ doSearch('pok:', 100);
});
it('should restore full table after search', () => {
.replace('+', ' ')
.split(':');
const columnsClone = [...columns];
- const dataClone = [...data];
- const filterColumns = (columnName: string) =>
- columnsClone.filter((c) => c.name.toLowerCase().indexOf(columnName) !== -1);
if (searchTerms.length === 2) {
- columns = filterColumns(searchTerms[0]);
+ columns = columnsClone.filter((c) => c.name.toLowerCase().indexOf(searchTerms[0]) !== -1);
}
- const searchTerm: string = _.last(searchTerms);
- data = this.basicDataSearch(searchTerm, data, columns);
+ data = this.basicDataSearch(_.last(searchTerms), data, columns);
// Checks if user searches for column but he is still typing
- if (data.length === 0 && searchTerms.length === 1 && filterColumns(searchTerm).length > 0) {
- data = dataClone;
- }
return this.subSearch(data, currentSearch, columnsClone);
}