-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0ef4dd
commit 01c5022
Showing
5 changed files
with
93 additions
and
9 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
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
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
77 changes: 77 additions & 0 deletions
77
...twenty-front/src/modules/context-store/utils/__tests__/computeContextStoreFilters.test.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,77 @@ | ||
import { ContextStoreTargetedRecordsRule } from '@/context-store/states/contextStoreTargetedRecordsRuleState'; | ||
import { computeContextStoreFilters } from '@/context-store/utils/computeContextStoreFilters'; | ||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; | ||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems'; | ||
describe('computeContextStoreFilters', () => { | ||
const personObjectMetadataItem = | ||
generatedMockObjectMetadataItems.find( | ||
(item) => item.nameSingular === 'person', | ||
)!; | ||
|
||
it('should work for selection mode', () => { | ||
const contextStoreTargetedRecordsRule: ContextStoreTargetedRecordsRule = { | ||
mode: 'selection', | ||
selectedRecordIds: ['1', '2', '3'], | ||
}; | ||
|
||
const filters = computeContextStoreFilters( | ||
contextStoreTargetedRecordsRule, | ||
personObjectMetadataItem, | ||
); | ||
|
||
expect(filters).toEqual({ | ||
id: { | ||
in: ['1', '2', '3'], | ||
}, | ||
}); | ||
}); | ||
|
||
it('should work for exclusion mode', () => { | ||
const contextStoreTargetedRecordsRule: ContextStoreTargetedRecordsRule = { | ||
mode: 'exclusion', | ||
filters: [ | ||
{ | ||
id: 'name-filter', | ||
variant: 'default', | ||
fieldMetadataId: personObjectMetadataItem.fields.find( | ||
(field) => field.name === 'name', | ||
)!.id, | ||
value: 'John', | ||
displayValue: 'John', | ||
displayAvatarUrl: undefined, | ||
operand: ViewFilterOperand.Contains, | ||
definition: { | ||
fieldMetadataId: 'field1', | ||
label: 'Label 1', | ||
iconName: 'icon1', | ||
type: 'TEXT', | ||
}, | ||
}, | ||
], | ||
excludedRecordIds: ['1', '2', '3'], | ||
}; | ||
|
||
const filters = computeContextStoreFilters( | ||
contextStoreTargetedRecordsRule, | ||
personObjectMetadataItem, | ||
); | ||
|
||
expect(filters).toEqual({ | ||
and: [ | ||
{ | ||
name: { | ||
ilike: '%John%', | ||
}, | ||
}, | ||
{ | ||
not: { | ||
id: { | ||
in: ['1', '2', '3'], | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
}); |
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