]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/unit/helpers.js
Rebundle latest version
[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     assert.deepStrictEqual(identifyLinkInQuery('R-123'), ['R', -123]);
14   });
15
16   it('.formatLabel', function () {
17     // not enough data
18     assert.equal(formatLabel({}), '');
19
20     // if label set, that becomes the label
21     assert.equal(formatLabel({ label: 'A Label' }), 'A Label');
22
23     // type, but nicely formatted
24     assert.equal(formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop');
25
26     // type=yes, so we use the category
27     assert.equal(formatLabel({ category: 'building', type: 'yes' }), 'Building');
28   });
29
30   it('.wikipediaLink', function () {
31     assert.equal(
32       wikipediaLink({}),
33       ''
34     );
35
36     assert.equal(
37       wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }),
38       '<a href="https://de.wikipedia.org/wiki/Brandenburg Gate" target="_blank">de:Brandenburg Gate</a>'
39     );
40
41     // title includes HTML
42     assert.equal(
43       wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }),
44       '<a href="https://en.wikipedia.org/wiki/Slug &amp; Lattuce" target="_blank">en:Slug &amp; Lattuce</a>'
45     );
46   });
47 });