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

106 lines
3.2 KiB
TypeScript

import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { WeKnoraMonitorView } from './WeKnoraMonitor'
import type { MonitorTaskPage } from './monitorTasks'
const page: MonitorTaskPage = {
items: [
{
id: 'tp-1',
title: '维护手册.pdf',
path: '产品/维护',
source_id: 's1',
source_name: '技术资料',
target_scope: 'internal',
target_kb: 'test-kb',
action: 'update',
stage: 'parsing',
status: 'attention',
detail: 'remote_parse_failed',
updated_at: '2026-10-27T02:00:00Z',
retry_kind: 'upload',
failure_id: '',
retry_count: 2,
version_id: 'v1',
},
{
id: 'tp-2',
title: '过期资料.pdf',
path: '历史',
source_id: 's1',
source_name: '技术资料',
target_scope: 'external',
target_kb: 'test-public',
action: 'remove',
stage: 'finished',
status: 'completed',
detail: '已从测试库移除;来源文件保留',
updated_at: '2026-10-27T02:01:00Z',
retry_kind: '',
failure_id: '',
retry_count: 0,
version_id: 'v2',
},
],
total: 145,
limit: 20,
offset: 0,
sources: [{ id: 's1', name: '技术资料' }],
targets: [],
retryable: 1,
}
const props = {
overview: null,
metrics: null,
page,
loading: false,
error: '',
message: '',
filters: { q: '', source: '', scope: '', target: '', action: '', status: 'active', stage: '', since: '', until: '' },
selected: [],
busy: false,
canOperate: true,
onFilters: vi.fn(),
onPage: vi.fn(),
onSelection: vi.fn(),
onSelectAll: vi.fn(),
onRetry: vi.fn(),
onDetail: vi.fn(),
onRefresh: vi.fn(),
}
describe('unified monitor', () => {
it('shows metric cards before a single server-paginated file table without manual start or lane tabs', () => {
const html = renderToStaticMarkup(<WeKnoraMonitorView {...props} />)
expect(html).toContain('monitor-metric-grid')
expect(html.indexOf('monitor-metric-grid')).toBeLessThan(html.indexOf('<h2>文件处理</h2>'))
expect(html.match(/<table/g)).toHaveLength(1)
for (const s of [
'维护手册.pdf',
'过期资料.pdf',
'处理动作',
'当前阶段',
'处理状态',
'状态说明',
'共 145',
'重试所选',
'服务与依赖',
])
expect(html).toContain(s)
expect(html).not.toContain('开始处理')
expect(html).not.toContain('role="tab"')
expect(html).toContain('value="active" selected=""')
})
it('does not claim healthy zeroes or 100% when metrics are unavailable', () => {
const html = renderToStaticMarkup(<WeKnoraMonitorView {...props} error="无法读取运行指标" />)
expect(html).toContain('无法读取运行指标')
expect(html).not.toContain('100%')
expect(html).toContain('尚未取得服务状态')
})
it('keeps removal semantics and does not offer retry for completed rows', () => {
const html = renderToStaticMarkup(<WeKnoraMonitorView {...props} />)
expect(html).toContain('已从测试库移除;来源文件保留')
expect(html).toContain('aria-label="选择维护手册.pdf"')
expect(html).not.toContain('aria-label="选择过期资料.pdf"')
})
})