diff --git a/app.amsterdam.json b/app.amsterdam.json index da6cc95de7..3b296fae07 100644 --- a/app.amsterdam.json +++ b/app.amsterdam.json @@ -54,7 +54,7 @@ "smallHeight": "29px" }, "map": { - "municipality": ["amsterdam", "ouder-amstel"], + "municipality": "amsterdam \"ouder-amstel\"", "options": { "center": [ 52.3731081, diff --git a/internals/schemas/app.schema.json b/internals/schemas/app.schema.json index ea1d4d847e..e1724fc404 100644 --- a/internals/schemas/app.schema.json +++ b/internals/schemas/app.schema.json @@ -342,6 +342,7 @@ "additionalProperties": false, "properties": { "municipality": { + "description": "Allows to filter address lookup by municipality. For example a value of 'amsterdam' will be used in the following format: `fq=gemeentenaam:(amsterdam)`. Separate multiple municipalities with a space. If a municipality has spaces, surround it by quotes, which in the config will look like `\"boxtel \\\"den bosch\\\"\"`. For more information see https://www.pdok.nl/restful-api/-/article/pdok-locatieserver#/paths/~1suggest/get", "type": [ "string", "array" diff --git a/src/components/PDOKAutoSuggest/PDOKAutoSuggest.test.tsx b/src/components/PDOKAutoSuggest/PDOKAutoSuggest.test.tsx index cfd6ba7057..e76e5c2c22 100644 --- a/src/components/PDOKAutoSuggest/PDOKAutoSuggest.test.tsx +++ b/src/components/PDOKAutoSuggest/PDOKAutoSuggest.test.tsx @@ -71,15 +71,35 @@ describe('components/PDOKAutoSuggest', () => { it('should call fetch with municipality', async () => { await renderAndSearch('Dam', { municipality: 'amsterdam' }) expect(fetch).toHaveBeenCalledWith( - expect.stringContaining(`${municipalityQs}("amsterdam")`), + expect.stringContaining(`${municipalityQs}(amsterdam)`), expect.objectContaining({ method: 'GET' }) ) }) - it('should work with an array for municipality', async () => { - await renderAndSearch('Dam', { municipality: ['utrecht', 'amsterdam'] }) + it('should work with multiple municipalities', async () => { + await renderAndSearch('Dam', { municipality: 'utrecht amsterdam' }) expect(fetch).toHaveBeenCalledWith( - expect.stringContaining(`${municipalityQs}("utrecht" "amsterdam")`), + expect.stringContaining(`${municipalityQs}(utrecht amsterdam)`), + expect.objectContaining({ method: 'GET' }) + ) + }) + + it('should work with quotes and negations', async () => { + await renderAndSearch('Dam', { + municipality: '"den bosch" -amsterdam', + }) + expect(fetch).toHaveBeenCalledWith( + expect.stringContaining(`${municipalityQs}("den bosch" -amsterdam)`), + expect.objectContaining({ method: 'GET' }) + ) + }) + + it('should ignore an empty string', async () => { + await renderAndSearch('Dam', { + municipality: '', + }) + expect(fetch).toHaveBeenCalledWith( + expect.not.stringContaining(municipalityQs), expect.objectContaining({ method: 'GET' }) ) }) diff --git a/src/components/PDOKAutoSuggest/PDOKAutoSuggest.tsx b/src/components/PDOKAutoSuggest/PDOKAutoSuggest.tsx index e885478d1c..c33e82d705 100644 --- a/src/components/PDOKAutoSuggest/PDOKAutoSuggest.tsx +++ b/src/components/PDOKAutoSuggest/PDOKAutoSuggest.tsx @@ -42,14 +42,8 @@ const PDOKAutoSuggest: FC = ({ municipality = configuration.map.municipality, ...rest }) => { - const municipalityArray = Array.isArray(municipality) - ? municipality - : [municipality].filter(Boolean) - const municipalityString = municipalityArray - .map((item) => `"${item}"`) - .join(' ') const fq = municipality - ? [['fq', `${municipalityFilterName}:(${municipalityString})`]] + ? [['fq', `${municipalityFilterName}:(${municipality})`]] : [] // ['fl', '*'], // undocumented; requests all available field values from the API const fl = [