From 3e7d875df78b94d17251d811f891761dc8b67735 Mon Sep 17 00:00:00 2001 From: mtmail Date: Mon, 17 May 2021 00:09:58 +0200 Subject: [PATCH] detail page: fix display when keywords from API are empty (#153) --- src/pages/DetailsPage.svelte | 53 +++++++++++++++++++++--------------- test/details.js | 44 +++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/pages/DetailsPage.svelte b/src/pages/DetailsPage.svelte index 9d72944..eef7f23 100644 --- a/src/pages/DetailsPage.svelte +++ b/src/pages/DetailsPage.svelte @@ -163,20 +163,11 @@ {/if}

Keywords

- {#if aPlace.keywords} -

Name Keywords

- {#each aPlace.keywords.name as keyword} - - {formatKeywordToken(keyword.token)} - {#if keyword.id} - word id: {keyword.id} - {/if} - - {/each} + {#if api_request_params.keywords} - {#if aPlace.keywords.address} -

Address Keywords

- {#each aPlace.keywords.address as keyword} + {#if aPlace.keywords && (aPlace.keywords.name || aPlace.keywords.address) } +

Name Keywords

+ {#each aPlace.keywords.name as keyword} {formatKeywordToken(keyword.token)} {#if keyword.id} @@ -184,6 +175,20 @@ {/if} {/each} + + {#if aPlace.keywords.address} +

Address Keywords

+ {#each aPlace.keywords.address as keyword} + + {formatKeywordToken(keyword.token)} + {#if keyword.id} + word id: {keyword.id} + {/if} + + {/each} + {/if} + {:else} + Place has no keywords {/if} {:else} @@ -195,17 +200,21 @@ {/if}

Parent Of

- {#if aPlace.hierarchy} + {#if api_request_params.hierarchy} + {#if aPlace.hierarchy && aPlace.hierarchy.length} - {#each Object.keys(aPlace.hierarchy) as type} -

{type}

- {#each aPlace.hierarchy[type] as line} - - {/each} - {/each} + {#each Object.keys(aPlace.hierarchy) as type} +

{type}

+ {#each aPlace.hierarchy[type] as line} + + {/each} + {/each} - {#if Object.keys(aPlace.hierarchy) > 500} -

There are more child objects which are not shown.

+ {#if Object.keys(aPlace.hierarchy) > 500} +

There are more child objects which are not shown.

+ {/if} + {:else} + Place is not parent of other places {/if} {:else} diff --git a/test/details.js b/test/details.js index 5baf402..f2f8eb6 100644 --- a/test/details.js +++ b/test/details.js @@ -18,7 +18,28 @@ describe('Details Page', function () { }); }); - describe('With search', function () { + describe('With search - no place found', function () { + before(async function () { + page = await browser.newPage(); + await page.goto('http://localhost:9999/details.html'); + await page.type('input[type=edit]', 'n3'); + await page.click('button[type=submit]'); + await page.waitForSelector('#api-request'); + }); + + + it('should display error', async function () { + let page_content = await page.$eval('body', el => el.textContent); + + assert.ok(page_content.includes('No place with that OSM ID found')); + }); + + after(async function () { + await page.close(); + }); + }); + + describe('With search - Eiffel Tower', function () { before(async function () { page = await browser.newPage(); await page.goto('http://localhost:9999/details.html'); @@ -79,4 +100,25 @@ describe('Details Page', function () { assert.ok((await page.$eval('.container h1', el => el.textContent)).includes('Taj Mahal')); }); }); + + describe('Place without name, keywords, hierarchy', function () { + // e.g. a numeric house number + before(async function () { + page = await browser.newPage(); + await page.goto('http://localhost:9999/details.html?osmtype=N&osmid=946563004&keywords=1&hierarchy=1'); + await page.waitForSelector('.container .row'); + }); + + after(async function () { + await page.close(); + }); + + it('should display No Name, no keywords, no hierarchy', async function () { + let page_content = await page.$eval('body', el => el.textContent); + + assert.ok(page_content.includes('Name No Name')); + assert.ok(page_content.includes('Place has no keywords')); + assert.ok(page_content.includes('Place is not parent of other places')); + }); + }); }); -- 2.43.2