完善 ChatView 页面功能与用户交互逻辑
- 增加请求状态管理,区分 RUNNING 和 DONE 状态 - 优化消息列表归一化处理逻辑,提高代码可读性 - 添加按键事件支持 (Ctrl+Enter) 以改善发送消息体验 - 更新输入框与发送按钮的禁用逻辑,明确状态反馈 - 提升 SSE 连接恢复的安全性,增加鉴权检查 - 优化界面显示,新增快捷键提示及样式改进 - 移除 package-lock.json 中多余的 peer 标记
This commit is contained in:
62
tests/login.spec.js
Normal file
62
tests/login.spec.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { createRouter, createMemoryHistory } from 'vue-router'
|
||||
import ElementPlus from 'element-plus'
|
||||
import LoginView from '../src/views/LoginView.vue'
|
||||
import axios from 'axios'
|
||||
|
||||
vi.mock('axios', () => ({
|
||||
default: {
|
||||
post: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
const mockedAxios = axios
|
||||
|
||||
const makeRouter = () =>
|
||||
createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: '/', name: 'login', component: LoginView },
|
||||
{ path: '/welcome', name: 'welcome', component: LoginView },
|
||||
],
|
||||
})
|
||||
|
||||
describe('LoginView enter submit', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('submits login on form submit', async () => {
|
||||
mockedAxios.post.mockResolvedValue({
|
||||
data: { token: 'token-123', user: { id: 'u1' } },
|
||||
})
|
||||
|
||||
const router = makeRouter()
|
||||
router.push('/')
|
||||
await router.isReady()
|
||||
|
||||
const wrapper = mount(LoginView, {
|
||||
global: {
|
||||
plugins: [router, ElementPlus],
|
||||
},
|
||||
})
|
||||
|
||||
const emailInput = wrapper.find('input[autocomplete="email"]')
|
||||
const passwordInput = wrapper.find(
|
||||
'input[autocomplete="current-password"]'
|
||||
)
|
||||
await emailInput.setValue('user@example.com')
|
||||
await passwordInput.setValue('password')
|
||||
|
||||
await wrapper.find('form').trigger('submit')
|
||||
await flushPromises()
|
||||
|
||||
expect(mockedAxios.post).toHaveBeenCalledWith(
|
||||
'http://localhost:8000/api/login',
|
||||
{ email: 'user@example.com', password: 'password' }
|
||||
)
|
||||
expect(router.currentRoute.value.name).toBe('welcome')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user