fix: 修复前端登录体验和API调用问题
- 修复路由守卫:未登录时直接跳转,不显示提示信息 - 修复API拦截器:401错误直接跳转,无需确认 - 移除不必要的ElMessageBox确认框 - 优化Token过期处理逻辑 - 修复文件管理API引入路径和URL前缀 - 修复调拨/回收管理API端点不匹配问题 - 修复通知管理API方法不匹配问题 - 统一系统配置API路径为单数形式 影响文件: - src/router/index.ts - src/api/request.ts - src/api/file.ts - src/api/index.ts 测试状态: - 前端构建通过 - 所有API路径已验证 - 登录流程测试通过 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
141
tests/unit/composables/useECharts.test.ts
Normal file
141
tests/unit/composables/useECharts.test.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* useECharts Composable 测试
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
import { useECharts } from '@/composables/useECharts'
|
||||
|
||||
// Mock echarts
|
||||
vi.mock('echarts', () => ({
|
||||
default: {
|
||||
init: vi.fn(() => ({
|
||||
setOption: vi.fn(),
|
||||
resize: vi.fn(),
|
||||
dispose: vi.fn(),
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
showLoading: vi.fn(),
|
||||
hideLoading: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
getDataURL: vi.fn(),
|
||||
})),
|
||||
},
|
||||
}))
|
||||
|
||||
describe('useECharts', () => {
|
||||
let chartRef: Ref<HTMLElement | null>
|
||||
|
||||
beforeEach(() => {
|
||||
// 创建 mock DOM 元素
|
||||
const mockElement = document.createElement('div')
|
||||
chartRef = ref(mockElement)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('initializes chart correctly', () => {
|
||||
const { chart, isReady } = useECharts(chartRef)
|
||||
|
||||
// 检查图表实例是否创建
|
||||
expect(chart.value).toBeTruthy()
|
||||
})
|
||||
|
||||
it('sets chart option', () => {
|
||||
const { setOption } = useECharts(chartRef)
|
||||
|
||||
const option = {
|
||||
series: [{
|
||||
type: 'pie',
|
||||
data: [{ name: '测试', value: 100 }],
|
||||
}],
|
||||
}
|
||||
|
||||
setOption(option)
|
||||
|
||||
// 验证 setOption 被调用
|
||||
expect(chart.value?.setOption).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows loading', () => {
|
||||
const { showLoading, loading } = useECharts(chartRef)
|
||||
|
||||
showLoading({ text: '加载中...' })
|
||||
|
||||
expect(loading.value).toBe(true)
|
||||
expect(chart.value?.showLoading).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('hides loading', () => {
|
||||
const { hideLoading, loading } = useECharts(chartRef)
|
||||
|
||||
hideLoading()
|
||||
|
||||
expect(loading.value).toBe(false)
|
||||
expect(chart.value?.hideLoading).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('resizes chart', () => {
|
||||
const { resize } = useECharts(chartRef)
|
||||
|
||||
resize()
|
||||
|
||||
expect(chart.value?.resize).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('disposes chart', () => {
|
||||
const { dispose, chart } = useECharts(chartRef)
|
||||
|
||||
dispose()
|
||||
|
||||
expect(chart.value?.dispose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('clears chart', () => {
|
||||
const { clear } = useECharts(chartRef)
|
||||
|
||||
clear()
|
||||
|
||||
expect(chart.value?.clear).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('binds event', () => {
|
||||
const { on } = useECharts(chartRef)
|
||||
|
||||
const handler = vi.fn()
|
||||
on('click', handler)
|
||||
|
||||
expect(chart.value?.on).toHaveBeenCalledWith('click', handler)
|
||||
})
|
||||
|
||||
it('unbinds event', () => {
|
||||
const { off } = useECharts(chartRef)
|
||||
|
||||
const handler = vi.fn()
|
||||
off('click', handler)
|
||||
|
||||
expect(chart.value?.off).toHaveBeenCalledWith('click', handler)
|
||||
})
|
||||
|
||||
it('gets data URL', () => {
|
||||
const { getDataURL } = useECharts(chartRef)
|
||||
|
||||
getDataURL({ type: 'png', pixelRatio: 2 })
|
||||
|
||||
expect(chart.value?.getDataURL).toHaveBeenCalledWith({
|
||||
type: 'png',
|
||||
pixelRatio: 2,
|
||||
backgroundColor: '#fff',
|
||||
})
|
||||
})
|
||||
|
||||
it('returns chart instance', () => {
|
||||
const { getInstance } = useECharts(chartRef)
|
||||
|
||||
const instance = getInstance()
|
||||
|
||||
expect(instance).toBeTruthy()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user