1 const assert = require('assert');
3 describe('Search Page', function () {
6 describe('No search', function () {
7 before(async function () {
8 page = await browser.newPage();
9 await page.goto('http://localhost:9999/search.html');
12 after(async function () {
16 it('should have a HTML page title', async function () {
17 assert.equal(await page.title(), 'Nominatim Demo');
20 it('should have a welcome message', async function () {
21 let welcome_message = await page.$eval('#welcome h2', el => el.textContent);
22 assert.deepStrictEqual(welcome_message, 'Welcome to Nominatim');
25 it('should have a last_updated_: ... ago data', async function () {
26 await page.waitForSelector('abbr[id="data-date"]');
28 let last_updated = await page.$eval('abbr[id="data-date"]', el => el.textContent);
29 assert.ok(last_updated.includes('ago'));
32 it('should show map bounds buttons', async function () {
33 await page.waitForSelector('#map');
34 let show_map_pos_handle = await page.$('#show-map-position');
35 let map_pos_handle = await page.$('#map-position');
37 await show_map_pos_handle.click();
38 assert.strictEqual(await map_pos_handle.evaluate(node => node.style.display), 'block');
40 let map_pos_details = await page.$eval('#map-position-inner', el => el.textContent);
41 map_pos_details = map_pos_details.split(' \n');
43 let map_center_coor = map_pos_details[0]
44 .split('map center: ')[1].split(' view')[0].split(',');
45 let map_zoom = map_pos_details[1].split('map zoom: ')[1];
46 let map_viewbox = map_pos_details[2].split('viewbox: ')[1].split(',');
47 let last_click = map_pos_details[3].split('last click: ')[1];
49 assert.deepStrictEqual(map_center_coor.length, 2);
51 assert.deepStrictEqual(map_viewbox.length, 4);
52 assert.deepStrictEqual(last_click, 'undefined');
54 await page.click('#map-position-close a');
55 assert.strictEqual(await map_pos_handle.evaluate(node => node.style.display), 'none');
59 describe('Search for City of London', function () {
60 before(async function () {
61 page = await browser.newPage();
62 await page.goto('http://localhost:9999/search.html');
63 await page.type('input[name=q]', 'City of London');
64 await page.click('button[type=submit]');
65 await page.waitForSelector('#searchresults');
66 // await page.screenshot({ path: "./screen.png", fullPage: true });
69 after(async function () {
73 it('should have a HTML page title', async function () {
74 assert.equal(await page.title(), 'Result for City of London | Nominatim Demo');
77 it('should have added search params', async function () {
78 let current_url = new URL(await page.url());
79 assert.strictEqual(current_url.searchParams.get('q'), 'City of London');
82 it('should atleast one result', async function () {
83 let results_count = await page.$$eval('#searchresults .result', elements => elements.length);
84 assert.ok(results_count > 1);
87 it('should have show more results button', async function () {
88 let [search_more_btn] = await page.$x("//a[contains(text(), 'Search for more results')]");
89 assert.ok(search_more_btn);
92 it('should display the API request and debug URL', async function () {
93 let link_titles = await page.$$eval('#api-request a', links => links.map(l => l.innerHTML));
94 assert.deepEqual(link_titles, ['API request', 'debug output']);
97 it('should display a map', async function () {
98 await page.waitForSelector('#map');
99 assert.equal((await page.$$('#map')).length, 1);
102 it('should have polygon and marker in map and minimap', async function () {
103 assert.strictEqual((await page.$$('#map .leaflet-overlay-pane path')).length, 4);
106 it('should redirect to details page on clicking details button', async function () {
109 let results = await page.$$('#searchresults .result a');
111 await results[0].click();
112 await page.waitForNavigation();
114 current_url = new URL(await page.url());
115 assert.deepStrictEqual(current_url.pathname, '/details.html');
117 await page.waitForSelector('.container h1');
118 page_header = await page.$eval('.container h1', el => el.textContent);
119 assert.ok(page_header.includes('City of London'));