Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filters): filtering with IN_CONTAINS should also work with spaces #368

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ describe('filterUtilities', () => {
expect(output).toBeTruthy();
});

it('should return True when value1 is "IN_CONTAINS" value2 collection even if there is extra spaces in the string', () => {
const output = testFilterCondition('IN_CONTAINS', 'Task2, Task3 ', ['Task2', 'Task3']);
expect(output).toBeTruthy();
});

it('should return False when value1 is not "IN_CONTAINS" value2 collection', () => {
const output = testFilterCondition('IN_CONTAINS', 'Task11,Task4', ['Task 1', 'Task2', 'Task3']);
expect(output).toBeFalsy();
Expand All @@ -212,7 +217,15 @@ describe('filterUtilities', () => {
expect(output1).toBeFalsy();
expect(output2).toBeFalsy();
});


it('should return False when value1 is not "NOT_IN_CONTAINS" value2 collection even if there is extra spaces in the string', () => {
const output1 = testFilterCondition('NIN_CONTAINS', 'Task2, Task3 ', ['Task2', 'Task3']);
const output2 = testFilterCondition('NOT_IN_CONTAINS', 'Task2, Task3', ['Task2', 'Task3']);

expect(output1).toBeFalsy();
expect(output2).toBeFalsy();
});

it('should return False when value2 is not a collection', () => {
const output = testFilterCondition('NOT_IN_CONTAINS', 'Task2,Task3', 'Task2');
expect(output).toBeFalsy();
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/filter-conditions/filterUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export const testFilterCondition = (operator: OperatorString, value1: any, value
return ((value2 && Array.isArray(value2 as string[])) ? (!value2.includes(value1)) : false);
case 'IN_CONTAINS':
if (value2 && Array.isArray(value2) && typeof value1 === 'string') {
return value2.some(item => value1.split(/[\s,]+/).includes(item));
return value2.some(item => value1.split(/[\s,]+/).map(val => (val.trim())).includes(item));
}
return false;
case 'NIN_CONTAINS':
case 'NOT_IN_CONTAINS':
if (value2 && Array.isArray(value2) && typeof value1 === 'string') {
return !value2.some(item => value1.split(/[\s,]+/).includes(item));
return !value2.some(item => value1.split(/[\s,]+/).map(val => (val.trim())).includes(item));
}
return false;
case 'IN_COLLECTION':
Expand Down