Files
kestrelos/test/nuxt/NavDrawer.spec.js
Madison Grubb 4e51ca5509
All checks were successful
ci/woodpecker/pr/pr Pipeline was successful
new nav system
2026-02-14 22:47:05 -05:00

59 lines
2.0 KiB
JavaScript

import { describe, it, expect } from 'vitest'
import { mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime'
import NavDrawer from '../../app/components/NavDrawer.vue'
const withAuth = () => {
registerEndpoint('/api/me', () => ({ id: '1', identifier: 'user', role: 'member', avatar_url: null }), { method: 'GET' })
}
describe('NavDrawer', () => {
it('renders navigation links with correct paths', async () => {
withAuth()
await mountSuspended(NavDrawer, {
props: { modelValue: true },
attachTo: document.body,
})
const links = document.body.querySelectorAll('aside nav a[href]')
const hrefs = [...links].map(a => a.getAttribute('href'))
expect(hrefs).toContain('/')
expect(hrefs).toContain('/account')
expect(hrefs).toContain('/cameras')
expect(hrefs).toContain('/poi')
expect(hrefs).toContain('/members')
expect(hrefs).toContain('/settings')
expect(links.length).toBeGreaterThanOrEqual(6)
})
it('renders Map and Settings labels', async () => {
withAuth()
await mountSuspended(NavDrawer, {
props: { modelValue: true },
attachTo: document.body,
})
expect(document.body.textContent).toContain('Map')
expect(document.body.textContent).toContain('Settings')
})
it('emits update:modelValue when close is triggered', async () => {
withAuth()
const wrapper = await mountSuspended(NavDrawer, {
props: { modelValue: true },
attachTo: document.body,
})
expect(document.body.querySelector('aside button[aria-label="Close navigation"]')).toBeTruthy()
await wrapper.vm.close()
expect(wrapper.emitted('update:modelValue')).toEqual([[false]])
})
it('applies active styling for current route', async () => {
withAuth()
await mountSuspended(NavDrawer, {
props: { modelValue: true },
attachTo: document.body,
})
const mapLink = document.body.querySelector('aside nav a[href="/"]')
expect(mapLink).toBeTruthy()
expect(mapLink.className).toMatch(/kestrel-accent|border-kestrel-accent/)
})
})