Files
hnh-map/frontend-nuxt/composables/__tests__/useToast.test.ts
Nikolay Tatarinov fd624c2357 Refactor frontend components for improved functionality and accessibility
- 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.
2026-03-04 14:06:27 +03:00

50 lines
1.3 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { ref } from 'vue'
import { useToast } from '../useToast'
const stateByKey: Record<string, ReturnType<typeof ref>> = {}
const useStateMock = vi.fn((key: string, init: () => unknown) => {
if (!stateByKey[key]) {
stateByKey[key] = ref(init())
}
return stateByKey[key]
})
vi.stubGlobal('useState', useStateMock)
describe('useToast', () => {
beforeEach(() => {
stateByKey['hnh-map-toasts'] = ref([])
})
it('exposes toasts and show/dismiss', () => {
const { toasts, success, dismiss } = useToast()
expect(toasts.value).toEqual([])
success('Done!')
expect(toasts.value).toHaveLength(1)
expect(toasts.value[0].type).toBe('success')
expect(toasts.value[0].text).toBe('Done!')
const id = toasts.value[0].id
dismiss(id)
expect(toasts.value).toHaveLength(0)
})
it('error and info set type', () => {
const { toasts, error, info } = useToast()
error('Failed')
expect(toasts.value[0].type).toBe('error')
info('Note')
expect(toasts.value[1].type).toBe('info')
})
it('each toast has unique id', () => {
const { toasts, success } = useToast()
success('A')
success('B')
const ids = toasts.value.map((t) => t.id)
expect(new Set(ids).size).toBe(2)
})
})