]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/search.js
upgrade puppeteer to v22
[nominatim-ui.git] / test / search.js
1 import assert from 'assert';
2
3 describe('Search Page', function () {
4   let page;
5
6   // eslint-disable-next-line mocha/no-setup-in-describe
7   if (process.env.REVERSE_ONLY) return;
8
9   describe('No search', function () {
10     before(async function () {
11       page = await browser.newPage();
12       await page.goto('http://localhost:9999/search.html');
13     });
14
15     after(async function () {
16       await page.close();
17     });
18
19     it('should have a HTML page title', async function () {
20       assert.equal(await page.title(), 'Nominatim Demo');
21     });
22
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');
26     });
27
28     it('should have a last_updated_: ... ago data', async function () {
29       await page.waitForSelector('abbr[id="data-date"]');
30
31       let last_updated = await page.$eval('abbr[id="data-date"]', el => el.textContent);
32       assert.ok(last_updated.includes('ago'));
33     });
34
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');
39
40       await show_map_pos_handle.click();
41       assert.strictEqual(await map_pos_handle.evaluate(node => node.style.display), 'block');
42
43       let map_pos_details = await page.$eval('#map-position-inner', el => el.textContent);
44       map_pos_details = map_pos_details.split(' \n');
45
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];
51
52       assert.deepStrictEqual(map_center_coor.length, 2);
53       assert.ok(map_zoom);
54       assert.deepStrictEqual(map_viewbox.length, 4);
55       assert.deepStrictEqual(last_click, 'undefined');
56
57       await page.click('#map-position-close a');
58       assert.strictEqual(await map_pos_handle.evaluate(node => node.style.display), 'none');
59     });
60   });
61
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 });
70     });
71
72     after(async function () {
73       await page.close();
74     });
75
76     it('should have a HTML page title', async function () {
77       assert.equal(await page.title(), 'Result for Paris | Nominatim Demo');
78     });
79
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');
83     });
84
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);
88     });
89
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')]"
93       );
94       assert.ok(search_more_btn);
95     });
96
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']);
100     });
101
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]);
106
107       assert.deepStrictEqual(api_request_url.searchParams.has('polygon_geojson'), false);
108       assert.deepStrictEqual(debug_url.searchParams.has('polygon_geojson'), false);
109     });
110
111     it('should display a map', async function () {
112       await page.waitForSelector('#map');
113       assert.equal((await page.$$('#map')).length, 1);
114     });
115
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);
119
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]);
123
124       assert.deepStrictEqual(api_request_url.searchParams.has('dedupe'), false);
125       assert.deepStrictEqual(debug_url.searchParams.has('dedupe'), false);
126     });
127
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);
130     });
131
132     it('should redirect to details page on clicking details button', async function () {
133       let current_url;
134       let page_header;
135       let results = await page.$$('#searchresults .result a');
136
137       await results[0].click();
138       await page.waitForSelector('table#address');
139
140       current_url = new URL(await page.url());
141       assert.deepStrictEqual(current_url.pathname, '/details.html');
142
143       await page.waitForSelector('.container h1');
144       page_header = await page.$eval('.container h1', el => el.textContent);
145       assert.ok(page_header.includes('Paris'));
146     });
147   });
148
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');
156     });
157
158     after(async function () {
159       await page.close();
160     });
161
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'));
165     });
166   });
167 });