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.$x("//a[contains(text(), 'Search for more results')]");
92 assert.ok(search_more_btn);
95 it('should display the API request and debug URL', async function () {
96 let link_titles = await page.$$eval('#api-request a', links => links.map(l => l.innerHTML));
97 assert.deepEqual(link_titles, ['API request', 'debug output']);
100 it('should not have polygon params in API request and debug URL', async function () {
101 let links_href = await page.$$eval('#api-request a', links => links.map(l => l.href));
102 let api_request_url = new URL(links_href[0]);
103 let debug_url = new URL(links_href[1]);
105 assert.deepStrictEqual(api_request_url.searchParams.has('polygon_geojson'), false);
106 assert.deepStrictEqual(debug_url.searchParams.has('polygon_geojson'), false);
109 it('should display a map', async function () {
110 await page.waitForSelector('#map');
111 assert.equal((await page.$$('#map')).length, 1);
114 it('should default to dedupe=1', async function () {
115 const checkbox_checked = await page.$eval('#option_dedupe', el => el.checked);
116 assert.equal(checkbox_checked, true);
118 const links_href = await page.$$eval('#api-request a', links => links.map(l => l.href));
119 let api_request_url = new URL(links_href[0]);
120 let debug_url = new URL(links_href[1]);
122 assert.deepStrictEqual(api_request_url.searchParams.has('dedupe'), false);
123 assert.deepStrictEqual(debug_url.searchParams.has('dedupe'), false);
126 it('should have polygon and marker in map and minimap', async function () {
127 assert.strictEqual((await page.$$('#map .leaflet-overlay-pane path')).length, 4);
130 it('should redirect to details page on clicking details button', async function () {
133 let results = await page.$$('#searchresults .result a');
135 await results[0].click();
136 await page.waitForSelector('table#address');
138 current_url = new URL(await page.url());
139 assert.deepStrictEqual(current_url.pathname, '/details.html');
141 await page.waitForSelector('.container h1');
142 page_header = await page.$eval('.container h1', el => el.textContent);
143 assert.ok(page_header.includes('Paris'));
147 describe('Search for OSM URL', function () {
148 before(async function () {
149 page = await browser.newPage();
150 await page.goto('http://localhost:9999/search.html');
151 await page.type('input[name=q]', 'https://www.openstreetmap.org/relation/3459013#map=11/41.2388/-8.3867');
152 await page.click('button[type=submit]');
153 await page.waitForSelector('table#address');
156 after(async function () {
160 it('should redirect to detail page search', async function () {
161 assert.equal(await page.title(), 'Details for R3459013 | Nominatim Demo');
162 assert.ok((await page.$eval('.container h1', el => el.textContent)).includes('Porto'));