Files
X-Financial/web/tests/travel-reimbursement-composer-tools.test.mjs
caoxiaozhu 7989f3a159 feat: 新增风险图谱算法与系统仪表盘及操作反馈体系
后端新增风险图谱算法模块、风险观察与反馈服务、规则 DSL
校验器和可解释性引擎,完善系统仪表盘和财务仪表盘统计,
优化 agent 运行和编排执行链路,清理旧开发文档,前端新增
系统趋势、负载热力图等多种仪表盘图表组件,完善操作反馈
对话框和工作台日期选择器,优化报销创建和审批详情交互,
补充单元测试覆盖。
2026-05-30 15:46:51 +08:00

115 lines
4.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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'
)
const createViewTemplate = readFileSync(
fileURLToPath(new URL('../src/views/TravelReimbursementCreateView.vue', import.meta.url)),
'utf8'
)
const composerToolsScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementComposerTools.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 strips raw date picker prefix before building structured display', () => {
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 date selection shows raw date capsule labels', () => {
assert.match(createViewTemplate, /aria-label="选择日期"/)
assert.match(createViewTemplate, /aria-label="日期选择"/)
assert.match(createViewTemplate, /aria-label="移除日期"/)
assert.match(createViewTemplate, /handleComposerDateInputChange\('single'\)/)
assert.match(createViewTemplate, /handleComposerDateInputChange\('range-start'\)/)
assert.match(createViewTemplate, /handleComposerDateInputChange\('range-end'\)/)
assert.doesNotMatch(createViewTemplate, /@click="applyComposerDateSelection"/)
assert.doesNotMatch(createViewTemplate, /aria-label="选择业务发生时间"/)
assert.doesNotMatch(createViewTemplate, /aria-label="移除业务发生时间"/)
assert.doesNotMatch(composerToolsScript, /return `发生时间:\$\{composerSingleDate\.value\}`/)
assert.match(composerToolsScript, /return composerSingleDate\.value/)
assert.match(composerToolsScript, /return `\$\{composerRangeStartDate\.value\} 至 \$\{composerRangeEndDate\.value\}`/)
assert.match(composerToolsScript, /function commitComposerDateSelection/)
assert.match(composerToolsScript, /onComposerDateSelection\?\.\(selection\)/)
})
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, /知识问答仍在检索整理/)
})