Files
X-Financial/web/tests/travel-reimbursement-composer-tools.test.mjs

68 lines
2.0 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
import {
buildStructuredComposerSubmitText
} from '../src/views/scripts/useTravelReimbursementComposerTools.js'
const submitComposerScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementSubmitComposer.js', import.meta.url)),
'utf8'
)
test('composer formats date-picker expense text into readable structured fields', () => {
const formatted = buildStructuredComposerSubmitText(
'发生时间2026-05-20 至 2026-05-23去上海支撑上海国电的服务器部署出差3天',
{
mode: 'range',
start_date: '2026-05-20',
end_date: '2026-05-23',
business_time: '2026-05-20 至 2026-05-23'
}
)
assert.equal(
formatted,
[
'发生时间2026-05-20 至 2026-05-23',
'地点:上海',
'事由:支撑上海国电的服务器部署',
'天数3天'
].join('\n')
)
})
test('composer extracts destination and reason from compact travel text', () => {
const formatted = buildStructuredComposerSubmitText(
'出差上海,支撑国网服务器上线部署',
{
mode: 'single',
start_date: '2026-05-25',
end_date: '2026-05-25',
business_time: '2026-05-25'
}
)
assert.equal(
formatted,
[
'发生时间2026-05-25',
'地点:上海',
'事由:支撑国网服务器上线部署',
'天数1天'
].join('\n')
)
})
test('composer keeps backend raw text but displays structured user message', () => {
assert.match(submitComposerScript, /const rawText = resolveComposerSubmitText\(options\.rawText\)\.trim\(\)/)
assert.match(submitComposerScript, /resolveComposerDisplaySubmitText\(rawText\)/)
})
test('knowledge questions keep enough request time for LightRAG retrieval', () => {
assert.match(submitComposerScript, /timeoutMs:\s*75000/)
assert.match(submitComposerScript, /知识问答仍在检索整理/)
})