mirror of
https://github.com/Smile-QWQ/SubTracker.git
synced 2026-05-23 09:10:42 +08:00
- add statistics page AI summary card with auto-generate and markdown rendering - introduce dashboard summary query/composable and markdown sanitization utility - add marked and dompurify dependencies for summary rendering - raise dashboard summary generate request timeout to 65000ms and cover it with tests
83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const postMock = vi.fn()
|
|
const getMock = vi.fn()
|
|
const requestUseMock = vi.fn()
|
|
const responseUseMock = vi.fn()
|
|
|
|
vi.mock('axios', () => ({
|
|
default: {
|
|
create: vi.fn(() => ({
|
|
post: postMock,
|
|
get: getMock,
|
|
patch: vi.fn(),
|
|
put: vi.fn(),
|
|
delete: vi.fn(),
|
|
interceptors: {
|
|
request: {
|
|
use: requestUseMock
|
|
},
|
|
response: {
|
|
use: responseUseMock
|
|
}
|
|
}
|
|
}))
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/utils/auth-storage', () => ({
|
|
clearAuthSession: vi.fn(),
|
|
getStoredToken: vi.fn(() => null)
|
|
}))
|
|
|
|
vi.mock('@/utils/api-base', () => ({
|
|
getApiBaseUrl: vi.fn(() => '/api')
|
|
}))
|
|
|
|
vi.mock('@/utils/api-error', () => ({
|
|
normalizeApiErrorMessage: vi.fn((error: { message?: string }) => error.message || '请求失败')
|
|
}))
|
|
|
|
describe('api dashboard summary timeout', () => {
|
|
beforeEach(() => {
|
|
vi.resetModules()
|
|
postMock.mockReset()
|
|
getMock.mockReset()
|
|
requestUseMock.mockReset()
|
|
responseUseMock.mockReset()
|
|
})
|
|
|
|
it('uses a dedicated longer timeout when generating dashboard summary', async () => {
|
|
postMock.mockResolvedValueOnce({
|
|
data: {
|
|
data: {
|
|
scope: 'dashboard-overview',
|
|
status: 'success',
|
|
content: '## 总览',
|
|
previewContent: '总览',
|
|
errorMessage: null,
|
|
generatedAt: '2026-05-04T00:00:00.000Z',
|
|
updatedAt: '2026-05-04T00:00:00.000Z',
|
|
sourceDataHash: 'hash',
|
|
fromCache: false,
|
|
isStale: false,
|
|
canGenerate: true,
|
|
needsGeneration: false
|
|
}
|
|
}
|
|
})
|
|
|
|
const { api } = await import('../../../src/composables/api')
|
|
|
|
await api.generateDashboardAiSummary()
|
|
|
|
expect(postMock).toHaveBeenCalledWith(
|
|
'/ai/summary/dashboard/generate',
|
|
undefined,
|
|
expect.objectContaining({
|
|
timeout: 65000
|
|
})
|
|
)
|
|
})
|
|
})
|