import { renderToStaticMarkup } from 'react-dom/server' import { describe, expect, it, vi } from 'vitest' import { FindingDetail, ReconciliationFindingsView, ServiceStrip } from './ReconciliationFindings' import type { MonitorOverview } from './monitor' import type { ReconciliationFinding, ReconciliationRun } from './reconciliationApi' const run: ReconciliationRun = { id: 'run-1', kb_id: 'kb-1', state: 'succeeded', trigger: 'manual', started_at: '2026-12-01T02:00:00Z', finished_at: '2026-12-01T02:01:00Z', ledger_count: 12, kb_count: 11, counts: { R1: 1, R2: 0, R3: 2, R4: 0, R5: 0, R6: 0, R7: 0, R8: 0 }, previous_counts: { R1: 0, R2: 0, R3: 2, R4: 0, R5: 0, R6: 0, R7: 0, R8: 0 }, window_overlapped: true, error_code: '', } const finding: ReconciliationFinding = { id: 'f1', run_id: 'run-1', type: 'R1', publication_id: 'pub-1', document_id: 'doc-1', title: '缺失文件.pdf', path: '产品/缺失文件.pdf', source: '技术资料', target_scope: 'internal', ledger_state: 'completed', weknora_parse_status: '', normalized_state: '', ledger_sha256: '', declared_sha256: '', weknora_file_md5: '', evidence_level: 'none', confirmation_state: 'pending', detail: '台账认为应在库,单条读取返回 404', suggested_action: 'requeue_upload', action_state: 'open', weknora_url: '', } const props = { overview: null, runs: { items: [run], total: 1, limit: 20, offset: 0 }, findings: { items: [finding], total: 1, limit: 20, offset: 0 }, filters: { type: '', q: '' }, selectedRunID: 'run-1', selectedKB: 'kb-1', kbOptions: [{ id: 'kb-1', name: '测试知识库' }], loading: false, busy: false, canOperate: true, canRemove: true, error: '', message: '', onTab: vi.fn(), onSelectRun: vi.fn(), onSelectKB: vi.fn(), onFilters: vi.fn(), onPage: vi.fn(), onRefresh: vi.fn(), onCreate: vi.fn(), onAction: vi.fn(), onDetail: vi.fn(), } describe('reconciliation findings', () => { it('shows batch counts, pending confirmation, evidence and actions', () => { const html = renderToStaticMarkup() for (const text of [ '导入对账', '差异清单', '平台侧流水', '立即对账', 'R1 丢失', '待确认', '无', '重排上传', '缺失文件.pdf', ]) expect(html).toContain(text) expect(html).toContain('当前筛选 1 项') expect(html).toContain('保留最近 30 批') }) it('hides trigger and actions from a read-only role', () => { const html = renderToStaticMarkup() expect(html).not.toContain('立即对账') expect(html).not.toContain('>重排上传') expect(html).toContain('只读角色') }) it('renders loading, empty and error states', () => { const loading = renderToStaticMarkup( ) expect(loading).toContain('正在读取差异') expect(loading).toContain('还没有对账批次') const failed = renderToStaticMarkup() expect(failed).toContain('读取对账批次失败') }) it('links a finding to WeKnora when the backend supplies a URL', () => { const html = renderToStaticMarkup( ) expect(html).toContain('href="https://weknora.test/platform/knowledge-bases/kb-1"') expect(html).toContain('在 WeKnora 中打开') }) }) describe('ServiceStrip queue availability', () => { const overview = (queues: MonitorOverview['weknora_queues']) => ({ weknora_queues: queues, health: [] }) as unknown as MonitorOverview it('states an unavailable queue instead of rendering 0 waiting · 0 active', () => { const html = renderToStaticMarkup( ) expect(html).toContain('队列不可用') expect(html).not.toContain('0 等待') }) it('prints queue depth when the queue is available', () => { const html = renderToStaticMarkup( ) expect(html).toContain('2 等待 · 1 运行') }) })