65 lines
2.5 KiB
JavaScript
65 lines
2.5 KiB
JavaScript
|
|
import assert from 'node:assert/strict'
|
||
|
|
import { readFileSync } from 'node:fs'
|
||
|
|
import test from 'node:test'
|
||
|
|
import { fileURLToPath } from 'node:url'
|
||
|
|
|
||
|
|
const detailTemplate = readFileSync(
|
||
|
|
fileURLToPath(new URL('../src/views/TravelRequestDetailView.vue', import.meta.url)),
|
||
|
|
'utf8'
|
||
|
|
)
|
||
|
|
const detailScript = readFileSync(
|
||
|
|
fileURLToPath(new URL('../src/views/scripts/TravelRequestDetailView.js', import.meta.url)),
|
||
|
|
'utf8'
|
||
|
|
)
|
||
|
|
const reimbursementService = readFileSync(
|
||
|
|
fileURLToPath(new URL('../src/services/reimbursements.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('approval-mode detail collects leader opinion and confirms approval before API call', () => {
|
||
|
|
assert.match(detailScript, /approvalMode:/)
|
||
|
|
assert.match(detailScript, /const leaderOpinion = ref\(''\)/)
|
||
|
|
assert.match(detailScript, /const approveConfirmDialogOpen = ref\(false\)/)
|
||
|
|
assert.match(detailScript, /const canApproveRequest = computed/)
|
||
|
|
assert.match(detailScript, /approveExpenseClaim\(request\.value\.claimId, \{[\s\S]*opinion: leaderOpinion\.value\.trim\(\)/)
|
||
|
|
|
||
|
|
assert.match(detailTemplate, /v-if="showLeaderApprovalPanel"/)
|
||
|
|
assert.match(detailTemplate, /领导意见/)
|
||
|
|
assert.match(detailTemplate, /v-model="leaderOpinion"/)
|
||
|
|
assert.match(detailTemplate, /@click="handleApproveRequest"/)
|
||
|
|
assert.match(detailTemplate, /:open="approveConfirmDialogOpen"/)
|
||
|
|
assert.match(detailTemplate, /confirm-text="确认通过"/)
|
||
|
|
assert.match(detailTemplate, /@confirm="confirmApproveRequest"/)
|
||
|
|
|
||
|
|
const handleApproveRequest = extractFunction(detailScript, 'handleApproveRequest')
|
||
|
|
const confirmApproveRequest = extractFunction(detailScript, 'confirmApproveRequest')
|
||
|
|
assert.doesNotMatch(handleApproveRequest, /approveExpenseClaim/)
|
||
|
|
assert.match(confirmApproveRequest, /approveExpenseClaim/)
|
||
|
|
|
||
|
|
assert.match(reimbursementService, /export function approveExpenseClaim\(claimId, payload = \{\}\)/)
|
||
|
|
assert.match(reimbursementService, /\/approve/)
|
||
|
|
})
|