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

100 lines
4.2 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 {
buildWorkbenchDateLabel,
canApplyWorkbenchDateSelection,
getTodayDateValue,
mergeWorkbenchDateLabelIntoDraft,
stripWorkbenchDateLabelFromDraft
} from '../src/utils/workbenchComposerDate.js'
const workbench = readFileSync(
fileURLToPath(new URL('../src/components/business/PersonalWorkbench.vue', import.meta.url)),
'utf8'
)
const workbenchDateComposable = readFileSync(
fileURLToPath(new URL('../src/composables/useWorkbenchComposerDate.js', import.meta.url)),
'utf8'
)
const workbenchStyles = readFileSync(
fileURLToPath(new URL('../src/assets/styles/components/personal-workbench.css', import.meta.url)),
'utf8'
)
const workbenchDateStyles = readFileSync(
fileURLToPath(new URL('../src/assets/styles/components/personal-workbench-composer-date.css', import.meta.url)),
'utf8'
)
const workbenchResponsiveStyles = readFileSync(
fileURLToPath(new URL('../src/assets/styles/components/personal-workbench-responsive.css', import.meta.url)),
'utf8'
)
test('workbench composer renders date picker beside attachment upload', () => {
assert.match(workbench, /aria-label="上传附件"[\s\S]*class="workbench-date-anchor"/)
assert.match(workbench, /aria-label="选择日期"/)
assert.match(workbench, /class="workbench-date-chip"/)
assert.match(workbench, /removeWorkbenchDateTag/)
assert.match(workbench, /composer-date-popover/)
assert.match(workbench, /setWorkbenchDateMode\('single'\)/)
assert.match(workbench, /setWorkbenchDateMode\('range'\)/)
assert.match(workbench, /handleWorkbenchDateInputChange\('single'\)/)
assert.match(workbench, /handleWorkbenchDateInputChange\('range-start'\)/)
assert.match(workbench, /handleWorkbenchDateInputChange\('range-end'\)/)
assert.doesNotMatch(workbench, /@click="applyWorkbenchDateSelection"/)
assert.doesNotMatch(workbench, /插入标签/)
assert.match(workbench, /useWorkbenchComposerDate/)
assert.match(workbenchDateComposable, /const workbenchSingleDate = ref\(getTodayDateValue\(\)\)/)
assert.match(workbenchDateComposable, /const workbenchDateTagLabel = ref\(''\)/)
assert.match(workbenchDateComposable, /const today = getTodayDateValue\(\)[\s\S]*workbenchSingleDate\.value = today/)
assert.match(workbenchDateComposable, /function handleWorkbenchDateInputChange/)
assert.match(workbenchDateStyles, /\.workbench-date-anchor/)
assert.match(workbenchDateStyles, /\.workbench-date-chip/)
assert.match(workbenchDateStyles, /\.composer-date-popover/)
assert.match(workbenchStyles, /\.assistant-composer\s*\{[\s\S]*position:\s*relative/)
assert.match(workbenchDateStyles, /\.composer-date-popover\s*\{[\s\S]*top:\s*calc\(100% \+ 8px\)/)
assert.doesNotMatch(workbenchDateStyles, /bottom:\s*calc\(100%/)
assert.doesNotMatch(workbench, /composer-related-button/)
assert.doesNotMatch(workbenchStyles, /\.composer-related-button/)
assert.doesNotMatch(workbenchDateStyles, /\.composer-related-button/)
assert.doesNotMatch(workbenchResponsiveStyles, /\.composer-related-button/)
})
test('workbench date helper builds labels and inserts them into draft text', () => {
assert.equal(getTodayDateValue(new Date(2026, 4, 9, 12)), '2026-05-09')
assert.equal(
buildWorkbenchDateLabel({
mode: 'single',
singleDate: '2026-05-29'
}),
'2026-05-29'
)
assert.equal(
buildWorkbenchDateLabel({
mode: 'range',
rangeStartDate: '2026-05-29',
rangeEndDate: '2026-05-31'
}),
'2026-05-29 至 2026-05-31'
)
assert.equal(
mergeWorkbenchDateLabelIntoDraft('申请出差', '2026-05-29'),
'2026-05-29申请出差'
)
assert.equal(
mergeWorkbenchDateLabelIntoDraft('发生时间2026-05-28申请出差', '2026-05-29'),
'2026-05-29申请出差'
)
assert.equal(
mergeWorkbenchDateLabelIntoDraft('2026-05-28申请出差', '2026-05-29'),
'2026-05-29申请出差'
)
assert.equal(
stripWorkbenchDateLabelFromDraft('2026-05-28 至 2026-05-30申请出差'),
'申请出差'
)
assert.equal(canApplyWorkbenchDateSelection({ mode: 'range', rangeStartDate: '2026-06-01', rangeEndDate: '2026-05-31' }), false)
})