@@ -19,11 +19,13 @@ export const formatNavFloorLabel = (floorId: string) => {
|
|||||||
const value = Number(match[1])
|
const value = Number(match[1])
|
||||||
if (Number.isNaN(value)) return floorId
|
if (Number.isNaN(value)) return floorId
|
||||||
|
|
||||||
|
if (value === 1.5) return 'MF'
|
||||||
return value < 0 ? `B${Math.abs(value)}` : `${value}F`
|
return value < 0 ? `B${Math.abs(value)}` : `${value}F`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const navFloorIdFromLabel = (labelOrId: string) => {
|
export const navFloorIdFromLabel = (labelOrId: string) => {
|
||||||
if (floorIdPattern.test(labelOrId)) return labelOrId
|
if (floorIdPattern.test(labelOrId)) return labelOrId
|
||||||
|
if (labelOrId.trim().toUpperCase() === 'MF') return 'L1.5'
|
||||||
|
|
||||||
const basementMatch = labelOrId.match(/^B(\d+(?:\.\d+)?)$/i)
|
const basementMatch = labelOrId.match(/^B(\d+(?:\.\d+)?)$/i)
|
||||||
if (basementMatch) return `L-${basementMatch[1]}`
|
if (basementMatch) return `L-${basementMatch[1]}`
|
||||||
|
|||||||
@@ -225,8 +225,8 @@ export const formatSgsFloorLabel = (floorCode?: string | null, floorName?: strin
|
|||||||
const basementMatch = floorCode?.match(/^L-(\d+(?:\.\d+)?)$/)
|
const basementMatch = floorCode?.match(/^L-(\d+(?:\.\d+)?)$/)
|
||||||
if (basementMatch) return `B${basementMatch[1]}`
|
if (basementMatch) return `B${basementMatch[1]}`
|
||||||
|
|
||||||
const floorMatch = floorCode?.match(/^L(\d+(?:\.\d+)?)$/)
|
const floorMatch = floorCode?.match(/^L(\d+(?:\.\d+)?)$/)
|
||||||
if (floorMatch) return `${floorMatch[1]}F`
|
if (floorMatch) return floorMatch[1] === '1.5' ? 'MF' : `${floorMatch[1]}F`
|
||||||
|
|
||||||
return floorName || floorCode || '未知楼层'
|
return floorName || floorCode || '未知楼层'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ interface FloorLike {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const indoorFloorCodePattern = /^L-?\d+(?:\.\d+)?$/i
|
const indoorFloorCodePattern = /^L-?\d+(?:\.\d+)?$/i
|
||||||
const indoorFloorLabelPattern = /^(?:B\d+(?:\.\d+)?|\d+(?:\.\d+)?F)$/i
|
const indoorFloorLabelPattern = /^(?:B\d+(?:\.\d+)?|\d+(?:\.\d+)?F|MF)$/i
|
||||||
const rawNumericIdPattern = /^\d{6,}$/
|
const rawNumericIdPattern = /^\d{6,}$/
|
||||||
const nonNavigableFloorPattern = /(EXTERIOR|OUTDOOR|BUILDING|FACADE|EXTERNAL|外立面|建筑外观|建筑外立面|馆外模型|馆外场景|馆外底图|馆外建筑|馆外外观|馆外)$/i
|
const nonNavigableFloorPattern = /(EXTERIOR|OUTDOOR|BUILDING|FACADE|EXTERNAL|外立面|建筑外观|建筑外立面|馆外模型|馆外场景|馆外底图|馆外建筑|馆外外观|馆外)$/i
|
||||||
|
|
||||||
@@ -37,6 +37,8 @@ const parseFloorLevelFromToken = (value: unknown) => {
|
|||||||
const labelMatch = normalized.match(/^(\d+(?:\.\d+)?)F$/)
|
const labelMatch = normalized.match(/^(\d+(?:\.\d+)?)F$/)
|
||||||
if (labelMatch) return Number(labelMatch[1])
|
if (labelMatch) return Number(labelMatch[1])
|
||||||
|
|
||||||
|
if (normalized === 'MF') return 1.5
|
||||||
|
|
||||||
const codeMatch = normalized.match(/^L(-?\d+(?:\.\d+)?)$/)
|
const codeMatch = normalized.match(/^L(-?\d+(?:\.\d+)?)$/)
|
||||||
if (codeMatch) return Number(codeMatch[1])
|
if (codeMatch) return Number(codeMatch[1])
|
||||||
|
|
||||||
|
|||||||
17
tests/unit/floorPresentation.spec.ts
Normal file
17
tests/unit/floorPresentation.spec.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { formatNavFloorLabel, navFloorIdFromLabel } from '@/data/adapters/navAssetsAdapter'
|
||||||
|
import { formatSgsFloorLabel } from '@/data/adapters/sgsSdkGuideAdapter'
|
||||||
|
import { getFloorSortLevel, isIndoorNavigableFloor } from '@/domain/guideFloor'
|
||||||
|
|
||||||
|
describe('中间层游客展示', () => {
|
||||||
|
it('将稳定层 ID L1.5 显示为 MF,并可反向解析', () => {
|
||||||
|
expect(formatNavFloorLabel('L1.5')).toBe('MF')
|
||||||
|
expect(navFloorIdFromLabel('MF')).toBe('L1.5')
|
||||||
|
expect(formatSgsFloorLabel('L1.5')).toBe('MF')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('MF 保持可导航和正确的楼层排序', () => {
|
||||||
|
expect(isIndoorNavigableFloor({ label: 'MF' })).toBe(true)
|
||||||
|
expect(getFloorSortLevel({ label: 'MF' })).toBe(1.5)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user