- Updated frontend-nuxt.mdc to specify usage of composables for API calls. - Added new AuthCard and ConfirmModal components for improved UI consistency. - Introduced UserAvatar component for user profile display, replacing previous Gravatar implementation. - Implemented useFormSubmit composable for handling form submissions with loading and error states. - Enhanced vitest.config.ts to include coverage reporting for composables and components. - Removed deprecated useAdminApi and useAuth composables to streamline API interactions. - Updated login and setup pages to utilize new components and composables for better user experience.
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { ref } from 'vue'
|
|
|
|
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)
|
|
|
|
import { useToast } from '../useToast'
|
|
|
|
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)
|
|
})
|
|
})
|