// FE-COMP-PLACEPOPUP-001 to FE-COMP-PLACEPOPUP-014 import { describe, it, expect } from 'vitest' import { buildPlacePopupHtml, buildPoiPopupHtml } from './placePopup' import { buildPlace } from '../../../tests/helpers/factories' import type { Poi } from './poiCategories' import type { Place } from '../../types' type PopupPlace = Place & { category_color?: string | null category_icon?: string | null category_name?: string | null } function popupPlace(overrides: Partial = {}): PopupPlace { return { ...buildPlace(), category_color: null, category_icon: null, category_name: null, ...overrides, } as PopupPlace } function poi(overrides: Partial = {}): Poi { return { osm_id: 'node/1', name: 'Café Central', lat: 48.21, lng: 16.36, category: 'cafe', poi_type: 'cafe', address: null, website: null, phone: null, opening_hours: null, cuisine: null, source: 'openstreetmap', ...overrides, } } describe('buildPlacePopupHtml', () => { it('FE-COMP-PLACEPOPUP-001: renders the name and nothing else for a bare place', () => { const html = buildPlacePopupHtml(popupPlace({ name: 'Louvre', address: null }), null) expect(html).toContain('Louvre') expect(html).not.toContain(' { const html = buildPlacePopupHtml(popupPlace({ name: 'Bar & "Grill" x' }), null) expect(html).toContain('Bar & "Grill" <b>x</b>') expect(html).not.toContain('x') }) it('FE-COMP-PLACEPOPUP-003: embeds a data: thumbnail as an img', () => { const html = buildPlacePopupHtml(popupPlace(), 'data:image/jpeg;base64,AAAA') expect(html).toContain(' { const html = buildPlacePopupHtml(popupPlace(), '/api/maps/place-photo/abc123') expect(html).toContain(' { const html = buildPlacePopupHtml(popupPlace(), 'https://lh3.googleusercontent.com/p/AF1') expect(html).not.toContain(' { const html = buildPlacePopupHtml( popupPlace({ category_name: 'Museum', category_icon: 'Landmark', category_color: '#6366F1' }), null, ) expect(html).toContain('Museum') expect(html).toContain(' { const known = buildPlacePopupHtml(popupPlace({ category_name: 'X', category_icon: 'MapPin' }), null) const unknown = buildPlacePopupHtml(popupPlace({ category_name: 'X', category_icon: 'NoSuchIcon' }), null) const svgOf = (s: string) => s.slice(s.indexOf('')) expect(svgOf(unknown)).toBe(svgOf(known)) }) it('FE-COMP-PLACEPOPUP-008: a category without an icon draws no category row', () => { const html = buildPlacePopupHtml(popupPlace({ category_name: 'Museum', category_icon: null }), null) expect(html).not.toContain('Museum') expect(html).not.toContain(' { const html = buildPlacePopupHtml(popupPlace({ category_name: null, category_icon: 'Landmark' }), null) expect(html).not.toContain(' { const html = buildPlacePopupHtml(popupPlace({ address: 'Rue & B' }), null) expect(html).toContain('Rue <A> & B') }) it('FE-COMP-PLACEPOPUP-011: a category icon with no colour falls back to grey', () => { const html = buildPlacePopupHtml( popupPlace({ category_name: 'Museum', category_icon: 'Landmark', category_color: null }), null, ) expect(html).toContain('#6b7280') }) }) describe('buildPoiPopupHtml', () => { it('FE-COMP-PLACEPOPUP-012: renders the POI name with its category-coloured icon', () => { const html = buildPoiPopupHtml(poi({ name: 'Café Central', category: 'cafe' })) expect(html).toContain('Café Central') expect(html).toContain(' { const html = buildPoiPopupHtml(poi({ category: 'not-a-category', name: 'Somewhere' })) expect(html).not.toContain(' { expect(buildPoiPopupHtml(poi({ address: null }))).not.toContain('margin-top:3px') expect(buildPoiPopupHtml(poi({ address: 'Herrengasse 14 & 16' }))).toContain('Herrengasse 14 & 16') }) })