Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit e50a060

Browse files
authored
fix(filters): string <> should be Not Contains instead of Not Equal (#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
1 parent e24c6de commit e50a060

File tree

10 files changed

+82
-52
lines changed

10 files changed

+82
-52
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"excel-builder-webpacker": "^1.0.6",
105105
"flatpickr": "^4.6.9",
106106
"font-awesome": "^4.7.0",
107-
"jquery": "^3.5.1",
107+
"jquery": "~3.5.1",
108108
"jquery-ui-dist": "^1.12.1",
109109
"moment-mini": "^2.24.0",
110110
"rxjs": "^6.3.3",
@@ -177,4 +177,4 @@
177177
"yargs": "^16.2.0",
178178
"zone.js": "~0.9.1"
179179
}
180-
}
180+
}

src/app/modules/angular-slickgrid/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class Constants {
3434
TEXT_LAST_UPDATE: 'Last Update',
3535
TEXT_LESS_THAN: 'Less than',
3636
TEXT_LESS_THAN_OR_EQUAL_TO: 'Less than or equal to',
37+
TEXT_NOT_CONTAINS: 'Not contains',
3738
TEXT_NOT_EQUAL_TO: 'Not equal to',
3839
TEXT_PAGE: 'Page',
3940
TEXT_REFRESH_DATASET: 'Refresh Dataset',

src/app/modules/angular-slickgrid/filter-conditions/__tests__/stringFilterCondition.spec.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { FieldType, FilterConditionOption, OperatorType } from '../../models/index';
1+
import { FieldType, FilterConditionOption, OperatorType, SearchTerm } from '../../models/index';
22
import { executeFilterConditionTest } from '../filterConditionProcesses';
33
import { executeStringFilterCondition, getFilterParsedText } from '../stringFilterCondition';
44

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

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

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

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

97+
it('should return False when search term is a substring of the cell value and the operator is "<>" (not contains)', () => {
98+
const searchTerms = ['bost'];
99+
const options = { dataKey: '', operator: '<>', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms } as FilterConditionOption;
100+
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
101+
expect(output).toBe(false);
102+
});
103+
104+
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', () => {
105+
const searchTerms = ['bost'];
106+
const options = { dataKey: '', operator: '!=', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms } as FilterConditionOption;
107+
const output = executeStringFilterCondition(options, getFilterParsedText(searchTerms));
108+
expect(output).toBe(true);
109+
});
110+
97111
it('should return True when input value provided starts with same substring and the operator is empty string', () => {
98112
const searchTerms = ['abb'];
99113
const options = { dataKey: '', operator: '', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms } as FilterConditionOption;

src/app/modules/angular-slickgrid/filter-conditions/stringFilterCondition.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const executeStringFilterCondition: FilterCondition = ((options: FilterCo
2222
return cellValue.startsWith(parsedSearchValue);
2323
} else if (options.operator === '' || options.operator === OperatorType.contains) {
2424
return (cellValue.indexOf(parsedSearchValue) > -1);
25+
} else if (options.operator === '<>' || options.operator === OperatorType.notContains) {
26+
return (cellValue.indexOf(parsedSearchValue) === -1);
2527
}
2628
return testFilterCondition(options.operator || '==', cellValue, parsedSearchValue);
2729
}) as FilterCondition;

0 commit comments

Comments
 (0)