From d0fff309262cfb8e0e39d8b1220786701cc881ac Mon Sep 17 00:00:00 2001
From: clesausse-pass <187269096+clesausse-pass@users.noreply.github.com>
Date: Thu, 28 Nov 2024 10:18:43 +0100
Subject: [PATCH] (PC-33187) feat(venueMap): filtered only the selected venue
type when previous filter is all venue type group
---
.../VenueMapTypeFilter.native.test.tsx | 24 +++++++++++++++++++
.../VenueMapTypeFilter/VenueMapTypeFilter.tsx | 7 +++++-
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.native.test.tsx b/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.native.test.tsx
index d339651535f..519fe29e6a9 100644
--- a/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.native.test.tsx
+++ b/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.native.test.tsx
@@ -40,10 +40,12 @@ mockUseVenuesFilter.mockReturnValue([])
const mockAddVenuesFilters = jest.fn()
const mockRemoveVenuesFilters = jest.fn()
+const mockSetVenuesFilters = jest.fn()
const mockUseVenuesFilterActions = useVenuesFilterActions as jest.Mock
mockUseVenuesFilterActions.mockReturnValue({
addVenuesFilters: mockAddVenuesFilters,
removeVenuesFilters: mockRemoveVenuesFilters,
+ setVenuesFilters: mockSetVenuesFilters,
})
const user = userEvent.setup()
@@ -299,4 +301,26 @@ describe('VenueMapTypeFilter', () => {
expect(mockAddVenuesFilters).toHaveBeenNthCalledWith(1, [VenueTypeCodeKey.CONCERT_HALL])
})
+
+ it('should add only the current selection in venue type filter when pressing venue type checkbox (not checked) and all venue type group filtered', async () => {
+ mockUseVenuesFilter.mockReturnValueOnce(FILTERS_VENUE_TYPE_MAPPING['OUTINGS'])
+ render(
+
+ )
+
+ const concertHallCheckbox = screen.getByRole('checkbox', {
+ name: 'Musique - Salle de concerts',
+ })
+
+ await user.press(concertHallCheckbox)
+
+ expect(mockSetVenuesFilters).toHaveBeenNthCalledWith(1, [VenueTypeCodeKey.CONCERT_HALL])
+ })
})
diff --git a/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.tsx b/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.tsx
index d8d4e61e51f..6a9a1a38425 100644
--- a/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.tsx
+++ b/src/features/venueMap/components/VenueMapTypeFilter/VenueMapTypeFilter.tsx
@@ -23,7 +23,7 @@ export const VenueMapTypeFilter: FunctionComponent = ({ navigation, route
const { title, filterGroup } = route.params
const { navigate } = useNavigation()
const venueFilters = useVenuesFilter()
- const { addVenuesFilters, removeVenuesFilters } = useVenuesFilterActions()
+ const { addVenuesFilters, removeVenuesFilters, setVenuesFilters } = useVenuesFilterActions()
const onGoBack = () => {
navigation.goBack()
@@ -35,6 +35,11 @@ export const VenueMapTypeFilter: FunctionComponent = ({ navigation, route
const toggleFilters = (isChecked: boolean, filters: VenueTypeCodeKey[]) => {
if (isChecked) {
+ if (hasAllFilters) {
+ // Only the current selection is filtered
+ setVenuesFilters(filters)
+ return
+ }
addVenuesFilters(filters)
return
}