Files
knowledge-governance/web/src/WeKnoraMonitor.detail.test.tsx
T
Zhero & Rin 095aa3ed68
build / build (push) Failing after 26s
fix(reconciliation): 平台抽屉补 WeKnora 跳转链接
- 为什么:白盒复检 P1——平台侧文件详情抽屉 503 只有文案,需求 §8 要求跳转链接;/monitor/tasks 行没有 URL。
- 做什么:抽出 KnowledgeBaseConsoleURL,finding 与 /monitor/tasks 共用同一拼接;handler 用当前生效测试端点填 weknora_url,前端抽屉透传给 WeKnoraProgress;openapi/需求 §7 同步。
- 补证据:stage=weknora 真库合并用例;对账扫描改为真实 HTTP 桩断言零写;progress 投影断言上游密钥字段不外泄。
- 验证:make verify 17 项 success;go test ./... exit 0;web 648 测试 + build;monitor_tasks 真库集成用例 PASS。
2026-12-01 15:00:25 +08:00

69 lines
2.2 KiB
TypeScript

// @vitest-environment jsdom
import { act } from 'react'
import { createRoot } from 'react-dom/client'
import type { Root } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { TaskDetail } from './WeKnoraMonitor'
import type { MonitorTask } from './monitorTasks'
const item: MonitorTask = {
id: 'tp-1',
title: '维护手册.pdf',
path: '产品/维护',
node_id: 'node-1',
parent_node_id: 'folder-1',
source_id: 's1',
source_name: '技术资料',
target_scope: 'internal',
target_kb: 'kb-1',
document_id: 'doc-1',
weknora_url: 'https://weknora.test/platform/knowledge-bases/kb-1',
action: 'update',
stage: 'parsing',
status: 'running',
detail: '正在解析处理',
updated_at: '2026-12-01T02:00:00Z',
retry_kind: '',
failure_id: '',
retry_count: 0,
version_id: 'v1',
}
let container: HTMLDivElement
let root: Root
beforeEach(() => {
// React's test-only global; the test environment exposes it without a type.
const reactTestGlobal: { IS_REACT_ACT_ENVIRONMENT: boolean } = globalThis as unknown as {
IS_REACT_ACT_ENVIRONMENT: boolean
}
reactTestGlobal.IS_REACT_ACT_ENVIRONMENT = true
// jsdom does not implement the dialog methods the drawer calls on mount.
HTMLDialogElement.prototype.showModal = function showModal(this: HTMLDialogElement) {
this.open = true
}
container = document.createElement('div')
document.body.appendChild(container)
root = createRoot(container)
})
afterEach(() => {
act(() => root.unmount())
container.remove()
vi.unstubAllGlobals()
})
describe('platform task drawer', () => {
it('offers the WeKnora jump link when progress answers 503', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue(
new Response(JSON.stringify({ error: 'runtime_read_unavailable', code: 'runtime_read_unavailable' }), {
status: 503,
})
)
)
await act(async () => root.render(<TaskDetail item={item} onClose={vi.fn()} />))
await act(async () => await Promise.resolve())
expect(container.textContent).toContain('未配置 WeKnora 只读 Key')
expect(container.querySelector('a[href="https://weknora.test/platform/knowledge-bases/kb-1"]')).not.toBeNull()
})
})