Files
kestrelos/test/nuxt/default-layout.spec.js
Madison Grubb b7046dc0e6 initial commit
2026-02-10 23:32:26 -05:00

45 lines
1.6 KiB
JavaScript

import { describe, it, expect } from 'vitest'
import { mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime'
import DefaultLayout from '../../app/layouts/default.vue'
import NavDrawer from '../../app/components/NavDrawer.vue'
const withAuth = () => {
registerEndpoint('/api/me', () => ({ id: '1', identifier: 'user', role: 'member' }), { method: 'GET' })
}
describe('default layout', () => {
it('renders KestrelOS header', async () => {
withAuth()
const wrapper = await mountSuspended(DefaultLayout)
expect(wrapper.text()).toContain('KestrelOS')
expect(wrapper.text()).toContain('Tactical Operations Center')
})
it('renders drawer toggle with accessible label', async () => {
withAuth()
const wrapper = await mountSuspended(DefaultLayout)
const toggle = wrapper.find('button[aria-label="Toggle navigation"]')
expect(toggle.exists()).toBe(true)
})
it('renders NavDrawer', async () => {
withAuth()
const wrapper = await mountSuspended(DefaultLayout)
expect(wrapper.findComponent(NavDrawer).exists()).toBe(true)
})
it('calls logout and navigates when Logout is clicked', async () => {
withAuth()
registerEndpoint('/api/auth/logout', () => null, { method: 'POST' })
const wrapper = await mountSuspended(DefaultLayout)
await new Promise(r => setTimeout(r, 100))
const logoutBtn = wrapper.findAll('button').find(b => b.text().includes('Logout'))
expect(logoutBtn).toBeDefined()
await logoutBtn.trigger('click')
await new Promise(r => setTimeout(r, 100))
const router = useRouter()
await router.isReady()
expect(router.currentRoute.value.path).toBe('/')
})
})