Skip to content

Commit

Permalink
fix(filters): string <> should be Not Contains instead of Not Equal (#…
Browse files Browse the repository at this point in the history
…709)

* fix(filters): string <> should be Not Contains instead of Not Equal
- prefixing a text search with `<>` should be equivalent to "Not Contains" instead of "Not Equal", we can keep the `!=` as "Not Equal" so this way we have both available

* tests: keep jquery 3.5.1 to fix failing Cypress test
  • Loading branch information
ghiscoding committed Mar 5, 2021
1 parent e24c6de commit e50a060
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 52 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"excel-builder-webpacker": "^1.0.6",
"flatpickr": "^4.6.9",
"font-awesome": "^4.7.0",
"jquery": "^3.5.1",
"jquery": "~3.5.1",
"jquery-ui-dist": "^1.12.1",
"moment-mini": "^2.24.0",
"rxjs": "^6.3.3",
Expand Down Expand Up @@ -177,4 +177,4 @@
"yargs": "^16.2.0",
"zone.js": "~0.9.1"
}
}
}
1 change: 1 addition & 0 deletions src/app/modules/angular-slickgrid/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Constants {
TEXT_LAST_UPDATE: 'Last Update',
TEXT_LESS_THAN: 'Less than',
TEXT_LESS_THAN_OR_EQUAL_TO: 'Less than or equal to',
TEXT_NOT_CONTAINS: 'Not contains',
TEXT_NOT_EQUAL_TO: 'Not equal to',
TEXT_PAGE: 'Page',
TEXT_REFRESH_DATASET: 'Refresh Dataset',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { FieldType, FilterConditionOption, OperatorType } from '../../models/index';
import { FieldType, FilterConditionOption, OperatorType, SearchTerm } from '../../models/index';
import { executeFilterConditionTest } from '../filterConditionProcesses';
import { executeStringFilterCondition, getFilterParsedText } from '../stringFilterCondition';

describe('executeStringFilterCondition method', () => {
it('should return True when no cell input value is provided which is equal to the default search term, neither search terms', () => {
const searchTerms = [];
const searchTerms: SearchTerm[] = [];
const options = { dataKey: '', operator: 'EQ', cellValue: '', fieldType: FieldType.string } as FilterConditionOption;
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
expect(output).toBe(true);
});

it('should return True when cell input value is null and is equal to the default search term, neither search terms', () => {
const searchTerms = [];
const searchTerms: SearchTerm[] = [];
const options = { dataKey: '', operator: 'EQ', cellValue: null, fieldType: FieldType.string } as FilterConditionOption;
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
expect(output).toBe(true);
Expand All @@ -25,7 +25,7 @@ describe('executeStringFilterCondition method', () => {
});

it('should return False when any cell input value is provided without any search terms', () => {
const searchTerms = [];
const searchTerms: SearchTerm[] = [];
const options = { dataKey: '', operator: 'EQ', cellValue: 'foo', fieldType: FieldType.string } as FilterConditionOption;
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
expect(output).toBe(false);
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('executeStringFilterCondition method', () => {
});

it('should return False when the cell value is equal to at least 1 of the searchTerms', () => {
const searchTerms = [];
const searchTerms: SearchTerm[] = [];
const options = { dataKey: '', operator: 'EQ', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['bar', 'foo', 'John'] } as FilterConditionOption;
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
expect(output).toBe(false);
Expand Down Expand Up @@ -94,6 +94,20 @@ describe('executeStringFilterCondition method', () => {
expect(output).toBe(true);
});

it('should return False when search term is a substring of the cell value and the operator is "<>" (not contains)', () => {
const searchTerms = ['bost'];
const options = { dataKey: '', operator: '<>', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms } as FilterConditionOption;
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
expect(output).toBe(false);
});

it('should return True when search term is a substring of the cell value and the operator is "!=" (not contains) because "!=" compares agains the entire string', () => {
const searchTerms = ['bost'];
const options = { dataKey: '', operator: '!=', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms } as FilterConditionOption;
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
expect(output).toBe(true);
});

it('should return True when input value provided starts with same substring and the operator is empty string', () => {
const searchTerms = ['abb'];
const options = { dataKey: '', operator: '', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms } as FilterConditionOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const executeStringFilterCondition: FilterCondition = ((options: FilterCo
return cellValue.startsWith(parsedSearchValue);
} else if (options.operator === '' || options.operator === OperatorType.contains) {
return (cellValue.indexOf(parsedSearchValue) > -1);
} else if (options.operator === '<>' || options.operator === OperatorType.notContains) {
return (cellValue.indexOf(parsedSearchValue) === -1);
}
return testFilterCondition(options.operator || '==', cellValue, parsedSearchValue);
}) as FilterCondition;
Expand Down

0 comments on commit e50a060

Please sign in to comment.