import { describe, it, expect } from 'vitest' import { renderToStaticMarkup } from 'react-dom/server' import { createElement } from 'react' import { QAAnswerMarkdown } from './QAAnswerMarkdown' import { buildQAWeeklyDraft, weeklyQualitySourceLabel } from './qaWeekly' it('identifies the calendar-month prefill policy rather than labelling it unknown or weekly', () => { expect(weeklyQualitySourceLabel('master_live_calendar_month_v1')).toBe('自然月累计质量指标(跨月周按上月)') expect(weeklyQualitySourceLabel('reported-history')).toBe('历史上报指标') }) import type { QARecordPage, QAQuery } from './qaOps' import type { QualitySummary } from './qaQuality' const query: QAQuery = { start: '2026-10-11T16:00:00Z', end: '2026-10-18T10:00:00Z', keyword: '', cursor: '' } const page = { items: [ { id: 'fixture', status: 'succeeded', time_source: 'request_message.created_at', asker: 'fixture person', trigger_person: '', department: '', region: '', references: [], media: [], source_coverage: { verdict: '', reason_code: '', evaluator_version: '' }, question: '=HYPERLINK("https://example.invalid")', answer: '暂无已发布', asked_at: '2026-10-14T00:00:00Z', coverage: { verdict: 'uncovered', state: 'checked', rule_version: 'governance-answer-substring-v1', matched_text: '暂无已发布', }, feedback: { asker_value: '', up: 0, down: 0 }, }, ], columns: [], total: 1, has_more: false, next_cursor: '', as_of: query.end, local_revision: 1, } as QARecordPage const quality = { start: query.start, end: query.end, keyword: '', as_of: query.end, scope: 'whole_filter', ai_state: 'not_configured', summary: { total: 1, reviewed: 0, unreviewed: 1, stale: 0, pending_confirmation: 0, rule_uncovered: 1, rates: { policy_version: 'quality-rates-human-first-v1', coverage: { numerator: 0, denominator: 1, percent: 0 }, correctness: { numerator: 0, denominator: 0, percent: null }, breakdown: { covered: 0, uncovered: 1, partial: 0, pending: 0, unassessed: 0, excluded: 0, stale: 0, covered_correct: 0, covered_incorrect: 0, covered_pending: 0, covered_unassessed: 0, }, }, }, } as QualitySummary describe('weekly draft export', () => { it('builds preview and downloadable evidence from the same complete query without invented correctness', () => { const d = buildQAWeeklyDraft(page, query, quality, '2026-10-18T10:00:00Z') expect(d.questions).toBe(1) expect(d.revision).toBe(1) expect(d.markdown).toContain('周报(草稿)') expect(d.markdown).toContain('正确率:—') expect(renderToStaticMarkup(createElement(QAAnswerMarkdown, { answer: d.markdown }))).toContain(' { const input = { ...page, items: page.items.map((r) => ({ ...r, question: '中文 [链接](https://example.invalid) **危险**' + String.fromCharCode(10) + '第二行', })), } const d = buildQAWeeklyDraft(input, query, quality, query.end) const html = renderToStaticMarkup(createElement(QAAnswerMarkdown, { answer: d.markdown })) expect(html).not.toContain('>链接') expect(html).not.toContain('危险') expect(d.markdown).not.toContain(String.fromCharCode(10) + '第二行') }) it('refuses incomplete ranges or statistics from another scope', () => { expect(() => buildQAWeeklyDraft({ ...page, has_more: true }, query, quality, query.end)).toThrow() expect(() => buildQAWeeklyDraft(page, query, { ...quality, keyword: 'other' }, query.end)).toThrow() }) })