- Introduced .editorconfig for consistent coding styles across the project. - Added .golangci.yml for Go linting configuration. - Updated AGENTS.md to clarify project structure and components. - Enhanced CONTRIBUTING.md with Makefile usage for common tasks. - Updated Dockerfiles to use Go 1.24 and improved build instructions. - Refined README.md and deployment documentation for clarity. - Added testing documentation in testing.md for backend and frontend tests. - Introduced Makefile for streamlined development commands and tasks.
138 lines
5.1 KiB
TypeScript
138 lines
5.1 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { ref, reactive } from 'vue'
|
|
|
|
vi.stubGlobal('ref', ref)
|
|
vi.stubGlobal('reactive', reactive)
|
|
|
|
import { useMapLogic } from '../useMapLogic'
|
|
|
|
describe('useMapLogic', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('initializes with default state', () => {
|
|
const { state } = useMapLogic()
|
|
expect(state.showGridCoordinates.value).toBe(false)
|
|
expect(state.hideMarkers.value).toBe(false)
|
|
expect(state.panelCollapsed.value).toBe(false)
|
|
expect(state.trackingCharacterId.value).toBe(-1)
|
|
expect(state.selectedMapId.value).toBeNull()
|
|
expect(state.overlayMapId.value).toBe(-1)
|
|
expect(state.selectedMarkerId.value).toBeNull()
|
|
expect(state.selectedPlayerId.value).toBeNull()
|
|
expect(state.displayCoords.value).toBeNull()
|
|
expect(state.mapid.value).toBe(0)
|
|
})
|
|
|
|
it('zoomIn calls map.zoomIn', () => {
|
|
const { zoomIn } = useMapLogic()
|
|
const mockMap = { zoomIn: vi.fn() }
|
|
zoomIn(mockMap as unknown as import('leaflet').Map)
|
|
expect(mockMap.zoomIn).toHaveBeenCalled()
|
|
})
|
|
|
|
it('zoomIn handles null map', () => {
|
|
const { zoomIn } = useMapLogic()
|
|
expect(() => zoomIn(null)).not.toThrow()
|
|
})
|
|
|
|
it('zoomOutControl calls map.zoomOut', () => {
|
|
const { zoomOutControl } = useMapLogic()
|
|
const mockMap = { zoomOut: vi.fn() }
|
|
zoomOutControl(mockMap as unknown as import('leaflet').Map)
|
|
expect(mockMap.zoomOut).toHaveBeenCalled()
|
|
})
|
|
|
|
it('resetView resets tracking and sets view', () => {
|
|
const { state, resetView } = useMapLogic()
|
|
state.trackingCharacterId.value = 42
|
|
const mockMap = { setView: vi.fn() }
|
|
resetView(mockMap as unknown as import('leaflet').Map)
|
|
expect(state.trackingCharacterId.value).toBe(-1)
|
|
expect(mockMap.setView).toHaveBeenCalledWith([0, 0], 1, { animate: false })
|
|
})
|
|
|
|
it('updateDisplayCoords sets coords from map center', () => {
|
|
const { state, updateDisplayCoords } = useMapLogic()
|
|
const mockMap = {
|
|
project: vi.fn(() => ({ x: 550, y: 350 })),
|
|
getCenter: vi.fn(() => ({ lat: 0, lng: 0 })),
|
|
getZoom: vi.fn(() => 3),
|
|
}
|
|
updateDisplayCoords(mockMap as unknown as import('leaflet').Map)
|
|
expect(state.displayCoords.value).toEqual({ x: 5, y: 3, z: 3 })
|
|
})
|
|
|
|
it('updateDisplayCoords handles null map', () => {
|
|
const { state, updateDisplayCoords } = useMapLogic()
|
|
updateDisplayCoords(null)
|
|
expect(state.displayCoords.value).toBeNull()
|
|
})
|
|
|
|
it('toLatLng calls map.unproject', () => {
|
|
const { toLatLng } = useMapLogic()
|
|
const mockMap = { unproject: vi.fn(() => ({ lat: 1, lng: 2 })) }
|
|
const result = toLatLng(mockMap as unknown as import('leaflet').Map, 100, 200)
|
|
expect(mockMap.unproject).toHaveBeenCalledWith([100, 200], 6)
|
|
expect(result).toEqual({ lat: 1, lng: 2 })
|
|
})
|
|
|
|
it('toLatLng returns null for null map', () => {
|
|
const { toLatLng } = useMapLogic()
|
|
expect(toLatLng(null, 0, 0)).toBeNull()
|
|
})
|
|
|
|
it('closeContextMenus hides both menus', () => {
|
|
const { contextMenu, openTileContextMenu, openMarkerContextMenu, closeContextMenus } = useMapLogic()
|
|
openTileContextMenu(10, 20, { x: 1, y: 2 })
|
|
openMarkerContextMenu(30, 40, 5, 'Tower')
|
|
closeContextMenus()
|
|
expect(contextMenu.tile.show).toBe(false)
|
|
expect(contextMenu.marker.show).toBe(false)
|
|
})
|
|
|
|
it('openTileContextMenu sets tile context menu state', () => {
|
|
const { contextMenu, openTileContextMenu } = useMapLogic()
|
|
openTileContextMenu(100, 200, { x: 5, y: 10 })
|
|
expect(contextMenu.tile.show).toBe(true)
|
|
expect(contextMenu.tile.x).toBe(100)
|
|
expect(contextMenu.tile.y).toBe(200)
|
|
expect(contextMenu.tile.data).toEqual({ coords: { x: 5, y: 10 } })
|
|
})
|
|
|
|
it('openMarkerContextMenu sets marker context menu state', () => {
|
|
const { contextMenu, openMarkerContextMenu } = useMapLogic()
|
|
openMarkerContextMenu(50, 60, 42, 'Castle')
|
|
expect(contextMenu.marker.show).toBe(true)
|
|
expect(contextMenu.marker.x).toBe(50)
|
|
expect(contextMenu.marker.y).toBe(60)
|
|
expect(contextMenu.marker.data).toEqual({ id: 42, name: 'Castle' })
|
|
})
|
|
|
|
it('openTileContextMenu closes other menus first', () => {
|
|
const { contextMenu, openMarkerContextMenu, openTileContextMenu } = useMapLogic()
|
|
openMarkerContextMenu(10, 20, 1, 'A')
|
|
expect(contextMenu.marker.show).toBe(true)
|
|
|
|
openTileContextMenu(30, 40, { x: 0, y: 0 })
|
|
expect(contextMenu.marker.show).toBe(false)
|
|
expect(contextMenu.tile.show).toBe(true)
|
|
})
|
|
|
|
it('openCoordSet sets modal state', () => {
|
|
const { coordSetFrom, coordSet, coordSetModalOpen, openCoordSet } = useMapLogic()
|
|
openCoordSet({ x: 3, y: 7 })
|
|
expect(coordSetFrom.value).toEqual({ x: 3, y: 7 })
|
|
expect(coordSet.value).toEqual({ x: 3, y: 7 })
|
|
expect(coordSetModalOpen.value).toBe(true)
|
|
})
|
|
|
|
it('closeCoordSetModal closes modal', () => {
|
|
const { coordSetModalOpen, openCoordSet, closeCoordSetModal } = useMapLogic()
|
|
openCoordSet({ x: 0, y: 0 })
|
|
closeCoordSetModal()
|
|
expect(coordSetModalOpen.value).toBe(false)
|
|
})
|
|
})
|