1 import assert from 'assert';
 
   3 describe('Search Page', function () {
 
   6   // eslint-disable-next-line mocha/no-setup-in-describe
 
   7   if (process.env.REVERSE_ONLY) return;
 
   9   describe('No search', function () {
 
  10     before(async function () {
 
  11       page = await browser.newPage();
 
  12       await page.goto('http://localhost:9999/search.html');
 
  15     after(async function () {
 
  19     it('should have a HTML page title', async function () {
 
  20       assert.equal(await page.title(), 'Nominatim Demo');
 
  23     it('should have a welcome message', async function () {
 
  24       let welcome_message = await page.$eval('#welcome h2', el => el.textContent);
 
  25       assert.deepStrictEqual(welcome_message, 'Welcome to Nominatim');
 
  28     it('should have a last_updated_: ... ago data', async function () {
 
  29       await page.waitForSelector('abbr[id="data-date"]');
 
  31       let last_updated = await page.$eval('abbr[id="data-date"]', el => el.textContent);
 
  32       assert.ok(last_updated.includes('ago'));
 
  35     it('should show map bounds buttons', async function () {
 
  36       await page.waitForSelector('#map');
 
  37       let show_map_pos_handle = await page.$('#show-map-position');
 
  38       let map_pos_handle = await page.$('#map-position');
 
  40       await show_map_pos_handle.click();
 
  41       assert.strictEqual(await map_pos_handle.evaluate(node => node.style.display), 'block');
 
  43       let map_pos_details = await page.$eval('#map-position-inner', el => el.textContent);
 
  44       map_pos_details = map_pos_details.split(' \n');
 
  46       let map_center_coor = map_pos_details[0]
 
  47         .split('map center: ')[1].split(' view')[0].split(',');
 
  48       let map_zoom = map_pos_details[1].split('map zoom: ')[1];
 
  49       let map_viewbox = map_pos_details[2].split('viewbox: ')[1].split(',');
 
  50       let last_click = map_pos_details[3].split('last click: ')[1];
 
  52       assert.deepStrictEqual(map_center_coor.length, 2);
 
  54       assert.deepStrictEqual(map_viewbox.length, 4);
 
  55       assert.deepStrictEqual(last_click, 'undefined');
 
  57       await page.click('#map-position-close a');
 
  58       assert.strictEqual(await map_pos_handle.evaluate(node => node.style.display), 'none');
 
  62   describe('Search for Paris', function () {
 
  63     before(async function () {
 
  64       page = await browser.newPage();
 
  65       await page.goto('http://localhost:9999/search.html');
 
  66       await page.type('input[name=q]', 'Paris');
 
  67       await page.click('button[type=submit]');
 
  68       await page.waitForSelector('#searchresults');
 
  69       // await page.screenshot({ path: "./screen.png", fullPage: true });
 
  72     after(async function () {
 
  76     it('should have a HTML page title', async function () {
 
  77       assert.equal(await page.title(), 'Result for Paris | Nominatim Demo');
 
  80     it('should have added search params', async function () {
 
  81       let current_url = new URL(await page.url());
 
  82       assert.strictEqual(current_url.searchParams.get('q'), 'Paris');
 
  85     it('should atleast one result', async function () {
 
  86       let results_count = await page.$$eval('#searchresults .result', elements => elements.length);
 
  87       assert.ok(results_count > 1);
 
  90     it('should have show more results button', async function () {
 
  91       let [search_more_btn] = await page.$$(
 
  92         "xpath/.//a[contains(text(), 'Search for more results')]"
 
  94       assert.ok(search_more_btn);
 
  97     it('should display the API request and debug URL', async function () {
 
  98       let link_titles = await page.$$eval('#api-request a', links => links.map(l => l.innerHTML));
 
  99       assert.deepEqual(link_titles, ['API request', 'debug output']);
 
 102     it('should not have polygon params in API request and debug URL', async function () {
 
 103       let links_href = await page.$$eval('#api-request a', links => links.map(l => l.href));
 
 104       let api_request_url = new URL(links_href[0]);
 
 105       let debug_url = new URL(links_href[1]);
 
 107       assert.deepStrictEqual(api_request_url.searchParams.has('polygon_geojson'), false);
 
 108       assert.deepStrictEqual(debug_url.searchParams.has('polygon_geojson'), false);
 
 111     it('should display a map', async function () {
 
 112       await page.waitForSelector('#map');
 
 113       assert.equal((await page.$$('#map')).length, 1);
 
 116     it('should default to dedupe=1', async function () {
 
 117       const checkbox_checked = await page.$eval('#option_dedupe', el => el.checked);
 
 118       assert.equal(checkbox_checked, true);
 
 120       const links_href = await page.$$eval('#api-request a', links => links.map(l => l.href));
 
 121       let api_request_url = new URL(links_href[0]);
 
 122       let debug_url = new URL(links_href[1]);
 
 124       assert.deepStrictEqual(api_request_url.searchParams.has('dedupe'), false);
 
 125       assert.deepStrictEqual(debug_url.searchParams.has('dedupe'), false);
 
 128     it('should have polygon and marker in map and minimap', async function () {
 
 129       assert.strictEqual((await page.$$('#map .leaflet-overlay-pane path')).length, 4);
 
 132     it('should redirect to details page on clicking details button', async function () {
 
 135       let results = await page.$$('#searchresults .result a');
 
 137       await results[0].click();
 
 138       await page.waitForSelector('table#address');
 
 140       current_url = new URL(await page.url());
 
 141       assert.deepStrictEqual(current_url.pathname, '/details.html');
 
 143       await page.waitForSelector('.container h1');
 
 144       page_header = await page.$eval('.container h1', el => el.textContent);
 
 145       assert.ok(page_header.includes('Paris'));
 
 149   describe('Search for OSM URL', function () {
 
 150     before(async function () {
 
 151       page = await browser.newPage();
 
 152       await page.goto('http://localhost:9999/search.html');
 
 153       await page.type('input[name=q]', 'https://www.openstreetmap.org/relation/3459013#map=11/41.2388/-8.3867');
 
 154       await page.click('button[type=submit]');
 
 155       await page.waitForSelector('table#address');
 
 158     after(async function () {
 
 162     it('should redirect to detail page search', async function () {
 
 163       assert.equal(await page.title(), 'Details for R3459013 | Nominatim Demo');
 
 164       assert.ok((await page.$eval('.container h1', el => el.textContent)).includes('Porto'));