]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/search.spec.js
Rebundle latest version
[nominatim-ui.git] / test / search.spec.js
1 import { test, expect } from './shared.js';
2
3 test.describe('Search Page', () => {
4   test.skip(() => !!process.env.REVERSE_ONLY, 'Skipped in reverse-only mode');
5
6   test.describe('No search', () => {
7     let page;
8
9     test.beforeAll(async ({ browser }) => {
10       page = await browser.newPage();
11       await page.goto('/search.html');
12     });
13
14     test.afterAll(async () => {
15       await page.close();
16     });
17
18     test('should have a HTML page title', async () => {
19       expect(await page.title()).toBe('Nominatim Demo');
20     });
21
22     test('should have a welcome message', async () => {
23       await expect(page.locator('#welcome h2')).toHaveText(
24         'Welcome to Nominatim'
25       );
26     });
27
28     test('should have a last_updated_: ... ago data', async () => {
29       await page.waitForFunction(
30         () => {
31           const el = document.querySelector('abbr[id="data-date"]');
32           return el && el.textContent.includes('ago');
33         },
34         { timeout: 10000 }
35       );
36     });
37
38     test('should show map bounds buttons', async () => {
39       await page.locator('#map').waitFor();
40       await expect(page.locator('#map-position-inner')).toHaveCount(0);
41
42       await page.locator('#show-map-position').click();
43
44       let map_pos_details = await page.locator(
45         '#map-position-inner'
46       ).textContent();
47       map_pos_details = map_pos_details.split('  ');
48
49       const map_center_coords = map_pos_details[0]
50         .split('map center: ')[1].split(' view')[0].split(',');
51       const map_zoom = map_pos_details[1].split('map zoom: ')[1];
52       const map_viewbox = map_pos_details[2]
53         .split('viewbox: ')[1].split(',');
54       const last_click = map_pos_details[3].split('last click: ')[1];
55
56       expect(map_center_coords.length).toBe(2);
57       expect(map_zoom).toBeTruthy();
58       expect(map_viewbox.length).toBe(4);
59       expect(last_click).toBe('-');
60
61       await page.locator('#map-position-close a').click();
62       await expect(page.locator('#map-position-inner')).toHaveCount(0);
63       await expect(page.locator('#show-map-position')).toBeVisible();
64     });
65   });
66
67   test.describe('Search for Paris', () => {
68     let page;
69
70     test.beforeAll(async ({ browser }) => {
71       page = await browser.newPage();
72       await page.goto('/search.html');
73       await page.locator('input[name=q]').fill('Paris');
74       await page.locator('button[type=submit]').first().click();
75       await page.locator('#searchresults').waitFor();
76     });
77
78     test.afterAll(async () => {
79       await page.close();
80     });
81
82     test('should have a HTML page title', async () => {
83       expect(await page.title()).toBe('Result for Paris | Nominatim Demo');
84     });
85
86     test('should have added search params', async () => {
87       const current_url = new URL(page.url());
88       expect(current_url.searchParams.get('q')).toBe('Paris');
89     });
90
91     test('should have at least one result', async () => {
92       const results_count = await page.locator(
93         '#searchresults .result'
94       ).count();
95       expect(results_count).toBeGreaterThan(1);
96     });
97
98     test('should have show more results button', async () => {
99       await expect(
100         page.locator('a', { hasText: 'Search for more results' })
101       ).toBeVisible();
102     });
103
104     test('should display the API request and debug URL', async () => {
105       const link_titles = await page.locator(
106         '#api-request a'
107       ).evaluateAll(links => links.map(l => l.innerHTML));
108       expect(link_titles).toEqual(['API request', 'debug output']);
109     });
110
111     test('should not have polygon params in API request and debug URL',
112       async () => {
113         const links_href = await page.locator(
114           '#api-request a'
115         ).evaluateAll(links => links.map(l => l.href));
116         const api_request_url = new URL(links_href[0]);
117         const debug_url = new URL(links_href[1]);
118
119         expect(api_request_url.searchParams.has('polygon_geojson')).toBe(
120           false
121         );
122         expect(debug_url.searchParams.has('polygon_geojson')).toBe(false);
123       }
124     );
125
126     test('should display a map', async () => {
127       await expect(page.locator('#map')).toHaveCount(1);
128     });
129
130     test('should default to dedupe=1', async () => {
131       expect(
132         await page.locator('#option_dedupe').isChecked()
133       ).toBe(true);
134
135       const links_href = await page.locator(
136         '#api-request a'
137       ).evaluateAll(links => links.map(l => l.href));
138       const api_request_url = new URL(links_href[0]);
139       const debug_url = new URL(links_href[1]);
140
141       expect(api_request_url.searchParams.has('dedupe')).toBe(false);
142       expect(debug_url.searchParams.has('dedupe')).toBe(false);
143     });
144
145     test('should have polygon and marker in map and minimap', async () => {
146       await expect(
147         page.locator('#map .leaflet-overlay-pane path')
148       ).toHaveCount(4);
149     });
150
151     test('should redirect to details page on clicking details button',
152       async () => {
153         await page.locator('#searchresults .result a').first().click();
154         await page.locator('table#address').waitFor();
155
156         const current_url = new URL(page.url());
157         expect(current_url.pathname).toBe('/details.html');
158
159         await expect(page.locator('.container h1')).toContainText('Paris');
160       }
161     );
162   });
163
164   test.describe('Structured search for Paris', () => {
165     let page;
166
167     test.beforeAll(async ({ browser }) => {
168       page = await browser.newPage();
169       await page.goto('/search.html');
170       await page.locator(".nav-link[href='#structured']").click();
171       await page.locator('input[name=city]').fill('Paris');
172       await page.locator('input[name=country]').fill('USA');
173       await page.locator('#structured button[type=submit]').click();
174       await page.locator('#searchresults').waitFor();
175     });
176
177     test.afterAll(async () => {
178       await page.close();
179     });
180
181     test('should have a HTML page title', async () => {
182       expect(await page.title()).toBe(
183         'Result for Paris, USA | Nominatim Demo'
184       );
185     });
186
187     test('should have added search params', async () => {
188       const current_url = new URL(page.url());
189       expect(current_url.searchParams.get('q')).toBeNull();
190       expect(current_url.searchParams.get('city')).toBe('Paris');
191       expect(current_url.searchParams.get('country')).toBe('USA');
192     });
193
194     test('should have at least one result', async () => {
195       const results_count = await page.locator(
196         '#searchresults .result'
197       ).count();
198       expect(results_count).toBeGreaterThan(1);
199     });
200   });
201
202   test.describe('Search for OSM URL', () => {
203     let page;
204
205     test.beforeAll(async ({ browser }) => {
206       page = await browser.newPage();
207       await page.goto('/search.html');
208       await page.locator('input[name=q]').fill(
209         'https://www.openstreetmap.org/relation/3459013#map=11/41.2388/-8.3867'
210       );
211       await page.locator('button[type=submit]').first().click();
212       await page.locator('table#address').waitFor();
213     });
214
215     test.afterAll(async () => {
216       await page.close();
217     });
218
219     test('should redirect to detail page search', async () => {
220       expect(await page.title()).toBe(
221         'Details for R3459013 | Nominatim Demo'
222       );
223       await expect(page.locator('.container h1')).toContainText('Porto');
224     });
225   });
226 });