]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/search.js
b398b0d5d2f009f9bf2de9fdc31f02962edbf825
[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.$x("//a[contains(text(), 'Search for more results')]");
92       assert.ok(search_more_btn);
93     });
94
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']);
98     });
99
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]);
104
105       assert.deepStrictEqual(api_request_url.searchParams.has('polygon_geojson'), false);
106       assert.deepStrictEqual(debug_url.searchParams.has('polygon_geojson'), false);
107     });
108
109     it('should display a map', async function () {
110       await page.waitForSelector('#map');
111       assert.equal((await page.$$('#map')).length, 1);
112     });
113
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);
117
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]);
121
122       assert.deepStrictEqual(api_request_url.searchParams.has('dedupe'), false);
123       assert.deepStrictEqual(debug_url.searchParams.has('dedupe'), false);
124     });
125
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);
128     });
129
130     it('should redirect to details page on clicking details button', async function () {
131       let current_url;
132       let page_header;
133       let results = await page.$$('#searchresults .result a');
134
135       await results[0].click();
136       await page.waitForSelector('table#address');
137
138       current_url = new URL(await page.url());
139       assert.deepStrictEqual(current_url.pathname, '/details.html');
140
141       await page.waitForSelector('.container h1');
142       page_header = await page.$eval('.container h1', el => el.textContent);
143       assert.ok(page_header.includes('Paris'));
144     });
145   });
146 });