]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/unit/helpers.js
Convert some link functions to Svelte components (#296)
[nominatim-ui.git] / test / unit / helpers.js
1 import assert from 'assert';
2 import { identifyLinkInQuery, formatLabel } 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 });