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