-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added tests for upsert and remove record filters hooks
- Created and applied upsert and remove record filter everywhere old upsert and remove are used - Added RecordFilter context - Renamed usePrefetchRunQuery to useUpsertRecordsInCacheForPrefetchKey
- Loading branch information
1 parent
9ba510e
commit 21259b4
Showing
29 changed files
with
592 additions
and
106 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
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
1 change: 1 addition & 0 deletions
1
...s/object-record/object-filter-dropdown/states/availableFilterDefinitionsComponentState.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
117 changes: 117 additions & 0 deletions
117
...nt/src/modules/object-record/record-filter/hooks/__tests__/useRemoveRecordFilter.test.tsx
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,117 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { currentRecordFiltersComponentState } from '@/object-record/record-filter/states/currentRecordFiltersComponentState'; | ||
import { RecordFilter } from '@/object-record/record-filter/types/RecordFilter'; | ||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; | ||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; | ||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper'; | ||
import { useRemoveRecordFilter } from '../useRemoveRecordFilter'; | ||
import { useUpsertRecordFilter } from '../useUpsertRecordFilter'; | ||
|
||
const Wrapper = getJestMetadataAndApolloMocksWrapper({ | ||
apolloMocks: [], | ||
}); | ||
|
||
describe('useRemoveRecordFilter', () => { | ||
it('should remove an existing filter', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const currentRecordFilters = useRecoilComponentValueV2( | ||
currentRecordFiltersComponentState, | ||
); | ||
|
||
const { upsertRecordFilter } = useUpsertRecordFilter(); | ||
const { removeRecordFilter } = useRemoveRecordFilter(); | ||
|
||
return { | ||
upsertRecordFilter, | ||
removeRecordFilter, | ||
currentRecordFilters, | ||
}; | ||
}, | ||
{ | ||
wrapper: Wrapper, | ||
}, | ||
); | ||
|
||
const filter: RecordFilter = { | ||
id: 'filter-1', | ||
fieldMetadataId: 'field-1', | ||
value: 'test-value', | ||
operand: ViewFilterOperand.Contains, | ||
displayValue: 'test-value', | ||
definition: { | ||
type: 'TEXT', | ||
fieldMetadataId: 'field-1', | ||
label: 'Test Field', | ||
iconName: 'IconText', | ||
}, | ||
}; | ||
|
||
// First add a filter | ||
act(() => { | ||
result.current.upsertRecordFilter(filter); | ||
}); | ||
|
||
expect(result.current.currentRecordFilters).toHaveLength(1); | ||
expect(result.current.currentRecordFilters[0]).toEqual(filter); | ||
|
||
// Then remove it | ||
act(() => { | ||
result.current.removeRecordFilter(filter.fieldMetadataId); | ||
}); | ||
|
||
expect(result.current.currentRecordFilters).toHaveLength(0); | ||
}); | ||
|
||
it('should not modify filters when trying to remove a non-existent filter', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const currentRecordFilters = useRecoilComponentValueV2( | ||
currentRecordFiltersComponentState, | ||
); | ||
const { upsertRecordFilter } = useUpsertRecordFilter(); | ||
const { removeRecordFilter } = useRemoveRecordFilter(); | ||
return { | ||
upsertRecordFilter, | ||
removeRecordFilter, | ||
currentRecordFilters, | ||
}; | ||
}, | ||
{ | ||
wrapper: Wrapper, | ||
}, | ||
); | ||
|
||
const filter: RecordFilter = { | ||
id: 'filter-1', | ||
fieldMetadataId: 'field-1', | ||
value: 'test-value', | ||
operand: ViewFilterOperand.Contains, | ||
displayValue: 'test-value', | ||
definition: { | ||
type: 'TEXT', | ||
fieldMetadataId: 'field-1', | ||
label: 'Test Field', | ||
iconName: 'IconText', | ||
}, | ||
}; | ||
|
||
// Add a filter | ||
act(() => { | ||
result.current.upsertRecordFilter(filter); | ||
}); | ||
|
||
expect(result.current.currentRecordFilters).toHaveLength(1); | ||
|
||
// Try to remove a non-existent filter | ||
act(() => { | ||
result.current.removeRecordFilter('non-existent-field'); | ||
}); | ||
|
||
// Filter list should remain unchanged | ||
expect(result.current.currentRecordFilters).toHaveLength(1); | ||
expect(result.current.currentRecordFilters[0]).toEqual(filter); | ||
}); | ||
}); |
112 changes: 112 additions & 0 deletions
112
...nt/src/modules/object-record/record-filter/hooks/__tests__/useUpsertRecordFilter.test.tsx
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,112 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { currentRecordFiltersComponentState } from '@/object-record/record-filter/states/currentRecordFiltersComponentState'; | ||
import { RecordFilter } from '@/object-record/record-filter/types/RecordFilter'; | ||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; | ||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; | ||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper'; | ||
import { useUpsertRecordFilter } from '../useUpsertRecordFilter'; | ||
|
||
const Wrapper = getJestMetadataAndApolloMocksWrapper({ | ||
apolloMocks: [], | ||
}); | ||
|
||
describe('useUpsertRecordFilter', () => { | ||
it('should add a new filter when fieldMetadataId does not exist', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const currentRecordFilters = useRecoilComponentValueV2( | ||
currentRecordFiltersComponentState, | ||
); | ||
|
||
const { upsertRecordFilter } = useUpsertRecordFilter(); | ||
|
||
return { upsertRecordFilter, currentRecordFilters }; | ||
}, | ||
{ | ||
wrapper: Wrapper, | ||
}, | ||
); | ||
|
||
const newFilter: RecordFilter = { | ||
id: 'filter-1', | ||
fieldMetadataId: 'field-1', | ||
value: 'test-value', | ||
operand: ViewFilterOperand.Contains, | ||
displayValue: 'test-value', | ||
definition: { | ||
type: 'TEXT', | ||
fieldMetadataId: 'field-1', | ||
label: 'Test Field', | ||
iconName: 'IconText', | ||
}, | ||
}; | ||
|
||
act(() => { | ||
result.current.upsertRecordFilter(newFilter); | ||
}); | ||
|
||
expect(result.current.currentRecordFilters).toHaveLength(1); | ||
expect(result.current.currentRecordFilters[0]).toEqual(newFilter); | ||
}); | ||
|
||
it('should update an existing filter when fieldMetadataId exists', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const currentRecordFilters = useRecoilComponentValueV2( | ||
currentRecordFiltersComponentState, | ||
); | ||
|
||
const { upsertRecordFilter } = useUpsertRecordFilter(); | ||
|
||
return { upsertRecordFilter, currentRecordFilters }; | ||
}, | ||
{ | ||
wrapper: Wrapper, | ||
}, | ||
); | ||
|
||
const initialFilter: RecordFilter = { | ||
id: 'filter-1', | ||
fieldMetadataId: 'field-1', | ||
value: 'initial-value', | ||
operand: ViewFilterOperand.Contains, | ||
displayValue: 'initial-value', | ||
definition: { | ||
type: 'TEXT', | ||
fieldMetadataId: 'field-1', | ||
label: 'Test Field', | ||
iconName: 'IconText', | ||
}, | ||
}; | ||
|
||
const updatedFilter: RecordFilter = { | ||
id: 'filter-1', | ||
fieldMetadataId: 'field-1', | ||
value: 'updated-value', | ||
operand: ViewFilterOperand.Contains, | ||
displayValue: 'updated-value', | ||
definition: { | ||
type: 'TEXT', | ||
fieldMetadataId: 'field-1', | ||
label: 'Test Field', | ||
iconName: 'IconText', | ||
}, | ||
}; | ||
|
||
act(() => { | ||
result.current.upsertRecordFilter(initialFilter); | ||
}); | ||
|
||
expect(result.current.currentRecordFilters).toHaveLength(1); | ||
expect(result.current.currentRecordFilters[0]).toEqual(initialFilter); | ||
|
||
act(() => { | ||
result.current.upsertRecordFilter(updatedFilter); | ||
}); | ||
|
||
expect(result.current.currentRecordFilters).toHaveLength(1); | ||
expect(result.current.currentRecordFilters[0]).toEqual(updatedFilter); | ||
}); | ||
}); |
Oops, something went wrong.