From 7218a0c36c5b1e28ed46e1e1b133b5e5dd68b2ca Mon Sep 17 00:00:00 2001 From: mtmail Date: Mon, 31 May 2021 14:09:31 +0200 Subject: [PATCH] Helper check for details keywords (#160) * Details page helper to check if place has 1 or more keywords * add documentation hint how to run only one test file --- CONTRIBUTE.md | 6 ++++++ src/pages/DetailsPage.svelte | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index 9c184e4..c910337 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -47,6 +47,12 @@ The `test/` setup uses [Mocha](https://mochajs.org/) to run tests. Tests use [Pu port. That's a rare setup but something https://nominatim.openstreetmap.org/ does so worth testing. + To run a single test file only + + ``` + yarn run rollup -c && yarn run mocha test/details.js + ``` + * Run syntax linter (configuration in `.eslint.js`) ``` diff --git a/src/pages/DetailsPage.svelte b/src/pages/DetailsPage.svelte index baac180..2c7f8ba 100644 --- a/src/pages/DetailsPage.svelte +++ b/src/pages/DetailsPage.svelte @@ -54,6 +54,14 @@ } } + function place_has_keywords(aThisPlace) { + // Return false if Nominatim API sends 'keywords: { name: [], address: [] }' + return ( + aThisPlace.keywords && aThisPlace.keywords.name && aThisPlace.keywords.address + && (aThisPlace.keywords.name.length > 0 || aThisPlace.keywords.address.length > 0) + ); + } + $: { let pageinfo = $page; if (pageinfo.tab === 'details') { @@ -165,7 +173,7 @@

Keywords

{#if api_request_params.keywords} - {#if aPlace.keywords && (aPlace.keywords.name || aPlace.keywords.address) } + {#if place_has_keywords(aPlace)}

Name Keywords

{#each aPlace.keywords.name as keyword} -- 2.39.5