]> git.openstreetmap.org Git - nominatim-ui.git/blob - test/unit/helpers.spec.js
Rebundle latest version
[nominatim-ui.git] / test / unit / helpers.spec.js
1 import { test, expect } from '@playwright/test';
2 import { identifyLinkInQuery, formatLabel } from '../../src/lib/helpers.js';
3
4 test.describe('Helpers', () => {
5
6   test('.identifyLinkInQuery', () => {
7     expect(identifyLinkInQuery('')).toBeUndefined();
8     expect(identifyLinkInQuery('http://example.com')).toBeUndefined();
9
10     expect(identifyLinkInQuery(
11       'https://www.openstreetmap.org/relation/1234#map=11/41.2388/-8.3867'
12     )).toEqual(['R', 1234]);
13     expect(identifyLinkInQuery('n1234')).toEqual(['N', 1234]);
14     expect(identifyLinkInQuery('W1234')).toEqual(['W', 1234]);
15     expect(identifyLinkInQuery('R-123')).toEqual(['R', -123]);
16   });
17
18   test('.formatLabel', () => {
19     // not enough data
20     expect(formatLabel({})).toBe('');
21
22     // if label set, that becomes the label
23     expect(formatLabel({ label: 'A Label' })).toBe('A Label');
24
25     // type, but nicely formatted
26     expect(formatLabel({ category: 'highway', type: 'bus_stop' })).toBe('Bus stop');
27
28     // type=yes, so we use the category
29     expect(formatLabel({ category: 'building', type: 'yes' })).toBe('Building');
30   });
31 });