1 import assert from 'assert';
2 import { identifyLinkInQuery, formatLabel, wikipediaLink } from '../../src/lib/helpers.js';
4 describe('Helpers', function () {
6 it('.identifyLinkInQuery', function () {
7 assert.equal(identifyLinkInQuery(''), undefined);
8 assert.equal(identifyLinkInQuery('http://example.com'), undefined);
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]);
15 it('.formatLabel', function () {
17 assert.equal(formatLabel({}), '');
19 // if label set, that becomes the label
20 assert.equal(formatLabel({ label: 'A Label' }), 'A Label');
22 // type, but nicely formatted
23 assert.equal(formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop');
25 // type=yes, so we use the category
26 assert.equal(formatLabel({ category: 'building', type: 'yes' }), 'Building');
29 it('.wikipediaLink', function () {
36 wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }),
37 '<a href="https://de.wikipedia.org/wiki/Brandenburg Gate" target="_blank">de:Brandenburg Gate</a>'
40 // title includes HTML
42 wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }),
43 '<a href="https://en.wikipedia.org/wiki/Slug & Lattuce" target="_blank">en:Slug & Lattuce</a>'