Files
frontend-miniapp/tests/unit/GuideSemanticZoom.spec.ts
lyf 540bb8627f
Some checks failed
CI / verify (push) Has been cancelled
同步移动端源码并修复小程序嵌入标题
2026-07-28 18:37:40 +08:00

53 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
OUTDOOR_BUILDING_EXIT_ZOOM,
OUTDOOR_BUILDING_ENTRY_ZOOM,
canEnterBuildingSemanticMap,
distanceBetweenCoordinatesMeters,
hasReachedOutdoorExitBoundary
} from '@/domain/guideSemanticZoom'
const museum = { latitude: 22.692763, longitude: 114.363572 }
describe('guide semantic zoom', () => {
it('uses a stable outdoor extent below the building-entry threshold', () => {
expect(OUTDOOR_BUILDING_EXIT_ZOOM).toBeLessThan(OUTDOOR_BUILDING_ENTRY_ZOOM)
})
it('starts the outdoor handoff before the 3D camera reaches its hard zoom clamp', () => {
expect(hasReachedOutdoorExitBoundary(92, 100)).toBe(true)
expect(hasReachedOutdoorExitBoundary(91.9, 100)).toBe(false)
expect(hasReachedOutdoorExitBoundary(0, 0)).toBe(false)
})
it('enters the building only when the museum is centered at the entry zoom', () => {
expect(canEnterBuildingSemanticMap({
...museum,
zoom: OUTDOOR_BUILDING_ENTRY_ZOOM
}, museum)).toBe(true)
})
it('does not enter the building when the outdoor map has not been zoomed in enough', () => {
expect(canEnterBuildingSemanticMap({
...museum,
zoom: OUTDOOR_BUILDING_ENTRY_ZOOM - 0.1
}, museum)).toBe(false)
})
it('does not switch for a similarly zoomed but unrelated outdoor location', () => {
expect(canEnterBuildingSemanticMap({
latitude: 22.698,
longitude: 114.37,
zoom: OUTDOOR_BUILDING_ENTRY_ZOOM + 1
}, museum)).toBe(false)
})
it('calculates a usable geographic distance for the focus guard', () => {
expect(distanceBetweenCoordinatesMeters(museum, museum)).toBe(0)
expect(distanceBetweenCoordinatesMeters(museum, {
latitude: 22.693763,
longitude: 114.363572
})).toBeGreaterThan(100)
})
})