111 lines
3.2 KiB
TypeScript
111 lines
3.2 KiB
TypeScript
import {
|
|
calculatePerformanceSurveyResponseProgress,
|
|
calculatePerformanceSurveyWorkItemProgress,
|
|
} from '@/lib/performance-survey-response-progress'
|
|
|
|
const questions = [{ id: 'q1' }, { id: 'q2' }, { id: 'q3' }]
|
|
|
|
describe('performance survey response progress', () => {
|
|
it('填写过程中读取尚未提交的本地评分', () => {
|
|
const result = calculatePerformanceSurveyResponseProgress({
|
|
questions,
|
|
draftScores: { q1: 12, q2: 0 },
|
|
submitted: false,
|
|
})
|
|
expect(result).toMatchObject({
|
|
ratedCount: 2,
|
|
totalCount: 3,
|
|
totalScore: 12,
|
|
})
|
|
expect(result.percent).toBeCloseTo(200 / 3)
|
|
})
|
|
|
|
it('提交后改读数据库响应,不受本地评分清空影响', () => {
|
|
expect(calculatePerformanceSurveyResponseProgress({
|
|
questions,
|
|
draftScores: {},
|
|
submittedScores: { q1: 18, q2: 17, q3: 16 },
|
|
submitted: true,
|
|
})).toEqual({
|
|
ratedCount: 3,
|
|
totalCount: 3,
|
|
totalScore: 51,
|
|
percent: 100,
|
|
})
|
|
})
|
|
|
|
it('零分算已填写,缺失值和空值不算', () => {
|
|
expect(calculatePerformanceSurveyResponseProgress({
|
|
questions,
|
|
draftScores: { q1: 0, q2: null, q3: '' },
|
|
submitted: false,
|
|
})).toMatchObject({
|
|
ratedCount: 1,
|
|
totalScore: 0,
|
|
})
|
|
})
|
|
|
|
it('视觉案例进度同时统计当前评分人的已保存评分和完整本地草稿', () => {
|
|
const result = calculatePerformanceSurveyWorkItemProgress({
|
|
questions,
|
|
assignmentId: 'assignment-current',
|
|
workItems: [
|
|
{ id: 'work-1', scores: [{ assignmentId: 'assignment-current', totalScore: 27 }] },
|
|
{ id: 'work-2', scores: [] },
|
|
{ id: 'work-3', scores: [] },
|
|
],
|
|
scoreDrafts: {
|
|
'work-2': { scores: { q1: 10, q2: 0, q3: 8 } },
|
|
'work-3': { scores: { q1: 10, q2: 9 } },
|
|
},
|
|
})
|
|
|
|
expect(result).toEqual({
|
|
completedCount: 2,
|
|
persistedCount: 1,
|
|
totalScore: 64,
|
|
persistedWorkItemIds: ['work-1'],
|
|
draftCompletedWorkItemIds: ['work-2'],
|
|
unscoredWorkItemIds: ['work-2', 'work-3'],
|
|
})
|
|
})
|
|
|
|
it('视觉案例进度不把其他评分人的已保存记录算给当前评分人', () => {
|
|
expect(calculatePerformanceSurveyWorkItemProgress({
|
|
questions,
|
|
assignmentId: 'assignment-current',
|
|
workItems: [
|
|
{ id: 'work-1', scores: [{ assignmentId: 'assignment-other' }] },
|
|
],
|
|
})).toMatchObject({
|
|
completedCount: 0,
|
|
persistedCount: 0,
|
|
totalScore: 0,
|
|
unscoredWorkItemIds: ['work-1'],
|
|
})
|
|
})
|
|
|
|
it('视觉案例分数优先读取当前评分人的已保存总分且不重复累计本地草稿', () => {
|
|
expect(calculatePerformanceSurveyWorkItemProgress({
|
|
questions,
|
|
assignmentId: 'assignment-current',
|
|
workItems: [
|
|
{
|
|
id: 'work-1',
|
|
scores: [
|
|
{ assignmentId: 'assignment-other', totalScore: 30 },
|
|
{ assignmentId: 'assignment-current', totalScore: 24 },
|
|
],
|
|
},
|
|
],
|
|
scoreDrafts: {
|
|
'work-1': { scores: { q1: 10, q2: 10, q3: 10 } },
|
|
},
|
|
})).toMatchObject({
|
|
completedCount: 1,
|
|
persistedCount: 1,
|
|
totalScore: 24,
|
|
})
|
|
})
|
|
})
|