-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filter): add Filter Service, Filter Conditions and few unit tests
- Loading branch information
1 parent
30af496
commit 2baed7f
Showing
61 changed files
with
9,409 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum GridAutosizeColsMode { | ||
none = 'NOA', | ||
legacyOff = 'LOF', | ||
legacyForceFit = 'LFF', | ||
ignoreViewport = 'IGV', | ||
fitColsToViewport = 'FCV', | ||
fitViewportToCols = 'FVC' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/common/src/filter-conditions/__tests__/booleanFilterCondition.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { FieldType } from '../../enums/index'; | ||
import { FilterConditionOption } from '../../interfaces/index'; | ||
import { booleanFilterCondition } from '../booleanFilterCondition'; | ||
import { executeMappedCondition } from '../executeMappedCondition'; | ||
|
||
/** will return True in all cases with only 1 exception when the only searchTerm is inversed to the cell value */ | ||
|
||
describe('booleanFilterCondition method', () => { | ||
it('should return True when no cell value is provided, neither search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: '', fieldType: FieldType.boolean } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when any cell value is provided', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'foo', fieldType: FieldType.boolean } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when boolean value True is provided as cell value and called from the "executeMappedCondition"', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'true', fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when boolean value True is provided as cell value', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'true', fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when boolean value provided is equal to the searchTerms even when it is a string type', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: true, fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when the cell value is equal to at least 1 of the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: true, fieldType: FieldType.boolean, searchTerms: ['true', 'false'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when cell value is inversed to the searchTerm', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: false, fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when Operator is Not Equal because condition is always a strict equal check', () => { | ||
const options = { dataKey: '', operator: 'NE', cellValue: false, fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
packages/common/src/filter-conditions/__tests__/collectionSearchFilterCondition.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { FieldType } from '../../enums/index'; | ||
import { FilterConditionOption } from '../../interfaces/index'; | ||
import { collectionSearchFilterCondition } from '../collectionSearchFilterCondition'; | ||
import { executeMappedCondition } from '../executeMappedCondition'; | ||
|
||
describe('collectionSearchFilterCondition method', () => { | ||
it('should return False when searchTerms is empty', () => { | ||
const options = { dataKey: '', operator: 'IN', cellValue: 3, fieldType: FieldType.string } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value is in the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'IN', cellValue: 3, fieldType: FieldType.string, searchTerms: ['3'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when input value provided is equal to the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'IN', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['foo'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when input value provided is equal to the searchTerms even though there are no Operator provided (it will use EQ as default)', () => { | ||
const options = { dataKey: '', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['foo'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when the cell value is equal to at least 1 of the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'IN', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['bar', 'foo', 'John'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when the cell value is equal to at least 1 of the searchTerms and called by the "executeMappedCondition"', () => { | ||
const options = { dataKey: '', operator: 'IN', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['bar', 'foo', 'John'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when cell value is not within the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'IN', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['bar'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when Operator is Not IN because condition is always a strict equal check', () => { | ||
const options = { dataKey: '', operator: 'NOT_IN', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['foo'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when Operator is NIN because condition is always a strict equal check', () => { | ||
const options = { dataKey: '', operator: 'NIN', cellValue: 'foo', fieldType: FieldType.string, searchTerms: ['foo'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value contains searchTerms content', () => { | ||
const options = { dataKey: '', operator: 'IN_CONTAINS', cellValue: 'Task2,Task3', fieldType: FieldType.string, searchTerms: ['Task2', 'Task3'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when input value not in contains searchTerms content', () => { | ||
const options = { dataKey: '', operator: 'NIN_CONTAINS', cellValue: 'Task2,Task3', fieldType: FieldType.string, searchTerms: ['Task2', 'Task3'] } as FilterConditionOption; | ||
const output = collectionSearchFilterCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
packages/common/src/filter-conditions/__tests__/dateEuroFilterCondition.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { FieldType } from '../../enums/index'; | ||
import { FilterConditionOption } from '../../interfaces/index'; | ||
import { executeMappedCondition } from '../executeMappedCondition'; | ||
|
||
describe('dateEuroFilterCondition method', () => { | ||
it('should return False when no cell value is provided, neither search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuro, cellValue: '' } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when any cell value is provided without any search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuro, cellValue: '25/12/2000' } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when search term is not a valid date', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuro, cellValue: '25/12/2000', searchTerms: ['14/25/2000'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value provided is equal to the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuro, cellValue: '25/12/1993', searchTerms: ['25/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when cell value is not the same value as the searchTerm', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuro, cellValue: '25/12/1993', searchTerms: ['14/03/2003'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when the cell value is found in the searchTerms since it only compares first term', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuro, cellValue: '25/12/1993', searchTerms: ['14/03/2003', '25/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when Operator is Not Equal and cell value equals the search term', () => { | ||
const options = { dataKey: '', operator: 'NE', fieldType: FieldType.dateEuro, cellValue: '25/12/1993', searchTerms: ['25/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True even when Operator is Not Equal and cell value is different than the search term', () => { | ||
const options = { dataKey: '', operator: 'NE', fieldType: FieldType.dateEuro, cellValue: '25/12/1993', searchTerms: ['25/12/2002'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when there are no search term and no operator', () => { | ||
const options = { dataKey: '', fieldType: FieldType.dateEuro, cellValue: '25/12/1993', searchTerms: [null] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when search and cell values are different and there are no operator passed, it will use default EQ operator', () => { | ||
const options = { dataKey: '', fieldType: FieldType.dateEuro, cellValue: '25/12/1993', searchTerms: ['27/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value is in the range of search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: '25/12/1993', fieldType: FieldType.dateEuro, searchTerms: ['01/12/1993..31/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when input value is not in the range of search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: '25/11/1993', fieldType: FieldType.dateEuro, searchTerms: ['01/12/1993..31/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value equals the search terms min inclusive value and operator is set to "rangeInclusive"', () => { | ||
const options = { dataKey: '', operator: 'RangeInclusive', cellValue: '01/12/1993', fieldType: FieldType.dateEuro, searchTerms: ['01/12/1993..31/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when input value equals the search terms min inclusive value and operator is set to "RangeExclusive"', () => { | ||
const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '01/12/1993', fieldType: FieldType.dateEuro, searchTerms: ['01/12/1993..31/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when any of the 2 search term value is not a valid date', () => { | ||
const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '05/12/1993', fieldType: FieldType.dateEuro, searchTerms: ['01/12/1993..60/12/1993'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
packages/common/src/filter-conditions/__tests__/dateEuroShortFilterCondition.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { FieldType } from '../../enums/index'; | ||
import { FilterConditionOption } from '../../interfaces/index'; | ||
import { executeMappedCondition } from '../executeMappedCondition'; | ||
|
||
describe('dateEuroShortFilterCondition method', () => { | ||
it('should return False when no cell value is provided, neither search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuroShort, cellValue: '' } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when any cell value is provided without any search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuroShort, cellValue: '25/12/00' } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when search term is not a valid date', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuroShort, cellValue: '25/12/00', searchTerms: ['14/25/00'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value provided is equal to the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuroShort, cellValue: '25/12/93', searchTerms: ['25/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when cell value is not the same value as the searchTerm', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuroShort, cellValue: '25/12/93', searchTerms: ['14/03/03'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when the cell value is found in the searchTerms since it only compares first term', () => { | ||
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateEuroShort, cellValue: '25/12/93', searchTerms: ['14/03/2003', '25/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when Operator is Not Equal and cell value equals the search term', () => { | ||
const options = { dataKey: '', operator: 'NE', fieldType: FieldType.dateEuroShort, cellValue: '25/12/93', searchTerms: ['25/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True even when Operator is Not Equal and cell value is different than the search term', () => { | ||
const options = { dataKey: '', operator: 'NE', fieldType: FieldType.dateEuroShort, cellValue: '25/12/93', searchTerms: ['25/12/02'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when there are no search term and no operator', () => { | ||
const options = { dataKey: '', fieldType: FieldType.dateEuroShort, cellValue: '25/12/93', searchTerms: [null] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when search and cell values are different and there are no operator passed, it will use default EQ operator', () => { | ||
const options = { dataKey: '', fieldType: FieldType.dateEuroShort, cellValue: '25/12/93', searchTerms: ['27/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value is in the range of search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: '25/12/93', fieldType: FieldType.dateEuroShort, searchTerms: ['01/12/93..31/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when input value is not in the range of search terms', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: '25/11/93', fieldType: FieldType.dateEuroShort, searchTerms: ['01/12/93..31/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return True when input value equals the search terms min inclusive value and operator is set to "rangeInclusive"', () => { | ||
const options = { dataKey: '', operator: 'RangeInclusive', cellValue: '01/12/93', fieldType: FieldType.dateEuroShort, searchTerms: ['01/12/93..31/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when input value equals the search terms min inclusive value and operator is set to "RangeExclusive"', () => { | ||
const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '01/12/93', fieldType: FieldType.dateEuroShort, searchTerms: ['01/12/93..31/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False when any of the 2 search term value is not a valid date', () => { | ||
const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '05/12/93', fieldType: FieldType.dateEuroShort, searchTerms: ['01/12/93..60/12/93'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
expect(output).toBe(false); | ||
}); | ||
}); |
Oops, something went wrong.