import { renderToStaticMarkup } from 'react-dom/server'
import { describe, it, expect, vi } from 'vitest'
import { qaDailySeries, qaCategorySeries } from './qaDashboard'
import { QADashboard, QADashboardView } from './QADashboard'
import { parseQADashboard } from './qaDashboardData'
import { dashboardFixture } from './qaDashboard.fixture'
import type { QARecord, QAQuery } from './qaOps'
const query: QAQuery = { start: '2026-10-11T16:00:00Z', end: '2026-10-13T16:00:00Z', keyword: '', cursor: '' }
const records = [
{ id: 'a', asked_at: '2026-10-11T16:30:00Z', product_category: '
', problem_type: '通信' },
{ id: 'b', asked_at: '2026-10-12T16:01:00Z' },
] as QARecord[]
describe('question dashboard projections', () => {
it('does not render the personal monthly details entry on the statistics dashboard', () => {
const html = renderToStaticMarkup()
expect(html).not.toContain('个人月明细')
expect(html).not.toContain('qa-monthly-disclosure')
})
it('groups by Beijing day and keeps zero days instead of using the browser timezone', () => {
expect(qaDailySeries(records, query)).toEqual([
{ label: '2026-10-12', count: 1 },
{ label: '2026-10-13', count: 1 },
])
expect(qaDailySeries([], query).map((p) => p.count)).toEqual([0, 0])
})
it('keeps unclassified records distinct without inventing a category', () => {
expect(qaCategorySeries(records, 'problem_type')).toEqual([
{ label: '通信', count: 1 },
{ label: '未分类', count: 1 },
])
})
it('renders the real dashboard panels and escaped category text', () => {
const html = renderToStaticMarkup(
)
for (const title of ['问题总数', '本周新增', '覆盖率趋势', '正确率趋势', '产品问题排行', '导出看板图片'])
expect(html).toContain(title)
expect(html).not.toContain(')