// @ts-expect-error The test runner provides Node; the browser bundle intentionally omits @types/node. import { readFileSync } from 'node:fs' import { renderToStaticMarkup } from 'react-dom/server' import { describe, expect, it, vi } from 'vitest' import { QAOperationsTabs, QAOperationsView } from './QAOperations' import type { QARecord, QARecordPage } from './qaOps' import { restoreWorkspace } from './workspace' const item: QARecord = { id: 'fixture', status: 'succeeded', question: '', answer: '当前暂无已发布的权威知识。', asked_at: '2026-10-14T03:00:00Z', time_source: 'request_message.created_at', asker: '测试人员', trigger_person: '测试昵称', department: '', region: '', references: [{ title: '测试引用' }], media: [], feedback: { asker_value: 'down', up: 0, down: 1 }, source_coverage: { verdict: 'covered', reason_code: 'covered_has_references', evaluator_version: 'v5' }, coverage: { verdict: 'uncovered', state: 'checked', rule_version: 'governance-answer-substring-v1', matched_text: '暂无已发布', }, is_correct: false, } const page: QARecordPage = { items: [item], columns: ['answer', 'coverage', 'is_correct', 'asked_at', 'asker', 'question', 'feedback'], total: 1, has_more: false, next_cursor: '', as_of: '2026-10-14T04:00:00Z', } const props = { page, status: null, loading: false, error: null, detail: null, detailLoading: false, detailError: null, onSelect: vi.fn(), onCloseDetail: vi.fn(), onLoadMore: vi.fn(), onRetry: vi.fn(), } describe('QA operations workbench', () => { it('edits five fields directly in the first row without a separate review or feedback form', () => { const html = renderToStaticMarkup( ) const drawer = html.slice(html.indexOf(' { const withTasks = { ...item, background_tasks: [ { id: 'w', record_id: item.id, kind: 'evaluation' as const, state: 'running' as const, stage: 'request', attempt: 1, error_code: '', skip_reason: '', started_at: '2026-10-19T00:00:00Z', updated_at: '2026-10-19T00:00:01Z', }, ], } const detail = { ...item, record_origin: 'dobotai_2_0' as const, coverage: { state: 'checked' as const, verdict: 'covered' as const, rule_version: 'master-answer-substring-v2' }, } const html = renderToStaticMarkup( ) expect(html).toContain('字段分析:执行中') expect(html).toContain('已覆盖:成功读取且非空答案未包含') expect(html).toContain('字段结论与依据') }) it('hides only the two requested advisory warnings, not real errors', () => { const html = renderToStaticMarkup( ) expect(html).not.toContain('数据库仍允许临时对象') expect(html).not.toContain('数据库连接未启用 TLS') expect(html).toContain('数据源有待审核的安全告警') expect(html).toContain('fixture real read failure') }) it('removes workflow personnel from details while preserving the record data', () => { const detail = { ...item, trigger_person: JSON.stringify({ name: '示例姓名', unionId: 'fixture-union' }) } const html = renderToStaticMarkup() const drawer = html.slice(html.indexOf(' { const html = renderToStaticMarkup() expect(html).toContain('data-qa-row="fixture"') expect(html).toContain('双击行查看详情') expect(html).toContain('qa-field-tag') }) it('uses the four requested destinations in their fixed order', () => { const html = renderToStaticMarkup() const labels = ['问题流水', '问题统计看板', '区域统计', '周报生成'] for (const label of labels) expect(html).toContain(label) for (let i = 1; i < labels.length; i++) expect(html.indexOf(labels[i - 1])).toBeLessThan(html.indexOf(labels[i])) expect(html).not.toContain('部门/区域保留源快照') }) it('removes explanatory banners without hiding errors or any required column', () => { const html = renderToStaticMarkup() expect(html).not.toContain('本次读取') expect(html).not.toContain('固定显示完整字段') expect(html).not.toContain('DobotAI 2.0 / 钉钉') }) it('shows all required columns even when empty and keeps false/downvotes visible', () => { const html = renderToStaticMarkup() expect(html).toContain('原始问题') expect(html.indexOf('AI答案')).toBeLessThan(html.indexOf('是否覆盖')) expect(html.indexOf('是否正确')).toBeLessThan(html.indexOf('提问时间')) expect(html).toContain('否(点踩)') expect(html).toContain('是否正确') expect(html).toContain('部门') expect([...html.matchAll(/(.*?)<\/th>/g)].slice(0, 14).map((match) => match[1])).toEqual([ '中文问题', 'AI答案', '是否覆盖', '是否正确', '产品分类', '问题类型', '根因分析', '提问时间', '提问人', '原始问题', '语言', '流程触发人员信息', '部门', '区域', ]) expect(html).toContain('产品分类') expect(html).not.toContain('') }) it('never shows a load-more control for the all-records table', () => { const html = renderToStaticMarkup( ) expect(html).not.toContain('加载更多') expect(html).not.toContain('空列按整个筛选结果隐藏') }) it('distinguishes an unavailable source from a successful empty query', () => { const html = renderToStaticMarkup() expect(html).toContain('role="alert"') expect(html).toContain('只读源不可用') expect(html).not.toContain('没有符合条件的问答') }) it('shows complete source and governance evidence separately in the detail drawer', () => { const html = renderToStaticMarkup() expect(html).toContain('role="dialog"') expect(html).toContain('暂无已发布') expect(html).toContain('源端覆盖(仅对照)') expect(html).toContain('covered_has_references') expect(html).toContain('测试引用') }) it('restores the existing singleton workspace tab without creating another application', () => { const restored = restoreWorkspace(JSON.stringify({ openTabs: ['dashboard', 'qaops'], activeTab: 'qaops' })) expect(restored.openTabs).toEqual(['dashboard', 'qaops']) expect(restored.activeTab).toBe('qaops') }) }) it('opens a modeless right drawer with fixed leading quality fields and no redundant organization/personnel details', () => { const html = renderToStaticMarkup() const drawer = html.slice(html.indexOf('区域', '当前组织关联', '当前通讯录部门/区域', '组织版本', '源端组织快照', '记录来源', '问答状态', '流程触发人员信息', '原始人员信息', ]) expect(drawer).not.toContain(label) }) it('names the ledger explicitly as 问题流水表', () => { const html = renderToStaticMarkup() expect(html).toContain('>问题流水表') }) it('uses matching query/sync action sizing and keeps synchronization status outside the button baseline', () => { const css = readFileSync(new URL('./qaOps.css', import.meta.url), 'utf8') expect(css).toContain('.qa-ops-query .qa-query-action') expect(css).toMatch(/\.qa-ops-query \.qa-query-action\s*\{[^}]*width:\s*96px/) expect(css).toMatch(/\.qa-ops-query \.qa-mirror-sync-line\s*\{[^}]*margin-bottom:\s*0/) })