import { renderToStaticMarkup } from 'react-dom/server' import { it, expect } from 'vitest' import { QADashboardDrawing } from './QADashboardDrawing' import { dashboardFixture } from './qaDashboard.fixture' import { calendarDashboardFixture } from './qaDashboardMonthly.fixture' it('keeps the month identifiers intact on a narrow monthly-dashboard heading', () => { const html = renderToStaticMarkup( ) expect(html).toContain('区域统计 2026-10 月累计') const accuracy = html.split('data-panel="accuracy-trend"')[1] expect(accuracy).toMatch(/]*>2026-09<\/text>/) expect(accuracy).toMatch(/]*>—<\/text>/) }) import { parseQADashboard } from './qaDashboardData' it('places a keyboard-accessible statistics definition in the upper-right of every card', () => { const html = renderToStaticMarkup() expect((html.match(/data-statistics-help=/g) || []).length).toBe(11) expect((html.match(/统计口径<\/text>/g) || []).length).toBe(11) expect((html.match(/aria-label="[^"]*统计口径[^"]*"/g) || []).length).toBe(11) expect(html).toContain('tabindex="0"') expect(html).toContain('原始提问时间') expect(html).toContain('是÷(是+否)') }) it('draws all eleven panels as a self-contained exportable SVG without HTML execution', () => { const html = renderToStaticMarkup() expect((html.match(/data-panel=/g) || []).length).toBe(11) for (const title of [ '问题总数', '本周新增', '覆盖率', '正确率', '问题类型分布', '产品问题排行', '问题趋势', '区域平均使用频率', '区域使用覆盖率', '覆盖率趋势', '正确率趋势', ]) expect(html).toContain(title) expect(html).toContain('<img src=x') expect(html).not.toContain(' { const data = parseQADashboard({ ...dashboardFixture, reported_weeks: [ { week: '2026WK40', week_start: '2026-09-28T00:00:00+08:00', week_end: '2026-10-05T00:00:00+08:00', coverage_percent: 57.23, correctness_percent: 92.34, source: 'user_provided_history', }, ], }) const html = renderToStaticMarkup() expect(html).toContain('57.23%') expect(html).toContain('92.34%') expect(html).toContain('用户提供历史统计') expect(html).toContain('未提供分子/分母') expect((html.match(/data-source="user_provided_history"/g) || []).length).toBe(2) expect((html.match(/data-panel=/g) || []).length).toBe(11) expect(html).toContain('data-frozen="available"') }) it('renders dynamic cumulative points as a distinct green policy series in both charts', () => { const data = parseQADashboard({ ...dashboardFixture, cumulative_weeks: [ { week: '2026WK40', week_start: '2026-09-28T00:00:00+08:00', week_end: '2026-10-05T00:00:00+08:00', cutoff_at: '2026-10-05T00:00:00+08:00', calculated_at: '2026-10-18T10:00:00Z', records: 2, coverage: { numerator: 1, denominator: 2, percent: 50 }, correctness: { numerator: 1, denominator: 2, percent: 50 }, source: 'master_live_cumulative_v1', policy_version: 'weekly-strict-yes-over-yes-no-v1', }, ], }) const html = renderToStaticMarkup() expect(html).toContain('绿:总表累计') expect(html).toContain('stroke="#249c86"') expect((html.match(/data-source="master_live_cumulative_v1"/g) || []).length).toBe(2) expect(html).toContain('非历史冻结') }) it('keeps adjacent policy-boundary week and percentage labels from overlapping in long history', () => { const data = parseQADashboard(dashboardFixture), first = Date.parse('2026-04-06T00:00:00+08:00'), week = 7 * 86400000 data.end = '2026-10-20T01:00:00Z' data.reported_weeks = Array.from({ length: 25 }, (_, i) => ({ week: `2026WK${String(15 + i).padStart(2, '0')}`, week_start: new Date(first + i * week).toISOString(), week_end: new Date(first + (i + 1) * week).toISOString(), coverage_percent: 70, correctness_percent: 97, source: 'user_provided_history', })) data.cumulative_weeks = Array.from({ length: 4 }, (_, i) => ({ week: `2026WK${40 + i}`, week_start: new Date(first + (25 + i) * week).toISOString(), week_end: new Date(first + (26 + i) * week).toISOString(), cutoff_at: new Date(Math.min(first + (26 + i) * week, Date.parse(data.end))).toISOString(), calculated_at: data.end, records: 1, coverage: { numerator: 1, denominator: 1, percent: 100 }, correctness: { numerator: 1, denominator: 1, percent: 100 }, source: 'master_live_cumulative_v1', policy_version: 'weekly-strict-yes-over-yes-no-v1', })) const html = renderToStaticMarkup(), groups = [...html.matchAll(//g)] const labels = groups .slice(0, 29) .map((g) => g[0].match(/]*>2026W[0-9]+<\/text>/)) .filter((v): v is RegExpMatchArray => v !== null) .map((m) => Number(m[1])) .sort((a, b) => a - b) expect(groups).toHaveLength(58) for (let i = 1; i < labels.length; i++) expect(labels[i] - labels[i - 1]).toBeGreaterThanOrEqual(51.99) expect(groups.find((g) => g[0].includes('data-week="2026WK40"'))?.[0]).toContain('2026W40') }) it('reflows the same complete eleven panels at mobile width rather than clipping the canvas', () => { const html = renderToStaticMarkup() expect((html.match(/data-panel=/g) || []).length).toBe(11) expect(html).toContain('viewBox="0 0 350 ') })