]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/unit/helpers.js
when searching for OSM Url, show detail page result page
[nominatim-ui.git] / test / unit / helpers.js
1 import assert from 'assert';
2 import { identifyLinkInQuery, formatLabel, wikipediaLink } from '../../src/lib/helpers.js';
3
4 describe('Helpers', function () {
5
6   it('.identifyLinkInQuery', function () {
7     assert.equal(identifyLinkInQuery(''), undefined);
8     assert.equal(identifyLinkInQuery('http://example.com'), undefined);
9
10     assert.deepStrictEqual(identifyLinkInQuery('https://www.openstreetmap.org/relation/1234#map=11/41.2388/-8.3867'), ['R', 1234]);
11     assert.deepStrictEqual(identifyLinkInQuery('n1234'), ['N', 1234]);
12     assert.deepStrictEqual(identifyLinkInQuery('W1234'), ['W', 1234]);
13   });
14
15   it('.formatLabel', function () {
16     // not enough data
17     assert.equal(formatLabel({}), '');
18
19     // if label set, that becomes the label
20     assert.equal(formatLabel({ label: 'A Label' }), 'A Label');
21
22     // type, but nicely formatted
23     assert.equal(formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop');
24
25     // type=yes, so we use the category
26     assert.equal(formatLabel({ category: 'building', type: 'yes' }), 'Building');
27   });
28
29   it('.wikipediaLink', function () {
30     assert.equal(
31       wikipediaLink({}),
32       ''
33     );
34
35     assert.equal(
36       wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }),
37       '<a href="https://de.wikipedia.org/wiki/Brandenburg Gate" target="_blank">de:Brandenburg Gate</a>'
38     );
39
40     // title includes HTML
41     assert.equal(
42       wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }),
43       '<a href="https://en.wikipedia.org/wiki/Slug &amp; Lattuce" target="_blank">en:Slug &amp; Lattuce</a>'
44     );
45   });
46 });