]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/unit/helpers.js
rollup v2->v3, convert -require- to ESM style -import-
[nominatim-ui.git] / test / unit / helpers.js
1 import assert from 'assert';
2 import { formatLabel, wikipediaLink } from '../../src/lib/helpers.js';
3
4 describe('Helpers', function () {
5
6   it('.formatLabel', function () {
7     // not enough data
8     assert.equal(formatLabel({}), '');
9
10     // if label set, that becomes the label
11     assert.equal(formatLabel({ label: 'A Label' }), 'A Label');
12
13     // type, but nicely formatted
14     assert.equal(formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop');
15
16     // type=yes, so we use the category
17     assert.equal(formatLabel({ category: 'building', type: 'yes' }), 'Building');
18   });
19
20   it('.wikipediaLink', function () {
21     assert.equal(
22       wikipediaLink({}),
23       ''
24     );
25
26     assert.equal(
27       wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }),
28       '<a href="https://de.wikipedia.org/wiki/Brandenburg Gate" target="_blank">de:Brandenburg Gate</a>'
29     );
30
31     // title includes HTML
32     assert.equal(
33       wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }),
34       '<a href="https://en.wikipedia.org/wiki/Slug &amp; Lattuce" target="_blank">en:Slug &amp; Lattuce</a>'
35     );
36   });
37 });