45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { calculatePerformanceSurveyResponseProgress } 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,
|
|
})
|
|
})
|
|
})
|