51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { groupVisualScoresByEvaluator } from '@/lib/performance-survey-result-grouping'
|
|
|
|
describe('performance survey visual result grouping', () => {
|
|
const workItems = [1, 2, 3].map((index) => ({
|
|
id: `work-${index}`,
|
|
title: `作品 ${index}`,
|
|
scores: [
|
|
{ id: `score-a-${index}`, participantKey: 'participant-a', totalScore: index === 1 ? 0 : index * 10 },
|
|
{ id: `score-b-${index}`, participantKey: 'participant-b', totalScore: index * 10 + 1 },
|
|
],
|
|
}))
|
|
|
|
it('三个作品只生成一次作品数据,并按评分人汇总各自三项评分', () => {
|
|
const result = groupVisualScoresByEvaluator([
|
|
{ id: 'response-a', participantKey: 'participant-a', respondentName: '评分人A' },
|
|
{ id: 'response-b', participantKey: 'participant-b', respondentName: '评分人B' },
|
|
], workItems)
|
|
|
|
expect(result).toHaveLength(2)
|
|
expect(result[0].workItemScores).toHaveLength(3)
|
|
expect(result[0].workItemScores.map((item) => item.score?.id)).toEqual([
|
|
'score-a-1',
|
|
'score-a-2',
|
|
'score-a-3',
|
|
])
|
|
expect(result[1].workItemScores.map((item) => item.score?.id)).toEqual([
|
|
'score-b-1',
|
|
'score-b-2',
|
|
'score-b-3',
|
|
])
|
|
})
|
|
|
|
it('同名评分人依靠参与键区分,并保留合法的零分', () => {
|
|
const result = groupVisualScoresByEvaluator([
|
|
{ id: 'response-a', participantKey: 'participant-a', respondentName: '同名' },
|
|
{ id: 'response-b', participantKey: 'participant-b', respondentName: '同名' },
|
|
], workItems)
|
|
|
|
expect(result[0].workItemScores[0].score?.totalScore).toBe(0)
|
|
expect(result[1].workItemScores[0].score?.totalScore).toBe(11)
|
|
})
|
|
|
|
it('缺失的作品评分保持为空,不伪造成零分', () => {
|
|
const result = groupVisualScoresByEvaluator([
|
|
{ id: 'response-a', participantKey: 'participant-a' },
|
|
], [{ id: 'work-missing', title: '未评分作品', scores: [] }])
|
|
|
|
expect(result[0].workItemScores[0].score).toBeNull()
|
|
})
|
|
})
|