cb9f0c389f
build / build (push) Successful in 1m10s
去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。 自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。 验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。 真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。 没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
137 lines
6.1 KiB
TypeScript
137 lines
6.1 KiB
TypeScript
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(
|
|
<QADashboardDrawing data={parseQADashboard(calendarDashboardFixture)} width={362} />
|
|
)
|
|
expect(html).toContain('区域统计 2026-10 月累计')
|
|
const accuracy = html.split('data-panel="accuracy-trend"')[1]
|
|
expect(accuracy).toMatch(/<text[^>]*>2026-09<\/text>/)
|
|
expect(accuracy).toMatch(/<text[^>]*>—<\/text>/)
|
|
})
|
|
import { parseQADashboard } from './qaDashboardData'
|
|
it('places a keyboard-accessible statistics definition in the upper-right of every card', () => {
|
|
const html = renderToStaticMarkup(<QADashboardDrawing data={parseQADashboard(dashboardFixture)} width={1280} />)
|
|
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(<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 ')
|
|
})
|