forked from zhouruizhe/gmTouringMiniApp
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import type { PoiCategory, PoiSummary } from '@/domain/poi'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { buildMarkerIdMap, createPoiMarkers } from '@/services/map'
|
|
|
|
const categories: PoiCategory[] = [{
|
|
code: 'park',
|
|
name: '公园绿地',
|
|
markerIcon: '/static/markers/park.png',
|
|
selectedMarkerIcon: '/static/markers/park-selected.png',
|
|
sortOrder: 1,
|
|
status: 'enabled',
|
|
}]
|
|
|
|
function summary(id: string): PoiSummary {
|
|
return {
|
|
id,
|
|
name: id,
|
|
categoryCode: 'park',
|
|
categoryName: '公园绿地',
|
|
tagCodes: ['family'],
|
|
tags: [{ code: 'family', name: '亲子友好', sortOrder: 1, status: 'enabled' }],
|
|
longitude: 113.9,
|
|
latitude: 22.7,
|
|
coordinateSystem: 'GCJ02',
|
|
coverImage: {
|
|
id: 'cover',
|
|
url: '/static/poi/placeholder.png',
|
|
source: 'test',
|
|
sourceReference: null,
|
|
copyrightStatus: 'cleared',
|
|
licenseEvidence: 'test',
|
|
reviewedBy: 'test',
|
|
reviewedAt: '2026-07-29T00:00:00Z',
|
|
updatedAt: '2026-07-29T00:00:00Z',
|
|
alt: 'test',
|
|
},
|
|
summary: 'test',
|
|
description: 'test description',
|
|
address: 'test address',
|
|
recommendationIndex: 4,
|
|
recommendationSource: 'official_editorial',
|
|
openingHoursText: '开放时间待确认',
|
|
}
|
|
}
|
|
|
|
describe('map marker adapter', () => {
|
|
it('keeps numeric IDs stable when filter order changes', () => {
|
|
const first = buildMarkerIdMap(['poi-b', 'poi-a'])
|
|
const second = buildMarkerIdMap(['poi-a', 'poi-b'])
|
|
expect(Array.from(first.entries())).toEqual(Array.from(second.entries()))
|
|
})
|
|
|
|
it('maps selected POI to selected marker asset', () => {
|
|
const pois = [summary('poi-a'), summary('poi-b')]
|
|
const map = buildMarkerIdMap(pois.map(poi => poi.id))
|
|
const markers = createPoiMarkers(pois, categories, map, 'poi-b')
|
|
const selectedMarkerId = Array.from(map.entries())
|
|
.find(([, poiId]) => poiId === 'poi-b')?.[0]
|
|
const selected = markers.find(marker => marker.id === selectedMarkerId)
|
|
expect(selected?.iconPath).toBe('/static/markers/park-selected.png')
|
|
expect(selected?.zIndex).toBe(10)
|
|
expect(selected?.height).toBeGreaterThan(selected?.width ?? 0)
|
|
})
|
|
})
|