This commit is contained in:
@@ -1,46 +1,44 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, it, expect, beforeEach } 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', avatar_url: null }), { method: 'GET' })
|
||||
}
|
||||
const wait = (ms = 100) => new Promise(r => setTimeout(r, ms))
|
||||
|
||||
describe('default layout', () => {
|
||||
it('renders KestrelOS header', async () => {
|
||||
withAuth()
|
||||
const wrapper = await mountSuspended(DefaultLayout)
|
||||
expect(wrapper.text()).toContain('KestrelOS')
|
||||
beforeEach(() => {
|
||||
registerEndpoint('/api/me', () => ({ id: '1', identifier: 'user', role: 'member', avatar_url: null }), { method: 'GET' })
|
||||
})
|
||||
|
||||
it('renders drawer toggle with accessible label on mobile', async () => {
|
||||
withAuth()
|
||||
it.each([
|
||||
['KestrelOS header', 'KestrelOS'],
|
||||
['drawer toggle', 'button[aria-label="Toggle navigation"]'],
|
||||
])('renders %s', async (description, selector) => {
|
||||
const wrapper = await mountSuspended(DefaultLayout)
|
||||
const toggle = wrapper.find('button[aria-label="Toggle navigation"]')
|
||||
expect(toggle.exists()).toBe(true)
|
||||
if (selector.startsWith('button')) {
|
||||
expect(wrapper.find(selector).exists()).toBe(true)
|
||||
}
|
||||
else {
|
||||
expect(wrapper.text()).toContain(selector)
|
||||
}
|
||||
})
|
||||
|
||||
it('renders NavDrawer', async () => {
|
||||
withAuth()
|
||||
const wrapper = await mountSuspended(DefaultLayout)
|
||||
expect(wrapper.findComponent(NavDrawer).exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('renders user menu and sign out navigates home', async () => {
|
||||
withAuth()
|
||||
registerEndpoint('/api/auth/logout', () => null, { method: 'POST' })
|
||||
const wrapper = await mountSuspended(DefaultLayout)
|
||||
await new Promise(r => setTimeout(r, 100))
|
||||
await wait()
|
||||
const menuTrigger = wrapper.find('button[aria-label="User menu"]')
|
||||
expect(menuTrigger.exists()).toBe(true)
|
||||
await menuTrigger.trigger('click')
|
||||
await new Promise(r => setTimeout(r, 50))
|
||||
await wait(50)
|
||||
const signOut = wrapper.find('button[role="menuitem"]')
|
||||
expect(signOut.exists()).toBe(true)
|
||||
expect(signOut.text()).toContain('Sign out')
|
||||
await signOut.trigger('click')
|
||||
await new Promise(r => setTimeout(r, 100))
|
||||
await wait()
|
||||
const router = useRouter()
|
||||
await router.isReady()
|
||||
expect(router.currentRoute.value.path).toBe('/')
|
||||
|
||||
Reference in New Issue
Block a user