diff --git a/src/hooks/useGeolocationHandler.ts b/src/hooks/useGeolocationHandler.ts index a2d4ec495..457f20274 100644 --- a/src/hooks/useGeolocationHandler.ts +++ b/src/hooks/useGeolocationHandler.ts @@ -3,7 +3,8 @@ import { executeSearch } from '../utils/search-operations'; import { getUserLocation } from '../utils/location-operations'; import { useCallback, useState } from 'react'; -const LOCATION_FIELD_ID = 'builtin.location'; +const GEOLOCATION_FIELD_ID = 'builtin.location'; +const LOCATION_FIELD_IDS = [GEOLOCATION_FIELD_ID, 'builtin.region', 'address.countryCode']; const METERS_PER_MILE = 1609.344; /** @@ -49,7 +50,7 @@ export function useGeolocationHandler({ selected: true, filter: { kind: 'fieldValue', - fieldId: LOCATION_FIELD_ID, + fieldId: GEOLOCATION_FIELD_ID, matcher: Matcher.Near, value: { lat: latitude, @@ -60,7 +61,7 @@ export function useGeolocationHandler({ }; const nonLocationFilters = staticFilters.filter(filter => { return !(filter.filter.kind === 'fieldValue' - && filter.filter.fieldId === LOCATION_FIELD_ID); + && LOCATION_FIELD_IDS.includes(filter.filter.fieldId)); }); searchActions.setStaticFilters([...nonLocationFilters, locationFilter]); executeSearch(searchActions); diff --git a/tests/components/Geolocation.test.tsx b/tests/components/Geolocation.test.tsx index 2a6b57568..d5139a2f7 100644 --- a/tests/components/Geolocation.test.tsx +++ b/tests/components/Geolocation.test.tsx @@ -54,6 +54,26 @@ const mockedStateWithFilters: Partial = { }, } }, + { + displayName: 'Virginia, US', + selected: true, + filter: { + kind: 'fieldValue', + fieldId: 'builtin.region', + matcher: Matcher.Equals, + value: 'US-VA', + } + }, + { + displayName: 'United States', + selected: true, + filter: { + kind: 'fieldValue', + fieldId: 'address.countryCode', + matcher: Matcher.Equals, + value: 'US', + } + }, { displayName: 'My name', selected: true, @@ -141,7 +161,7 @@ describe('custom click handler', () => { describe('default click handler', () => { it('sets a location filter using provided radius', async () => { const actions = spyOnActions(); - render(); + render(); clickUpdateLocation(); const expectedLocationFilter: SelectableStaticFilter = createLocationFilter(10 * 1609.344); @@ -162,7 +182,7 @@ describe('default click handler', () => { }); }); - it('replace existing location filters with a new location filter in static filters state', async () => { + it('replaces existing location filters with a new location filter in static filters state', async () => { mockAnswersState(mockedStateWithFilters); const actions = spyOnActions(); render(); @@ -189,7 +209,7 @@ describe('default click handler', () => { it('sets a location filter using a larger radius than provided value due to low accuracy of user coordinate', async () => { jest.spyOn(locationOperations, 'getUserLocation').mockResolvedValue(newGeoPositionWithLowAccuracy); const actions = spyOnActions(); - render(); + render(); clickUpdateLocation(); const accuracy = newGeoPositionWithLowAccuracy.coords.accuracy; @@ -243,4 +263,4 @@ function createLocationFilter(radius: number = 50 * 1609.344): SelectableStaticF }, } }; -} \ No newline at end of file +}