feat: complete admin API integration

This commit is contained in:
2026-07-31 13:43:16 +08:00
parent bb09c7d6a0
commit d0f94d95d7
24 changed files with 1834 additions and 113 deletions
+20 -2
View File
@@ -4,6 +4,7 @@ import { createMemoryHistory, createRouter } from 'vue-router'
import { nextTick } from 'vue'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ApiResponseError } from '@/api/http'
import { useAccessPreviewStore } from '@/stores/accessPreview'
import { useAdminDataStore } from '@/stores/adminData'
import { useAuthStore } from '@/stores/auth'
@@ -14,7 +15,7 @@ vi.mock('element-plus', async (importOriginal) => {
const actual = await importOriginal<typeof import('element-plus')>()
return {
...actual,
ElMessage: { success: vi.fn(), error: vi.fn() },
ElMessage: { success: vi.fn(), warning: vi.fn(), error: vi.fn() },
ElMessageBox: { confirm: vi.fn() },
}
})
@@ -86,6 +87,7 @@ describe('AppLayout role preview coordination', () => {
vi.stubGlobal('localStorage', createMemoryStorage())
vi.mocked(ElMessageBox.confirm).mockReset()
vi.mocked(ElMessage.success).mockReset()
vi.mocked(ElMessage.warning).mockReset()
vi.mocked(ElMessage.error).mockReset()
document.body.innerHTML = ''
})
@@ -294,7 +296,7 @@ describe('AppLayout role preview coordination', () => {
const logout = auth.logout
vi.spyOn(access, 'reset').mockImplementation(() => { calls.push('access'); resetAccess() })
vi.spyOn(unsaved, 'clear').mockImplementation(() => { calls.push('unsaved'); clearUnsaved() })
vi.spyOn(auth, 'logout').mockImplementation(() => { calls.push('auth'); logout() })
vi.spyOn(auth, 'logout').mockImplementation(() => { calls.push('auth'); return logout() })
const replace = vi.spyOn(router, 'replace')
await wrapper.get('[aria-label="退出登录"]').trigger('click')
@@ -320,4 +322,20 @@ describe('AppLayout role preview coordination', () => {
expect(router.currentRoute.value.path).toBe('/')
expect(router.replace).toHaveBeenCalledTimes(1)
})
it('keeps the local logout and reports server revocation failure with a tracking id', async () => {
vi.mocked(ElMessageBox.confirm).mockResolvedValueOnce({} as never)
const { wrapper, router, auth } = await mountLayout('/')
vi.spyOn(auth, 'logout').mockImplementation(async () => {
auth.token = ''
auth.refreshToken = ''
throw new ApiResponseError('服务不可用', 'S0503', 503, undefined, 'request-logout')
})
await wrapper.get('[aria-label="退出登录"]').trigger('click')
await flushPromises()
expect(router.currentRoute.value.path).toBe('/login')
expect(ElMessage.warning).toHaveBeenCalledWith('本地已退出,但服务器会话撤销失败(追踪标识:request-logout)')
})
})