Files
frontend-miniapp/tests/unit/visitorPoiPresentation.spec.ts
lyf 9ea1bfab71
Some checks failed
CI / verify (push) Has been cancelled
同步 sgs-frontend-mobile 源码
2026-07-27 11:26:01 +08:00

60 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { MuseumPoi } from '@/domain/museum'
import { createVisitorPoiPresentations } from '@/view-models/visitorPoiPresentation'
const poi = (id: string, name: string, floorLabel = '1F', hallName?: string): MuseumPoi => ({
id,
name,
floorId: floorLabel === '1F' ? 'L1' : 'L2',
floorLabel,
hallName,
accessible: false,
primaryCategory: { id: 'facility', label: '服务设施' },
categories: []
})
describe('VisitorPoiPresentation', () => {
it.each([
['展厅 7生态厅', '生态厅'],
['男卫生间00', '男卫生间'],
['贵宾卫生间', '贵宾卫生间'],
['L1 K电梯', '电梯'],
['L1_H_楼梯23', '楼梯'],
['L1_导览屏_02', '导览屏'],
['B2_A_无障碍卫生间02', '无障碍卫生间'],
['L1 Cinema', 'Cinema']
])('规范游客展示名 %s', (rawName, displayName) => {
const result = createVisitorPoiPresentations([poi('p1', rawName)])
expect(result.get('p1')?.displayName).toBe(displayName)
})
it('用真实楼层或展厅区分重复设施', () => {
const result = createVisitorPoiPresentations([
poi('p1', '无障碍卫生间', '1F', '恐龙厅'),
poi('p2', '无障碍卫生间', '2F', '生态厅')
])
expect(result.get('p1')?.displayName).toBe('无障碍卫生间 · 1F · 恐龙厅 · 服务设施')
expect(result.get('p2')?.displayName).toBe('无障碍卫生间 · 2F · 生态厅 · 服务设施')
})
it('用稳定序号区分同楼层同区域的重名设施', () => {
const result = createVisitorPoiPresentations([
poi('p1', '无障碍卫生间', '1F', '恐龙厅'),
poi('p2', '无障碍卫生间', '1F', '恐龙厅')
])
expect(result.get('p1')?.displayName).toBe('无障碍卫生间 · 1F · 恐龙厅 · 服务设施')
expect(result.get('p2')?.displayName).toBe('无障碍卫生间 · 1F · 恐龙厅 · 服务设施 2')
})
it('省略与名称重复的展厅提示,保留最小位置上下文', () => {
const result = createVisitorPoiPresentations([
poi('p1', '球幕影院', '1F', '球幕影院')
])
expect(result.get('p1')?.displayName).toBe('球幕影院')
expect(result.get('p1')?.locationHint).toBe('1F · 服务设施')
})
})