initial commit
This commit is contained in:
44
test/nuxt/default-layout.spec.js
Normal file
44
test/nuxt/default-layout.spec.js
Normal file
@@ -0,0 +1,44 @@
|
||||
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('/')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user