Files
knowledge-governance/web/src/monitorTasks.test.ts
T
姚章浩 1b09f7d35b
build / build (push) Successful in 1m17s
feat(monitor): 卡片概况与统一文件处理表
2026-10-27 12:14:19 +08:00

47 lines
2.0 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { fetchMonitorTasks } from './monitorTasks'
import { healthLabel } from './WeKnoraMonitor'
import type { ServiceHealth } from './monitor'
afterEach(() => vi.unstubAllGlobals())
describe('monitor table contract', () => {
it('rejects malformed facets instead of rendering a broken selector', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
data: {
items: [],
total: 0,
limit: 20,
offset: 0,
retryable: 0,
sources: [{ id: 7, name: 'bad' }],
targets: [],
},
}),
})
)
await expect(fetchMonitorTasks({ status: 'active' })).rejects.toThrow('筛选项')
})
it('passes the filter and page to the server without client-side totals', async () => {
const data = { items: [], total: 145, limit: 20, offset: 40, retryable: 12, sources: [], targets: [] }
const request = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ data }) })
vi.stubGlobal('fetch', request)
const result = await fetchMonitorTasks({ status: 'attention', action: 'remove', q: '手册' }, 40)
expect(result.total).toBe(145)
expect(result.retryable).toBe(12)
const url = new URL(request.mock.calls[0][0], 'http://localhost')
expect(url.searchParams.get('offset')).toBe('40')
expect(url.searchParams.get('action')).toBe('remove')
expect(url.searchParams.get('q')).toBe('手册')
})
it('distinguishes unknown, unconfigured, blocked and inapplicable services', () => {
const s = { applicable: true, configured: true, readiness: 'unknown' } as ServiceHealth
expect(healthLabel(s)).toBe('未确认')
expect(healthLabel({ ...s, configured: false })).toBe('未配置')
expect(healthLabel({ ...s, applicable: false })).toBe('不适用')
expect(healthLabel({ ...s, readiness: 'blocked' })).toBe('阻断')
})
})