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]);
13 assert.deepStrictEqual(identifyLinkInQuery('R-123'), ['R', -123]);
16 it('.formatLabel', function () {
18 assert.equal(formatLabel({}), '');
20 // if label set, that becomes the label
21 assert.equal(formatLabel({ label: 'A Label' }), 'A Label');
23 // type, but nicely formatted
24 assert.equal(formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop');
26 // type=yes, so we use the category
27 assert.equal(formatLabel({ category: 'building', type: 'yes' }), 'Building');
30 it('.wikipediaLink', function () {
37 wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }),
38 '<a href="https://de.wikipedia.org/wiki/Brandenburg Gate" target="_blank">de:Brandenburg Gate</a>'
41 // title includes HTML
43 wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }),
44 '<a href="https://en.wikipedia.org/wiki/Slug & Lattuce" target="_blank">en:Slug & Lattuce</a>'