You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
5.3 KiB

4 days ago
jest.mock('@/api/budget/leadDepartment.js', () => ({}))
jest.mock('@/views/budget/collection/components/BudgetSubmissionForm.vue', () => ({}))
import LeadDepartmentSummaryForm from '@/views/budget/collection/components/LeadDepartmentSummaryForm.vue'
function createContext() {
const methods = LeadDepartmentSummaryForm.methods
const context = {
formData: {
economicSummary: [],
fundApplication: {
newProject: {},
oldProject: {}
},
implementationScheduleDetail: {}
},
$set(target, key, value) {
target[key] = value
}
}
context.normalizeFileList = methods.normalizeFileList.bind(context)
context.mergeFileLists = methods.mergeFileLists.bind(context)
return context
}
describe('LeadDepartmentSummaryForm automatic aggregation', () => {
const submissions = [
{
departmentName: '监测一科',
economicItems: [{
categoryId: 1,
categoryName: '物业管理费',
amount: '10.0000',
calculationBasis: '10个月 × 1万元',
files: [{ id: 101, name: '一科.pdf' }]
}],
fundApplication: {
newProject: { totalAmount: '3.0000', yearCurrent: '2.0000', yearNext: '1.0000' },
oldProject: { contractTotal: '8.0000', previousYearsTotal: '4.0000', previousYearBalance: '1.0000', yearCurrent: '2.0000' }
},
implementationScheduleDetail: { currentYearAmount: '4.0000', currentYearMonth1: '1.0000', currentYearMonth2: '3.0000' }
},
{
departmentName: '监测二科',
economicItems: [{
categoryId: 1,
categoryName: '物业管理费',
amount: '20.0000',
calculationBasis: '20个月 × 1万元',
files: [{ id: 102, name: '二科.pdf' }]
}],
fundApplication: {
newProject: { totalAmount: '5.0000', yearCurrent: '3.0000', yearNext: '2.0000' },
oldProject: { contractTotal: '12.0000', previousYearsTotal: '6.0000', previousYearBalance: '2.0000', yearCurrent: '4.0000' }
},
implementationScheduleDetail: { currentYearAmount: '6.0000', currentYearMonth1: '2.0000', currentYearMonth2: '4.0000' }
}
]
it('combines economic amounts, department-labelled bases, and every attachment', () => {
const context = createContext()
LeadDepartmentSummaryForm.methods.generateEconomicSummary.call(context, submissions)
expect(context.formData.economicSummary).toEqual([expect.objectContaining({
categoryId: 1,
totalAmount: '30.0000',
departmentCount: 2,
summaryCalculationBasis: '监测一科10个月 × 1万元\n\n监测二科20个月 × 1万元',
fileList: [
expect.objectContaining({ fileId: 101 }),
expect.objectContaining({ fileId: 102 })
]
})])
})
it('adds all seven fund fields and all thirteen schedule amount fields', () => {
const context = createContext()
LeadDepartmentSummaryForm.methods.aggregateFundApplication.call(context, submissions)
LeadDepartmentSummaryForm.methods.aggregateImplementationScheduleAmounts.call(context, submissions)
expect(context.formData.fundApplication).toEqual({
newProject: { totalAmount: '8.0000', yearCurrent: '5.0000', yearNext: '3.0000' },
oldProject: { contractTotal: '20.0000', previousYearsTotal: '10.0000', previousYearBalance: '3.0000', yearCurrent: '6.0000' }
})
expect(context.formData.implementationScheduleDetail.currentYearAmount).toBe('10.0000')
expect(context.formData.implementationScheduleDetail.currentYearMonth1).toBe('3.0000')
expect(context.formData.implementationScheduleDetail.currentYearMonth2).toBe('7.0000')
expect(context.formData.implementationScheduleDetail.currentYearMonth12).toBe('0.0000')
})
it('inherits fixed-asset choices only when there is one department submission', () => {
const context = createContext()
context.formData.fundApplication = {
newProject: { hasFixedAssets: null },
oldProject: { hasFixedAssets: null }
}
LeadDepartmentSummaryForm.methods.aggregateFundApplication.call(context, submissions)
expect(context.formData.fundApplication.newProject.hasFixedAssets).toBeNull()
expect(context.formData.fundApplication.oldProject.hasFixedAssets).toBeNull()
LeadDepartmentSummaryForm.methods.aggregateFundApplication.call(context, [{
fundApplication: {
newProject: { hasFixedAssets: true },
oldProject: { hasFixedAssets: false }
}
}])
expect(context.formData.fundApplication.newProject.hasFixedAssets).toBe(true)
expect(context.formData.fundApplication.oldProject.hasFixedAssets).toBe(false)
})
it('restores saved economic summary content instead of recalculating it in edit mode', () => {
const context = createContext()
context.formData.economicSummary = [{
categoryId: 1,
summaryCalculationBasis: '自动生成的依据',
fileList: [{ fileId: 101, name: '自动附件.pdf' }]
}]
LeadDepartmentSummaryForm.methods.mergeSavedEconomicSummary.call(context, [{
categoryId: 1,
summaryCalculationBasis: '已保存的汇总依据',
files: [{ id: 201, name: '已保存附件.pdf' }]
}])
expect(context.formData.economicSummary[0]).toEqual(expect.objectContaining({
summaryCalculationBasis: '已保存的汇总依据',
fileList: [expect.objectContaining({ fileId: 201 })]
}))
})
})