55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
|
|
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'
|
||
|
|
)
|
||
|
|
|
||
|
|
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, /<ConfirmDialog[\s\S]*:open="submitConfirmDialogOpen"[\s\S]*confirm-text="确认提交"[\s\S]*@close="closeSubmitConfirmDialog"[\s\S]*@confirm="confirmSubmitRequest"/)
|
||
|
|
assert.match(detailViewTemplate, /cancel-text="返回核对"/)
|
||
|
|
assert.match(detailViewTemplate, /@click="handleSubmit"/)
|
||
|
|
|
||
|
|
assert.match(detailViewScript, /const submitConfirmDialogOpen = ref\(false\)/)
|
||
|
|
assert.match(detailViewScript, /submitConfirmDialogOpen\.value = true/)
|
||
|
|
assert.match(detailViewScript, /submitConfirmDialogOpen\.value = false/)
|
||
|
|
assert.match(detailViewScript, /submitConfirmDialogOpen,/)
|
||
|
|
assert.match(detailViewScript, /closeSubmitConfirmDialog,/)
|
||
|
|
assert.match(detailViewScript, /confirmSubmitRequest,/)
|
||
|
|
|
||
|
|
const handleSubmit = extractFunction(detailViewScript, 'handleSubmit')
|
||
|
|
const confirmSubmitRequest = extractFunction(detailViewScript, 'confirmSubmitRequest')
|
||
|
|
assert.doesNotMatch(handleSubmit, /submitExpenseClaim/)
|
||
|
|
assert.match(confirmSubmitRequest, /submitExpenseClaim\(request\.value\.claimId\)/)
|
||
|
|
})
|