1 import { test, expect } from './shared.js';
3 test.describe('Search Page', () => {
4 test.skip(() => !!process.env.REVERSE_ONLY, 'Skipped in reverse-only mode');
6 test.describe('No search', () => {
9 test.beforeAll(async ({ browser }) => {
10 page = await browser.newPage();
11 await page.goto('/search.html');
14 test.afterAll(async () => {
18 test('should have a HTML page title', async () => {
19 expect(await page.title()).toBe('Nominatim Demo');
22 test('should have a welcome message', async () => {
23 await expect(page.locator('#welcome h2')).toHaveText(
24 'Welcome to Nominatim'
28 test('should have a last_updated_: ... ago data', async () => {
29 await page.waitForFunction(
31 const el = document.querySelector('abbr[id="data-date"]');
32 return el && el.textContent.includes('ago');
38 test('should show map bounds buttons', async () => {
39 await page.locator('#map').waitFor();
40 await expect(page.locator('#map-position-inner')).toHaveCount(0);
42 await page.locator('#show-map-position').click();
44 let map_pos_details = await page.locator(
47 map_pos_details = map_pos_details.split(' ');
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];
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('-');
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();
67 test.describe('Search for Paris', () => {
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();
78 test.afterAll(async () => {
82 test('should have a HTML page title', async () => {
83 expect(await page.title()).toBe('Result for Paris | Nominatim Demo');
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');
91 test('should have at least one result', async () => {
92 const results_count = await page.locator(
93 '#searchresults .result'
95 expect(results_count).toBeGreaterThan(1);
98 test('should have show more results button', async () => {
100 page.locator('a', { hasText: 'Search for more results' })
104 test('should display the API request and debug URL', async () => {
105 const link_titles = await page.locator(
107 ).evaluateAll(links => links.map(l => l.innerHTML));
108 expect(link_titles).toEqual(['API request', 'debug output']);
111 test('should not have polygon params in API request and debug URL',
113 const links_href = await page.locator(
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]);
119 expect(api_request_url.searchParams.has('polygon_geojson')).toBe(
122 expect(debug_url.searchParams.has('polygon_geojson')).toBe(false);
126 test('should display a map', async () => {
127 await expect(page.locator('#map')).toHaveCount(1);
130 test('should default to dedupe=1', async () => {
132 await page.locator('#option_dedupe').isChecked()
135 const links_href = await page.locator(
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]);
141 expect(api_request_url.searchParams.has('dedupe')).toBe(false);
142 expect(debug_url.searchParams.has('dedupe')).toBe(false);
145 test('should have polygon and marker in map and minimap', async () => {
147 page.locator('#map .leaflet-overlay-pane path')
151 test('should redirect to details page on clicking details button',
153 await page.locator('#searchresults .result a').first().click();
154 await page.locator('table#address').waitFor();
156 const current_url = new URL(page.url());
157 expect(current_url.pathname).toBe('/details.html');
159 await expect(page.locator('.container h1')).toContainText('Paris');
164 test.describe('Structured search for Paris', () => {
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();
177 test.afterAll(async () => {
181 test('should have a HTML page title', async () => {
182 expect(await page.title()).toBe(
183 'Result for Paris, USA | Nominatim Demo'
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');
194 test('should have at least one result', async () => {
195 const results_count = await page.locator(
196 '#searchresults .result'
198 expect(results_count).toBeGreaterThan(1);
202 test.describe('Search for OSM URL', () => {
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'
211 await page.locator('button[type=submit]').first().click();
212 await page.locator('table#address').waitFor();
215 test.afterAll(async () => {
219 test('should redirect to detail page search', async () => {
220 expect(await page.title()).toBe(
221 'Details for R3459013 | Nominatim Demo'
223 await expect(page.locator('.container h1')).toContainText('Porto');