import { createPinia, setActivePinia } from 'pinia' import { beforeEach, describe, expect, it } from 'vitest' import { DEFAULT_GUANGMING_VIEWPORT, useLocationStore, useMapStore } from '@/stores' describe('map session store', () => { beforeEach(() => { setActivePinia(createPinia()) }) it('keeps category, selected POI and viewport while navigating back', () => { const store = useMapStore() store.setCategory('urban_park') store.selectPoi('poi_hongqiao_park') store.updateViewport({ longitude: 113.94, latitude: 22.76, scale: 13 }) expect(store.categoryCode).toBe('urban_park') expect(store.selectedPoiId).toBe('poi_hongqiao_park') expect(store.viewport).toEqual({ longitude: 113.94, latitude: 22.76, scale: 13 }) }) it('shows and clears the planned-route overlay explicitly', () => { const store = useMapStore() expect(store.plannedRouteVisible).toBe(false) store.showPlannedRoute() expect(store.plannedRouteVisible).toBe(true) store.hidePlannedRoute() expect(store.plannedRouteVisible).toBe(false) }) it('ignores invalid viewport updates', () => { const store = useMapStore() store.updateViewport({ longitude: Number.NaN, latitude: 22.76, scale: 13 }) expect(store.viewport).toEqual(DEFAULT_GUANGMING_VIEWPORT) }) it('keeps a validated user location in memory independently from the map viewport', () => { const mapStore = useMapStore() const locationStore = useLocationStore() expect(locationStore.updateLocation(113.94, 22.76, 18)).toBe(true) expect(locationStore.snapshot).toMatchObject({ longitude: 113.94, latitude: 22.76, accuracy: 18, coordinateSystem: 'GCJ02', }) expect(locationStore.status).toBe('ready') expect(mapStore.viewport).toEqual(DEFAULT_GUANGMING_VIEWPORT) }) it('rejects malformed user coordinates', () => { const store = useLocationStore() expect(store.updateLocation(181, 22.76, 10)).toBe(false) expect(store.snapshot).toBeNull() }) })