gongxiangp2/lib/__tests__/performance-salary-templates.test.ts

50 lines
3.0 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 { currentSalaryMonth, getSalaryTemplate, resolveSalaryMonth, salaryDetailsHref, salaryMonthLabel } from '@/lib/performance-salary-templates'
describe('薪资模板月份与字段', () => {
test('上海时区跨月及非法查询参数', () => {
const now = new Date('2026-12-31T16:00:00Z')
expect(currentSalaryMonth(now)).toBe('2027-01')
for (const value of [undefined, '', '2026-13', '2026-1', '0000-01', ['2026-09'], '2026-09<script>']) {
expect(resolveSalaryMonth(value, now)).toBe('2027-01')
}
expect(resolveSalaryMonth('2026-09', now)).toBe('2026-09')
expect(salaryMonthLabel('2027-01', -1)).toBe('2026年12月')
expect(salaryMonthLabel('2027-01', -2)).toBe('2026年11月')
expect(salaryDetailsHref('management', '2027-01')).toBe('/workspaces/organization/performance-review?role=management&month=2027-01')
})
test('AI每项只保留综合占比考核得分,删除三项保底字段', () => {
const template = getSalaryTemplate('ai-planning', '2026-09')
expect(template.columns).toHaveLength(19)
expect(template.columns.map(column => column.label)).toEqual(expect.arrayContaining([
'品牌调性评审 · 考核得分(综合占比25%)', '项目按时交付率 · 考核得分(综合占比63%)',
]))
expect(template.columns.some(column => /Weighted/.test(column.key) || /加权得分|保底提成|实际保底/.test(column.label))).toBe(false)
})
test('摄影保留16列,薪资比较月份跨年', () => {
const template = getSalaryTemplate('photography', '2027-01')
expect(template.columns).toHaveLength(16)
expect(template.grouped).toBe(false)
expect(template.columns.slice(11, 14).map(column => column.label)).toEqual(['2027年1月合计薪资', '2026年12月合计薪资', '2026年11月合计薪资'])
})
test('空间视觉单列考核得分,未确认维度占比不猜测', () => {
const template = getSalaryTemplate('spatial-visual', '2026-10')
expect(template.columns).toHaveLength(16)
expect(template.columns.map(column => column.label)).not.toEqual(expect.arrayContaining(['百分比', '实际绩效']))
expect(template.groups.find(group => group.key === 'cooperation')?.label).toBe('配合度 · 维度权重5%')
expect(template.columns.map(column => column.label)).toContain('工作配合度 · 考核得分(综合占比0.3%)')
})
test('管理岗合并为17列,身份唯一,保留得分与系数', () => {
const template = getSalaryTemplate('management', '2027-01')
const labels = template.columns.map(column => column.label)
expect(labels).toHaveLength(17)
expect(labels.filter(label => ['姓名', '花名', '部门'].includes(label))).toEqual(['姓名', '花名', '部门'])
expect(labels).not.toContain('保护提成')
expect(labels).toEqual(expect.arrayContaining(['2027年1月绩效得分', '绩效系数', '2027年1月新薪资', '2026年12月薪资']))
expect(new Set(template.columns.map(column => column.key)).size).toBe(17)
})
})