import ExcelJS from 'exceljs' import JSZip from 'jszip' import { INITIAL_SALARY_POSITIONS } from '../salary-position-seeds' import { buildPositionWorkbook } from '../salary-position-export' import { buildSalaryTemplateWorkbook } from '../performance-salary-export' test('岗位配置导出同时标明实施月份及有限适用区间', async () => { const seed = INITIAL_SALARY_POSITIONS[0] const position = { ...seed.value, id: seed.id, revision: 1, personnelCount: 0, updatedAt: '', performanceVersion: { id: 'november', effectiveMonth: '2026-11', endsBeforeMonth: '2027-01', revision: 1, } } const workbook = await buildPositionWorkbook([position], []) const reloaded = new ExcelJS.Workbook() await reloaded.xlsx.load(await workbook.xlsx.writeBuffer()) expect(reloaded.worksheets[0].getCell('A2').text).toContain('2026年11月起实施 · 适用期间 2026年11月至2026年12月') }) test('重读岗位配置与薪资空模板:权重来源完整,不含人员、公式或外链', async () => { const positions = INITIAL_SALARY_POSITIONS.map(seed => ({ ...seed.value, id: seed.id, revision: 1, personnelCount: 7, updatedAt: '2026-10-28' })) const book = await buildPositionWorkbook(positions, [{ code: 'visual_brand_tone', name: '视觉调研' }]) const bytes = await book.xlsx.writeBuffer(), reloaded = new ExcelJS.Workbook() await reloaded.xlsx.load(bytes) expect(reloaded.worksheets.map(s => s.name)).toEqual(positions.map(p => p.name)) const text: string[] = [] reloaded.eachSheet(sheet => { expect(sheet.state).toBe('visible') expect(sheet.views[0]).toMatchObject({ state: 'frozen', xSplit: 1, ySplit: 3 }) sheet.eachRow(row => row.eachCell(cell => { text.push(String(cell.value)); expect(cell.type).not.toBe(ExcelJS.ValueType.Formula) })) }) expect(text).toContain('视觉调研') expect(text).toContain('项目维护') expect(text).toContain('0') const zip = await JSZip.loadAsync(bytes) expect(Object.keys(zip.files).some(name => /externalLinks|hidden/i.test(name))).toBe(false) const template = await buildSalaryTemplateWorkbook('2026-10', positions) expect(template.worksheets).toHaveLength(5) for (const sheet of template.worksheets) { for (let row = sheet.rowCount - 4; row <= sheet.rowCount; row++) sheet.getRow(row).eachCell({ includeEmpty: true }, cell => expect(cell.value).toBeNull()) } }) test('重读10月与11月版本导出,薪资按月表头与0%过滤一致,五行全空白且冻结花名',async()=>{ const parent={...INITIAL_SALARY_POSITIONS[1].value,id:INITIAL_SALARY_POSITIONS[1].id,revision:1,personnelCount:7,updatedAt:'',performanceVersions:[ {id:'closed',effectiveMonth:'2026-11',endsBeforeMonth:null,revision:1,description:'按职级',dimensions:[]}, {id:'old',effectiveMonth:'0000-00',endsBeforeMonth:'2026-11',revision:1,description:'原方案',dimensions:INITIAL_SALARY_POSITIONS[1].value.dimensions}, ]} const current=JSON.parse(JSON.stringify(parent.performanceVersions[1].dimensions)) as typeof parent.dimensions current[0].weight='20'; current[1].weight='70'; current[2].weight='10' current[1].metrics.forEach((m,i)=>{m.weight=['30','50','20'][i]}) const child={...parent,id:'child',name:'策划P3',personnelPositionId:parent.id,jobGrade:'P3',performanceVersions:[{id:'new',effectiveMonth:'2026-11',endsBeforeMonth:null,revision:1,description:'11月版',dimensions:current}]} const configuration = new ExcelJS.Workbook() await configuration.xlsx.load(await (await buildPositionWorkbook([{ ...child, performanceVersion: child.performanceVersions[0] }], [], '2026-11')).xlsx.writeBuffer()) expect(configuration.worksheets[0].getCell('A2').text).toContain('适用职级 P2/P3') for(const month of ['2026-10','2026-11']){ const workbook=await buildSalaryTemplateWorkbook(month,[parent,child]) const reread=new ExcelJS.Workbook() await reread.xlsx.load(await workbook.xlsx.writeBuffer()) const sheet=reread.worksheets[0] expect(sheet.getCell(1,1).text).toContain(month==='2026-10'?'2026年10月及以前':'2026年11月起实施') expect((sheet.getRow(3).values as ExcelJS.CellValue[]).join(' ')).toContain(month==='2026-10'?'综合占比63%':'综合占比35%') expect((sheet.getRow(3).values as ExcelJS.CellValue[]).join(' ').includes('知识分享')).toBe(month==='2026-11') expect(sheet.getCell(1,1).text.includes('适用职级 P2/P3')).toBe(month === '2026-11') expect(reread.worksheets).toHaveLength(5) expect(sheet.getCell(3,1).text).toBe('花名') expect(sheet.views[0]).toMatchObject({state:'frozen',xSplit:1,ySplit:3}) expect(sheet.rowCount).toBe(8) for(let row=4;row<=8;row++) sheet.getRow(row).eachCell({includeEmpty:true},cell=>expect(cell.value).toBeNull()) } })