This commit is contained in:
124
tests/unit/SgsSdkRouteAdapter.spec.ts
Normal file
124
tests/unit/SgsSdkRouteAdapter.spec.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
toGuideRouteResultFromSgs,
|
||||
toGuideRouteResultFromSgsPlan
|
||||
} from '@/data/adapters/sgsSdkRouteAdapter'
|
||||
|
||||
const start = {
|
||||
routeTargetId: 'start-anchor',
|
||||
poiId: 'start',
|
||||
name: '文创 02',
|
||||
floorId: 'L1',
|
||||
floorLabel: '1F',
|
||||
positionGltf: [1, 0, 1] as [number, number, number],
|
||||
routeNodeId: 'start-node'
|
||||
}
|
||||
|
||||
const end = {
|
||||
routeTargetId: 'end-anchor',
|
||||
poiId: 'end',
|
||||
name: '文创盖章打卡',
|
||||
floorId: 'L2',
|
||||
floorLabel: '2F',
|
||||
positionGltf: [8, 0, 8] as [number, number, number],
|
||||
routeNodeId: 'end-node'
|
||||
}
|
||||
|
||||
describe('toGuideRouteResultFromSgsPlan', () => {
|
||||
it('keeps the backend floor-transfer semantic instead of flattening it away', () => {
|
||||
const route = toGuideRouteResultFromSgsPlan({
|
||||
distance: 32,
|
||||
segments: [
|
||||
{ floorId: 'L1', transferType: 'WALK', pathPoints: [{ x: 1, y: 0, z: 1 }, { x: 3, y: 0, z: 3 }] },
|
||||
{
|
||||
floorId: 'L1',
|
||||
fromFloorId: 'L1',
|
||||
targetFloorId: 'L2',
|
||||
transferType: 'ELEVATOR',
|
||||
connectorName: '东侧电梯'
|
||||
},
|
||||
{ floorId: 'L2', transferType: 'WALK', pathPoints: [{ x: 5, y: 0, z: 5 }, { x: 8, y: 0, z: 8 }] }
|
||||
]
|
||||
}, start, end)
|
||||
|
||||
expect(route.floorSegments.map((segment) => segment.floorId)).toEqual(['L1', 'L2'])
|
||||
expect(route.transitions).toEqual([expect.objectContaining({
|
||||
fromFloorId: 'L1',
|
||||
toFloorId: 'L2',
|
||||
transferType: 'ELEVATOR',
|
||||
connectorName: '东侧电梯'
|
||||
})])
|
||||
})
|
||||
|
||||
it('unifies floor aliases with published model floor ids', () => {
|
||||
const rawStart = {
|
||||
...start,
|
||||
floorId: 'floor-db-5',
|
||||
floorLabel: '5F'
|
||||
}
|
||||
const rawEnd = {
|
||||
...end,
|
||||
floorId: 'floor-db-1',
|
||||
floorLabel: '1F'
|
||||
}
|
||||
const route = toGuideRouteResultFromSgsPlan({
|
||||
distance: 20,
|
||||
segments: [
|
||||
{
|
||||
floorId: 'L5',
|
||||
floorCode: 'L5',
|
||||
transferType: 'WALK',
|
||||
pathPoints: [{ x: 1, y: 0, z: 1 }, { x: 3, y: 0, z: 3 }]
|
||||
},
|
||||
{
|
||||
floorId: 'floor-db-5',
|
||||
fromFloorId: 'floor-db-5',
|
||||
targetFloorId: 'L1',
|
||||
transferType: 'ELEVATOR',
|
||||
connectorName: 'B电梯'
|
||||
},
|
||||
{
|
||||
floorId: 'floor-db-1',
|
||||
floorCode: 'L1',
|
||||
transferType: 'WALK',
|
||||
pathPoints: [{ x: 5, y: 0, z: 5 }, { x: 8, y: 0, z: 8 }]
|
||||
}
|
||||
]
|
||||
}, rawStart, rawEnd)
|
||||
|
||||
expect(route.start.floorId).toBe('floor-db-5')
|
||||
expect(route.end.floorId).toBe('floor-db-1')
|
||||
expect(route.floorSegments.map((segment) => segment.floorId)).toEqual([
|
||||
'floor-db-5',
|
||||
'floor-db-1'
|
||||
])
|
||||
expect(route.points.every((point) => (
|
||||
point.floorId === 'floor-db-5' || point.floorId === 'floor-db-1'
|
||||
))).toBe(true)
|
||||
expect(route.transitions).toEqual([expect.objectContaining({
|
||||
fromFloorId: 'floor-db-5',
|
||||
toFloorId: 'floor-db-1'
|
||||
})])
|
||||
})
|
||||
|
||||
it('keeps runtime SDK path aliases aligned with endpoint floors', () => {
|
||||
const rawStart = { ...start, floorId: 'floor-db-5', floorLabel: '5F' }
|
||||
const rawEnd = { ...end, floorId: 'floor-db-1', floorLabel: '1F' }
|
||||
const route = toGuideRouteResultFromSgs({
|
||||
distance: 12,
|
||||
path: [
|
||||
{ nodeId: 'a', floorId: 'L5', x: 1, z: 1 },
|
||||
{ nodeId: 'b', floorId: 'L1', x: 8, z: 8 }
|
||||
]
|
||||
} as never, rawStart, rawEnd)
|
||||
|
||||
expect(route.floorSegments.map((segment) => segment.floorId)).toEqual([
|
||||
'floor-db-5',
|
||||
'floor-db-1'
|
||||
])
|
||||
expect(route.points.map((point) => point.floorId)).toEqual([
|
||||
'floor-db-5',
|
||||
'floor-db-1'
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user