Skip to content

Commit

Permalink
(PC-33187) feat(venueMap): filtered only the selected venue type when…
Browse files Browse the repository at this point in the history
… previous filter is all venue type group
  • Loading branch information
clesausse-pass committed Nov 28, 2024
1 parent 96198d7 commit d0fff30
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
<VenueMapTypeFilter
navigation={mockNavigation}
route={{
key: 'VenueMapTypeFilter',
name: 'VenueMapTypeFilter',
params: { title: 'Sorties', filterGroup: 'OUTINGS' },
}}
/>
)

const concertHallCheckbox = screen.getByRole('checkbox', {
name: 'Musique - Salle de concerts',
})

await user.press(concertHallCheckbox)

expect(mockSetVenuesFilters).toHaveBeenNthCalledWith(1, [VenueTypeCodeKey.CONCERT_HALL])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const VenueMapTypeFilter: FunctionComponent<Props> = ({ navigation, route
const { title, filterGroup } = route.params
const { navigate } = useNavigation<UseNavigationType>()
const venueFilters = useVenuesFilter()
const { addVenuesFilters, removeVenuesFilters } = useVenuesFilterActions()
const { addVenuesFilters, removeVenuesFilters, setVenuesFilters } = useVenuesFilterActions()

const onGoBack = () => {
navigation.goBack()
Expand All @@ -35,6 +35,11 @@ export const VenueMapTypeFilter: FunctionComponent<Props> = ({ navigation, route

const toggleFilters = (isChecked: boolean, filters: VenueTypeCodeKey[]) => {
if (isChecked) {
if (hasAllFilters) {
// Only the current selection is filtered
setVenuesFilters(filters)
return
}
addVenuesFilters(filters)
return
}
Expand Down

0 comments on commit d0fff30

Please sign in to comment.