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(' ');
46 // 'map center: 20.00000,0.00000 view on osm.org',
48 // 'viewbox: -131.48438,69.16256,131.48438,-48.69096',
50 // ' mouse position: 65.69612,103.71094'
52 let map_center_coords = map_pos_details[0]
53 .split('map center: ')[1].split(' view')[0].split(',');
54 let map_zoom = map_pos_details[1].split('map zoom: ')[1];
55 let map_viewbox = map_pos_details[2].split('viewbox: ')[1].split(',');
56 let last_click = map_pos_details[3].split('last click: ')[1];
58 assert.deepStrictEqual(map_center_coords.length, 2);
60 assert.deepStrictEqual(map_viewbox.length, 4);
61 assert.deepStrictEqual(last_click, undefined);
63 await page.click('#map-position-close a');
64 assert.strictEqual(await map_pos_handle.evaluate(node => node.style.display), 'none');
68 describe('Search for Paris', function () {
69 before(async function () {
70 page = await browser.newPage();
71 await page.goto('http://localhost:9999/search.html');
72 await page.type('input[name=q]', 'Paris');
73 await page.click('button[type=submit]');
74 await page.waitForSelector('#searchresults');
75 // await page.screenshot({ path: "./screen.png", fullPage: true });
78 after(async function () {
82 it('should have a HTML page title', async function () {
83 assert.equal(await page.title(), 'Result for Paris | Nominatim Demo');
86 it('should have added search params', async function () {
87 let current_url = new URL(await page.url());
88 assert.strictEqual(current_url.searchParams.get('q'), 'Paris');
91 it('should have at least one result', async function () {
92 let results_count = await page.$$eval('#searchresults .result', elements => elements.length);
93 assert.ok(results_count > 1);
96 it('should have show more results button', async function () {
97 let [search_more_btn] = await page.$$(
98 "xpath/.//a[contains(text(), 'Search for more results')]"
100 assert.ok(search_more_btn);
103 it('should display the API request and debug URL', async function () {
104 let link_titles = await page.$$eval('#api-request a', links => links.map(l => l.innerHTML));
105 assert.deepEqual(link_titles, ['API request', 'debug output']);
108 it('should not have polygon params in API request and debug URL', async function () {
109 let links_href = await page.$$eval('#api-request a', links => links.map(l => l.href));
110 let api_request_url = new URL(links_href[0]);
111 let debug_url = new URL(links_href[1]);
113 assert.deepStrictEqual(api_request_url.searchParams.has('polygon_geojson'), false);
114 assert.deepStrictEqual(debug_url.searchParams.has('polygon_geojson'), false);
117 it('should display a map', async function () {
118 await page.waitForSelector('#map');
119 assert.equal((await page.$$('#map')).length, 1);
122 it('should default to dedupe=1', async function () {
123 const checkbox_checked = await page.$eval('#option_dedupe', el => el.checked);
124 assert.equal(checkbox_checked, true);
126 const links_href = await page.$$eval('#api-request a', links => links.map(l => l.href));
127 let api_request_url = new URL(links_href[0]);
128 let debug_url = new URL(links_href[1]);
130 assert.deepStrictEqual(api_request_url.searchParams.has('dedupe'), false);
131 assert.deepStrictEqual(debug_url.searchParams.has('dedupe'), false);
134 it('should have polygon and marker in map and minimap', async function () {
135 assert.strictEqual((await page.$$('#map .leaflet-overlay-pane path')).length, 4);
138 it('should redirect to details page on clicking details button', async function () {
141 let results = await page.$$('#searchresults .result a');
143 await results[0].click();
144 await page.waitForSelector('table#address');
146 current_url = new URL(await page.url());
147 assert.deepStrictEqual(current_url.pathname, '/details.html');
149 await page.waitForSelector('.container h1');
150 page_header = await page.$eval('.container h1', el => el.textContent);
151 assert.ok(page_header.includes('Paris'));
155 describe('Structured search for Paris', function () {
156 before(async function () {
157 page = await browser.newPage();
158 await page.goto('http://localhost:9999/search.html');
159 await page.click(".nav-link[href='#structured']");
160 // await page.screenshot({ path: "./screen.png", fullPage: true });
161 await page.type('input[name=city]', 'Paris');
162 await page.type('input[name=country]', 'USA');
163 await page.click('#structured button[type=submit]');
164 await page.waitForSelector('#searchresults');
167 after(async function () {
171 it('should have a HTML page title', async function () {
172 assert.equal(await page.title(), 'Result for Paris, USA | Nominatim Demo');
175 it('should have added search params', async function () {
176 let current_url = new URL(await page.url());
177 assert.strictEqual(current_url.searchParams.get('q'), null);
178 assert.strictEqual(current_url.searchParams.get('city'), 'Paris');
179 assert.strictEqual(current_url.searchParams.get('country'), 'USA');
182 it('should have at least one result', async function () {
183 let results_count = await page.$$eval('#searchresults .result', elements => elements.length);
184 assert.ok(results_count > 1);
188 describe('Search for OSM URL', function () {
189 before(async function () {
190 page = await browser.newPage();
191 await page.goto('http://localhost:9999/search.html');
192 await page.type('input[name=q]', 'https://www.openstreetmap.org/relation/3459013#map=11/41.2388/-8.3867');
193 await page.click('button[type=submit]');
194 await page.waitForSelector('table#address');
197 after(async function () {
201 it('should redirect to detail page search', async function () {
202 assert.equal(await page.title(), 'Details for R3459013 | Nominatim Demo');
203 assert.ok((await page.$eval('.container h1', el => el.textContent)).includes('Porto'));