Files
knowledge-governance/web/src/QAUsage.test.tsx
T
2026-10-18 21:50:29 +08:00

47 lines
1.9 KiB
TypeScript

import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it } from 'vitest'
import { QAUsageView } from './QAUsage'
import { parseQAUsage } from './qaUsage'
const usage = parseQAUsage({
organization: {
state: 'ready',
directory_id: 'd',
directory_source: 'weekly_report_live',
synced_at: '2026-10-17T07:59:50Z',
revision_id: 'r',
basis: 'current_directory',
},
as_of: '2026-10-17T08:00:00Z',
start: '2026-10-14T00:00:00Z',
end: '2026-10-15T00:00:00Z',
keyword: '',
questions: 2,
identified_users: 0,
rows: [{ key: 'unmatched', questions: 2, succeeded: 1, failed: 1, other: 0, users: null, roster_people: null }],
})
describe('usage statistics evidence', () => {
it('renders a custom label without inheriting Object prototype properties', () => {
const custom = {
...usage,
organization: { ...usage.organization, region_names: ['toString'] },
rows: usage.rows.map((r) => ({ ...r, key: 'toString' })),
}
const html = renderToStaticMarkup(<QAUsageView data={custom} loading={false} error="" onRetry={() => {}} />)
expect(html).toContain('toString')
})
it('shows a current-roster basis and unknown counts without performance claims', () => {
const html = renderToStaticMarkup(<QAUsageView data={usage} loading={false} error="" onRetry={() => {}} />)
expect(html).toContain('按当前通讯录回看')
expect(html).toContain('名册未匹配')
expect(html).toContain('不可确定')
expect(html).not.toContain('达标率')
expect(html).not.toContain('绩效合格')
})
it('keeps unavailable data an error, not a zero-result report', () => {
const html = renderToStaticMarkup(<QAUsageView data={null} loading={false} error="上游不可用" onRetry={() => {}} />)
expect(html).toContain('上游不可用')
expect(html).not.toContain('共 0 条')
})
})