X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/61e0c9318d8f48915877e6985a46f57ec6d43b83..2e5823e5ced30b6e83259a73fa16a3b2b5451ea0:/test/search.js diff --git a/test/search.js b/test/search.js index db16dbd..4ea86cc 100644 --- a/test/search.js +++ b/test/search.js @@ -1,8 +1,11 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Search Page', function () { let page; + // eslint-disable-next-line mocha/no-setup-in-describe + if (process.env.REVERSE_ONLY) return; + describe('No search', function () { before(async function () { page = await browser.newPage(); @@ -56,11 +59,11 @@ describe('Search Page', function () { }); }); - describe('Search for City of London', function () { + describe('Search for Paris', function () { before(async function () { page = await browser.newPage(); await page.goto('http://localhost:9999/search.html'); - await page.type('input[name=q]', 'City of London'); + await page.type('input[name=q]', 'Paris'); await page.click('button[type=submit]'); await page.waitForSelector('#searchresults'); // await page.screenshot({ path: "./screen.png", fullPage: true }); @@ -71,21 +74,23 @@ describe('Search Page', function () { }); it('should have a HTML page title', async function () { - assert.equal(await page.title(), 'Result for City of London | Nominatim Demo'); + assert.equal(await page.title(), 'Result for Paris | Nominatim Demo'); }); it('should have added search params', async function () { let current_url = new URL(await page.url()); - assert.strictEqual(current_url.searchParams.get('q'), 'City of London'); + assert.strictEqual(current_url.searchParams.get('q'), 'Paris'); }); - it('should atleast one result', async function () { + it('should have at least one result', async function () { let results_count = await page.$$eval('#searchresults .result', elements => elements.length); assert.ok(results_count > 1); }); it('should have show more results button', async function () { - let [search_more_btn] = await page.$x("//a[contains(text(), 'Search for more results')]"); + let [search_more_btn] = await page.$$( + "xpath/.//a[contains(text(), 'Search for more results')]" + ); assert.ok(search_more_btn); }); @@ -108,6 +113,18 @@ describe('Search Page', function () { assert.equal((await page.$$('#map')).length, 1); }); + it('should default to dedupe=1', async function () { + const checkbox_checked = await page.$eval('#option_dedupe', el => el.checked); + assert.equal(checkbox_checked, true); + + const links_href = await page.$$eval('#api-request a', links => links.map(l => l.href)); + let api_request_url = new URL(links_href[0]); + let debug_url = new URL(links_href[1]); + + assert.deepStrictEqual(api_request_url.searchParams.has('dedupe'), false); + assert.deepStrictEqual(debug_url.searchParams.has('dedupe'), false); + }); + it('should have polygon and marker in map and minimap', async function () { assert.strictEqual((await page.$$('#map .leaflet-overlay-pane path')).length, 4); }); @@ -125,7 +142,59 @@ describe('Search Page', function () { await page.waitForSelector('.container h1'); page_header = await page.$eval('.container h1', el => el.textContent); - assert.ok(page_header.includes('City of London')); + assert.ok(page_header.includes('Paris')); + }); + }); + + describe('Structured search for Paris', function () { + before(async function () { + page = await browser.newPage(); + await page.goto('http://localhost:9999/search.html'); + await page.click(".nav-link[href='#structured']"); + // await page.screenshot({ path: "./screen.png", fullPage: true }); + await page.type('input[name=city]', 'Paris'); + await page.type('input[name=country]', 'USA'); + await page.click('#structured button[type=submit]'); + await page.waitForSelector('#searchresults'); + }); + + after(async function () { + await page.close(); + }); + + it('should have a HTML page title', async function () { + assert.equal(await page.title(), 'Result for Paris, USA | Nominatim Demo'); + }); + + it('should have added search params', async function () { + let current_url = new URL(await page.url()); + assert.strictEqual(current_url.searchParams.get('q'), null); + assert.strictEqual(current_url.searchParams.get('city'), 'Paris'); + assert.strictEqual(current_url.searchParams.get('country'), 'USA'); + }); + + it('should have at least one result', async function () { + let results_count = await page.$$eval('#searchresults .result', elements => elements.length); + assert.ok(results_count > 1); + }); + }); + + describe('Search for OSM URL', function () { + before(async function () { + page = await browser.newPage(); + await page.goto('http://localhost:9999/search.html'); + await page.type('input[name=q]', 'https://www.openstreetmap.org/relation/3459013#map=11/41.2388/-8.3867'); + await page.click('button[type=submit]'); + await page.waitForSelector('table#address'); + }); + + after(async function () { + await page.close(); + }); + + it('should redirect to detail page search', async function () { + assert.equal(await page.title(), 'Details for R3459013 | Nominatim Demo'); + assert.ok((await page.$eval('.container h1', el => el.textContent)).includes('Porto')); }); }); });