claude rework
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import AppNav from '../AppNav.vue'
|
||||
|
||||
describe('AppNav', () => {
|
||||
let router
|
||||
|
||||
beforeEach(async () => {
|
||||
localStorage.setItem('user-token', 'abc123')
|
||||
localStorage.setItem('user-id', '7')
|
||||
|
||||
router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{ path: '/login', name: 'login', component: { template: '<div />' } },
|
||||
{ path: '/feeds', name: 'feeds', component: { template: '<div />' } },
|
||||
],
|
||||
})
|
||||
router.push('/feeds')
|
||||
await router.isReady()
|
||||
})
|
||||
|
||||
it('clears stored credentials and redirects to login on logout', async () => {
|
||||
const wrapper = mount(AppNav, { global: { plugins: [router] } })
|
||||
|
||||
await wrapper.find('.app-nav__logout').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(localStorage.getItem('user-token')).toBeNull()
|
||||
expect(localStorage.getItem('user-id')).toBeNull()
|
||||
expect(router.currentRoute.value.name).toBe('login')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user