- Consolidated global error handling in app.vue to redirect users to the login page on API authentication failure. - Enhanced MapView component by reintroducing event listeners for selected map and marker updates, improving interactivity. - Updated PasswordInput and various modal components to ensure proper input handling and accessibility compliance. - Refactored MapControls and MapControlsContent to streamline prop management and enhance user experience. - Improved error handling in local storage operations within useMapBookmarks and useRecentLocations composables. - Standardized input elements across forms for consistency in user interaction.
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
import { useAppPaths } from '../useAppPaths'
|
|
|
|
const useRuntimeConfigMock = vi.fn()
|
|
vi.stubGlobal('useRuntimeConfig', useRuntimeConfigMock)
|
|
|
|
describe('useAppPaths with default base /', () => {
|
|
beforeEach(() => {
|
|
useRuntimeConfigMock.mockReturnValue({ app: { baseURL: '/' } })
|
|
})
|
|
|
|
it('returns base as empty string for "/"', () => {
|
|
const { base } = useAppPaths()
|
|
expect(base).toBe('')
|
|
})
|
|
|
|
it('pathWithoutBase returns path unchanged', () => {
|
|
const { pathWithoutBase } = useAppPaths()
|
|
expect(pathWithoutBase('/login')).toBe('/login')
|
|
expect(pathWithoutBase('/admin/users')).toBe('/admin/users')
|
|
expect(pathWithoutBase('/')).toBe('/')
|
|
})
|
|
|
|
it('resolvePath returns path as-is', () => {
|
|
const { resolvePath } = useAppPaths()
|
|
expect(resolvePath('/login')).toBe('/login')
|
|
expect(resolvePath('admin')).toBe('/admin')
|
|
})
|
|
|
|
it('isLoginPath detects login', () => {
|
|
const { isLoginPath } = useAppPaths()
|
|
expect(isLoginPath('/login')).toBe(true)
|
|
expect(isLoginPath('/admin/login')).toBe(true)
|
|
expect(isLoginPath('/admin')).toBe(false)
|
|
expect(isLoginPath('/')).toBe(false)
|
|
})
|
|
|
|
it('isSetupPath detects setup', () => {
|
|
const { isSetupPath } = useAppPaths()
|
|
expect(isSetupPath('/setup')).toBe(true)
|
|
expect(isSetupPath('/other/setup')).toBe(true)
|
|
expect(isSetupPath('/')).toBe(false)
|
|
expect(isSetupPath('/login')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('useAppPaths with custom base /map', () => {
|
|
beforeEach(() => {
|
|
useRuntimeConfigMock.mockReturnValue({ app: { baseURL: '/map/' } })
|
|
})
|
|
|
|
it('strips base from path', () => {
|
|
const { base, pathWithoutBase } = useAppPaths()
|
|
expect(base).toBe('/map')
|
|
expect(pathWithoutBase('/map/login')).toBe('/login')
|
|
expect(pathWithoutBase('/map/admin/users')).toBe('/admin/users')
|
|
expect(pathWithoutBase('/map/')).toBe('/')
|
|
expect(pathWithoutBase('/map')).toBe('/')
|
|
})
|
|
|
|
it('resolvePath prepends base', () => {
|
|
const { resolvePath } = useAppPaths()
|
|
expect(resolvePath('/login')).toBe('/map/login')
|
|
expect(resolvePath('admin')).toBe('/map/admin')
|
|
})
|
|
|
|
it('isLoginPath with base', () => {
|
|
const { isLoginPath } = useAppPaths()
|
|
expect(isLoginPath('/map/login')).toBe(true)
|
|
expect(isLoginPath('/login')).toBe(true)
|
|
expect(isLoginPath('/map/admin')).toBe(false)
|
|
})
|
|
|
|
it('isSetupPath with base', () => {
|
|
const { isSetupPath } = useAppPaths()
|
|
expect(isSetupPath('/map/setup')).toBe(true)
|
|
expect(isSetupPath('/setup')).toBe(true)
|
|
expect(isSetupPath('/map/login')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('useAppPaths with no baseURL', () => {
|
|
beforeEach(() => {
|
|
useRuntimeConfigMock.mockReturnValue({ app: {} })
|
|
})
|
|
|
|
it('defaults to /', () => {
|
|
const { baseURL, base } = useAppPaths()
|
|
expect(baseURL).toBe('/')
|
|
expect(base).toBe('')
|
|
})
|
|
})
|