1580ebd826
build / build (push) Successful in 1m8s
按北京时间各自然周截止对整张统计总表累计计数,字段取当前有效结论。 覆盖和正确各按周报是除以是加否,保留历史上报与冻结并优先展示动态累计。 新增30秒顺序刷新、本地规则和历史复用非模型依据,保护当前原问答与人工字段。 验证:完整make verify通过;隔离PostgreSQL全量mirror race通过; 恢复库与真实周报calc_metrics四点对拍、源点踩自然刷新、桌面/390px及PNG通过。 新增源同步成员变化、人工版本保护及跨策略标签间距回归已通过。 模型全量语义风险审核及正式业务回填尚未完成,未部署本版本。
118 lines
5.0 KiB
TypeScript
118 lines
5.0 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { it, expect } from 'vitest'
|
|
import { QADashboardDrawing } from './QADashboardDrawing'
|
|
import { dashboardFixture } from './qaDashboard.fixture'
|
|
import { parseQADashboard } from './qaDashboardData'
|
|
it('draws all eleven panels as a self-contained exportable SVG without HTML execution', () => {
|
|
const html = renderToStaticMarkup(<QADashboardDrawing data={parseQADashboard(dashboardFixture)} width={1280} />)
|
|
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('<foreignObject')
|
|
expect(html).not.toContain('<img src=x')
|
|
expect(html).toContain('data-frozen="missing"')
|
|
expect(html).toContain('data-frozen="available"')
|
|
})
|
|
it('renders reported history in both existing trend panels with exact values and honest provenance', () => {
|
|
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(<QADashboardDrawing data={data} width={1280} />)
|
|
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(<QADashboardDrawing data={data} width={350} />)
|
|
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(<QADashboardDrawing data={data} width={1166} />),
|
|
groups = [...html.matchAll(/<g data-source="[^"]+" data-week="[^"]+"[\s\S]*?<\/g>/g)]
|
|
const labels = groups
|
|
.slice(0, 29)
|
|
.map((g) => g[0].match(/<text x="([0-9.]+)"[^>]*>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</text>')
|
|
})
|
|
it('reflows the same complete eleven panels at mobile width rather than clipping the canvas', () => {
|
|
const html = renderToStaticMarkup(<QADashboardDrawing data={parseQADashboard(dashboardFixture)} width={350} />)
|
|
expect((html.match(/data-panel=/g) || []).length).toBe(11)
|
|
expect(html).toContain('viewBox="0 0 350 ')
|
|
})
|