1 import { test, expect } from '@playwright/test';
2 import { identifyLinkInQuery, formatLabel } from '../../src/lib/helpers.js';
4 test.describe('Helpers', () => {
6 test('.identifyLinkInQuery', () => {
7 expect(identifyLinkInQuery('')).toBeUndefined();
8 expect(identifyLinkInQuery('http://example.com')).toBeUndefined();
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]);
18 test('.formatLabel', () => {
20 expect(formatLabel({})).toBe('');
22 // if label set, that becomes the label
23 expect(formatLabel({ label: 'A Label' })).toBe('A Label');
25 // type, but nicely formatted
26 expect(formatLabel({ category: 'highway', type: 'bus_stop' })).toBe('Bus stop');
28 // type=yes, so we use the category
29 expect(formatLabel({ category: 'building', type: 'yes' })).toBe('Building');