gongxiangp2/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx
2026-07-23 09:25:50 +08:00

111 lines
3.9 KiB
TypeScript

/** @jest-environment jsdom */
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { PerformanceSurveyAdminConfig } from './PerformanceSurveyAdminConfig'
const config = {
month: '2026-07',
groups: [{
id: 'group-1',
code: 'brand_designer',
name: '品牌设计师',
sortOrder: 10,
isActive: true,
status: 'ready',
memberCount: 6,
rules: [{
id: 'rule-1',
departmentPathPrefix: '集团/品牌中心',
positionTitle: '品牌设计师',
isActive: true,
sortOrder: 0,
}],
effectivePlan: {
id: 'plan-1',
version: 1,
effectiveMonth: '2026-07',
templateVersionIds: ['version-1'],
},
draftPlan: null,
}],
templates: [{
id: 'template-1',
code: 'visual_review',
name: '视觉案例评分',
description: '视觉案例评分',
surveyType: 'visual_case',
isActive: true,
versions: [{
id: 'version-1',
version: 1,
status: 'published',
effectiveMonth: '2026-07',
definition: {
code: 'visual_review',
name: '视觉案例评分',
shortName: '视觉评分',
description: '视觉案例评分',
surveyType: 'visual_case',
weight: 1,
maxTotal: 120,
questionMaxScore: 20,
requiredWorkItemCount: 3,
workItemImageRequired: true,
questions: [{ id: 'quality', title: '作品质量', maxScore: 20 }],
scoreBands: [],
workflow: {
stages: [{
key: 'review',
label: '终评',
order: 0,
reviewers: [{ source: 'direct_manager', label: '直属主管' }],
}],
scoring: { mode: 'final_reviewer', stageKey: 'review', reviewerSource: 'direct_manager' },
},
},
}],
}],
issues: {
unmatched: [{ id: 'employee-1', displayName: '待配置人员', departmentPath: '集团/品牌中心', positionTitle: '设计师' }],
conflicts: [],
},
} as const
describe('PerformanceSurveyAdminConfig', () => {
test('岗位配置使用岗位列表和右侧编辑区,并展示配置问题', async () => {
const request = jest.fn().mockResolvedValue(config)
render(<PerformanceSurveyAdminConfig mode="positions" request={request} />)
expect(screen.getByText('配置加载中...')).toBeInTheDocument()
await waitFor(() => expect(screen.getByText('品牌设计师')).toBeInTheDocument())
expect(screen.getByText('人员匹配规则')).toBeInTheDocument()
expect(screen.getByText('考核项与顺序')).toBeInTheDocument()
expect(screen.getByText(/未匹配 1 人/)).toBeInTheDocument()
expect(screen.getByText('待配置人员')).toBeInTheDocument()
expect(request).toHaveBeenCalledWith(expect.stringContaining('/admin/config?month='))
})
test('模板管理展示版本状态、评分项和评审流程', async () => {
const request = jest.fn().mockResolvedValue(config)
render(<PerformanceSurveyAdminConfig mode="templates" request={request} />)
await waitFor(() => expect(screen.getAllByText('视觉案例评分').length).toBeGreaterThan(0))
expect(screen.getByText('评分项')).toBeInTheDocument()
expect(screen.getByText('评审流程')).toBeInTheDocument()
expect(screen.getByText(/v1 · 已发布/)).toBeInTheDocument()
})
test('岗位发布失败时直接展示服务端业务错误', async () => {
const request = jest.fn().mockImplementation((path: string) => (
path.startsWith('/admin/config')
? Promise.resolve(config)
: Promise.reject(new Error('岗位规则存在重复匹配人员'))
))
render(<PerformanceSurveyAdminConfig mode="positions" request={request} />)
await waitFor(() => expect(screen.getByText('品牌设计师')).toBeInTheDocument())
fireEvent.click(screen.getByRole('button', { name: /发布至/ }))
await waitFor(() => expect(screen.getByText('岗位规则存在重复匹配人员')).toBeInTheDocument())
})
})