1 const assert = require('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 City of London', 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]', 'City of London');
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 City of London | 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'), 'City of London');
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 have polygon and marker in map and minimap', async function () {
115 assert.strictEqual((await page.$$('#map .leaflet-overlay-pane path')).length, 4);
118 it('should redirect to details page on clicking details button', async function () {
121 let results = await page.$$('#searchresults .result a');
123 await results[0].click();
124 await page.waitForSelector('table#address');
126 current_url = new URL(await page.url());
127 assert.deepStrictEqual(current_url.pathname, '/details.html');
129 await page.waitForSelector('.container h1');
130 page_header = await page.$eval('.container h1', el => el.textContent);
131 assert.ok(page_header.includes('City of London'));