]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/details.spec.js
Rebundle latest version
[nominatim-ui.git] / test / details.spec.js
1 import { test, expect } from './shared.js';
2
3 const reverse_only = !!process.env.REVERSE_ONLY;
4
5 test.describe('Details Page', () => {
6
7   test.describe('No search', () => {
8     let page;
9
10     test.beforeAll(async ({ browser }) => {
11       page = await browser.newPage();
12       await page.goto('/details.html');
13     });
14
15     test.afterAll(async () => {
16       await page.close();
17     });
18
19     test('should have a HTML page title', async () => {
20       expect(await page.title()).toBe('Nominatim Demo');
21     });
22   });
23
24   test.describe('With search - no place found', () => {
25     let page;
26
27     test.beforeAll(async ({ browser }) => {
28       page = await browser.newPage();
29       await page.goto('/details.html');
30       await page.locator('input[type=edit]').fill('N6');
31       await page.locator('button[type=submit]').click();
32       await page.locator('#api-request').waitFor();
33     });
34
35     test.afterAll(async () => {
36       await page.close();
37     });
38
39     test('should display error', async () => {
40       await expect(page.locator('body')).toContainText(
41         'No place with that OSM ID found'
42       );
43     });
44   });
45
46   test.describe('With search - Vaduz (Liechtenstein)', () => {
47     let page;
48
49     test.beforeAll(async ({ browser }) => {
50       page = await browser.newPage();
51       await page.goto('/details.html');
52       await page.locator('input[type=edit]').fill('R1155956');
53       await page.locator('button[type=submit]').click();
54       await page.locator('table#address').waitFor();
55     });
56
57     test.afterAll(async () => {
58       await page.close();
59     });
60
61     test('should have header title', async () => {
62       await expect(page.locator('.container h1')).toContainText('Vaduz');
63     });
64
65     test('should have OSM link', async () => {
66       const url = 'https://www.openstreetmap.org/relation/1155956';
67       await expect(page.locator(`a[href="${url}"]`)).toHaveCount(2);
68     });
69
70     // Reverse-only installation have no search index, therefore no keywords
71     if (!reverse_only) {
72
73       test('should have a link to postcode which includes country code',
74         async () => {
75           const url = 'search.html?postalcode=9490&country=li';
76           await expect(page.locator(`a[href="${url}"]`)).toHaveCount(1);
77         }
78       );
79
80       test('should change url and add new header on clicking display keywords',
81         async () => {
82           await page.locator('a', { hasText: 'display keywords' }).click();
83           await page.waitForURL(/keywords=1/);
84
85           const current_url = new URL(page.url());
86           expect(current_url.searchParams.get('keywords')).toBe('1');
87
88           await page.locator('h3').first().waitFor();
89           const display_headers = await page.locator('h3').evaluateAll(
90             elements => elements.map(el => el.textContent)
91           );
92           expect(display_headers).toEqual(
93             ['Name Keywords', 'Address Keywords']
94           );
95
96           await expect(page.locator('body')).toContainText('vadouz');
97         }
98       );
99     }
100
101     test('should support case-insensitive search, can navigate to new page',
102       async () => {
103         await page.locator('input[type=edit]').fill('w375257537');
104         await page.locator('button[type=submit]').click();
105
106         await page.locator(
107           'a[href="https://www.openstreetmap.org/way/375257537"]'
108         ).first().waitFor();
109         await expect(page.locator('.container h1')).toContainText('Taj Mahal');
110       }
111     );
112   });
113
114   test.describe(
115     'With street search - a place that is parent of buildings',
116     () => {
117       let page;
118
119       test.beforeAll(async ({ browser }) => {
120         page = await browser.newPage();
121         await page.goto(
122           '/details.html?osmtype=W&osmid=32703083'
123         );
124         await page.locator('.container .row').first().waitFor();
125       });
126
127       test.afterAll(async () => {
128         await page.close();
129       });
130
131       test('should change page url on clicking display child places',
132         async () => {
133           await expect(page.locator('body')).toContainText('Gafleistrasse');
134
135           await page.locator(
136             'a', { hasText: 'display child places' }
137           ).click();
138           await page.waitForURL(/hierarchy=1/);
139           await page.locator('table#address').waitFor();
140
141           const current_url = new URL(page.url());
142           expect(current_url.searchParams.get('hierarchy')).toBe('1');
143
144           await expect(page.locator('body')).toContainText('bus_stop');
145         }
146       );
147     }
148   );
149
150   test.describe('Place without name, keywords, hierarchy', () => {
151     let page;
152
153     // e.g. a numeric house number
154     test.beforeAll(async ({ browser }) => {
155       page = await browser.newPage();
156       await page.goto(
157         '/details.html?osmtype=N&osmid=946563004&keywords=1&hierarchy=1'
158       );
159       await page.locator('.container .row').first().waitFor();
160     });
161
162     test.afterAll(async () => {
163       await page.close();
164     });
165
166     test('should display No Name, no keywords, no hierarchy', async () => {
167       await expect(page.locator('body')).toContainText('NameNo Name');
168       if (!process.env.REVERSE_ONLY) {
169         await expect(page.locator('body')).toContainText(
170           'Place has no keywords'
171         );
172       }
173       await expect(page.locator('body')).toContainText(
174         'Place is not parent of other places'
175       );
176     });
177   });
178 });