gongxiangp2/components/department-dashboard/CoreMetricDetail.test.tsx
2026-08-19 12:08:38 +08:00

126 lines
5.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { render, screen } from '@testing-library/react'
import CoreMetricDetail from './CoreMetricDetail'
import { getCoreMetric } from './core-metrics'
jest.mock('next-auth/react', () => ({
useSession: () => ({ data: { user: { name: '本地超级管理员' } } }),
signOut: jest.fn(),
}))
describe('CoreMetricDetail', () => {
it('展示真实进行中项目列表与数据口径', () => {
const metric = getCoreMetric('ongoing-projects')!
render(
<CoreMetricDetail
metric={metric}
projectPage={{
items: [{
id: 'project-1',
title: '夏季主视觉过稿',
description: null,
status: 'pending_review',
workDate: '2026-08-10T00:00:00.000Z',
latestVersion: 2,
submitterName: '林一',
managerName: '陈主管',
finalReviewerName: '元泽',
updatedAt: '2026-08-14T02:30:00.000Z',
}],
pagination: { page: 1, pageSize: 20, total: 1, totalPages: 1 },
}}
/>,
)
expect(screen.getByRole('heading', { level: 1, name: '进行中项目' })).toBeInTheDocument()
expect(screen.getAllByText('夏季主视觉过稿')).toHaveLength(2)
expect(screen.getAllByText('评审中').length).toBeGreaterThan(0)
expect(screen.getByText(/数据来自作品过稿项目库/)).toBeInTheDocument()
expect(screen.getByRole('link', { name: /返回核心指标/ })).toHaveAttribute('href', '/workspaces/dashboard/core-metrics')
})
it('未接入的指标只展示诚实的明细框架', () => {
render(<CoreMetricDetail metric={getCoreMetric('risks')!} />)
expect(screen.getByRole('heading', { level: 1, name: '风险' })).toBeInTheDocument()
expect(screen.getByText(/当前不展示虚构记录/)).toBeInTheDocument()
expect(screen.getByText('数据源待接入')).toBeInTheDocument()
})
it('在按时交付明细中只用黄色数值呈现阈值状态', () => {
render(<CoreMetricDetail metric={getCoreMetric('on-time-delivery')!} />)
expect(screen.getByLabelText('按时交付示例值94.6%,黄色区间90%–95%')).toHaveClass('text-[#a88a00]')
expect(screen.queryByText('黄色区间 · 90%–95%')).not.toBeInTheDocument()
})
it('展示首轮通过真实公式与每个作品的 V1 审核结果', () => {
render(
<CoreMetricDetail
metric={getCoreMetric('first-pass-rate')!}
firstPassPage={{
summary: {
totalUploads: 3,
firstPassApproved: 1,
rate: 33.3,
statusBreakdown: { approved: 1, revisionRequired: 1, pendingReview: 1, unknown: 0 },
readAt: '2026-08-14T02:00:00.000Z',
},
items: [
{
id: 'approved-v1',
title: '已通过作品',
currentStatus: 'approved',
latestVersion: 1,
submitterName: '林一',
managerName: '陈主管',
finalReviewerName: '元泽',
workDate: '2026-08-10T00:00:00.000Z',
updatedAt: '2026-08-14T02:30:00.000Z',
firstVersionStatus: 'approved',
firstVersionSubmittedAt: '2026-08-10T02:00:00.000Z',
firstVersionCompletedAt: '2026-08-11T02:00:00.000Z',
},
{
id: 'revision-v1',
title: '首轮退修作品',
currentStatus: 'revision_required',
latestVersion: 1,
submitterName: '林二',
managerName: '陈主管',
finalReviewerName: '元泽',
workDate: '2026-08-11T00:00:00.000Z',
updatedAt: '2026-08-14T02:30:00.000Z',
firstVersionStatus: 'revision_required',
firstVersionSubmittedAt: '2026-08-11T02:00:00.000Z',
firstVersionCompletedAt: '2026-08-12T02:00:00.000Z',
},
{
id: 'pending-v1',
title: '评审中作品',
currentStatus: 'pending_review',
latestVersion: 1,
submitterName: '林三',
managerName: '陈主管',
finalReviewerName: '元泽',
workDate: '2026-08-12T00:00:00.000Z',
updatedAt: '2026-08-14T02:30:00.000Z',
firstVersionStatus: 'pending_review',
firstVersionSubmittedAt: '2026-08-12T02:00:00.000Z',
firstVersionCompletedAt: null,
},
],
pagination: { page: 1, pageSize: 20, total: 3, totalPages: 1 },
}}
/>,
)
expect(screen.getByRole('heading', { level: 1, name: '首轮通过' })).toBeInTheDocument()
expect(screen.getByText('首轮通过率 = V1 审核通过作品数 ÷ 全部上传作品数 × 100%')).toBeInTheDocument()
expect(screen.getByText('当前口径:1 ÷ 3 = 33.3%')).toBeInTheDocument()
expect(screen.getAllByText('首轮通过').length).toBeGreaterThan(0)
expect(screen.getAllByText('首轮未通过').length).toBeGreaterThan(0)
expect(screen.getAllByText('首轮评审中 · 仅计入分母').length).toBeGreaterThan(0)
expect(screen.getByRole('link', { name: /打开作品过稿数据源/ })).toHaveAttribute('href', 'https://sc.jiansun.vip/work-review')
})
})