import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' import { fileURLToPath } from 'node:url' const detailViewTemplate = readFileSync( fileURLToPath(new URL('../src/views/TravelRequestDetailView.vue', import.meta.url)), 'utf8' ) const detailViewScript = readFileSync( fileURLToPath(new URL('../src/views/scripts/TravelRequestDetailView.js', import.meta.url)), 'utf8' ) const detailExpenseModelScript = readFileSync( fileURLToPath(new URL('../src/views/scripts/travelRequestDetailExpenseModel.js', import.meta.url)), 'utf8' ) function extractFunction(source, name) { const signatureIndex = source.indexOf(`function ${name}(`) assert.notEqual(signatureIndex, -1, `${name} should exist`) const bodyStart = source.indexOf('{', signatureIndex) assert.notEqual(bodyStart, -1, `${name} should have a body`) let depth = 0 for (let index = bodyStart; index < source.length; index += 1) { const char = source[index] if (char === '{') { depth += 1 } else if (char === '}') { depth -= 1 if (depth === 0) { return source.slice(signatureIndex, index + 1) } } } assert.fail(`${name} body should be closed`) } test('detail submit opens a confirmation dialog before calling submit API', () => { assert.match(detailViewTemplate, / { assert.match(detailViewTemplate, /:open="riskOverrideDialogOpen"/) assert.match(detailViewTemplate, /重大风险/) assert.match(detailViewTemplate, /goToPreviousSubmitRisk/) assert.match(detailViewTemplate, /goToNextSubmitRisk/) assert.match(detailViewTemplate, /v-model="riskOverrideReasons\[currentSubmitRiskWarning\.id\]"/) assert.match(detailViewScript, /const submitRiskWarnings = computed/) assert.match(detailViewScript, /submitRiskWarnings\.value\.length && !hasRiskOverrideExplanation\.value/) assert.match(detailViewScript, /function confirmRiskOverrideReasons\(\)/) assert.match(detailViewScript, /updateExpenseClaim\(request\.value\.claimId,\s*\{\s*reason: nextNote/s) assert.match(detailViewScript, /超标说明:\$\{tags\}/) }) test('detail header and fallback progress use reimbursement wording', () => { assert.match(detailViewScript, /label:\s*'单据申请日期'/) assert.match(detailExpenseModelScript, /label:\s*'创建单据'/) assert.doesNotMatch(detailViewScript, /label:\s*'保存草稿'/) })