Files
X-Financial/web/tests/workbench-composer-date.test.mjs
caoxiaozhu ee730aa31c feat(web): AI 工作台文件预览/附件关联任务与草稿分支
- 新增 WorkbenchAiFilePreviewDialog 附件预览对话框及 useWorkbenchAiFilePreview,附件支持点击预览
- 新增 attachmentAssociationJobs/linkedReimbursementDraftJobs 前端服务与对应 composable,接入后台任务轮询与状态展示
- 新增 travelReimbursementDraftBranchModel 草稿分支模型,报销关联门控支持跳过/选择草稿
- PersonalWorkbenchAiMode 及各 composable(expense/document/steward/application-preview/attachment-association)重构适配,WorkbenchAiComposer/FileStrip 样式与交互完善
- DocumentsCenter/ReceiptFolder/TravelReimbursementCreate 等视图及 scripts 重构,风险/差旅规划/审批等工具适配
- 新增/更新前端测试:application-result-card、reimbursement-list-preview-fetch、guided-flow、composer-components 等
2026-06-24 10:42:50 +08:00

112 lines
4.2 KiB
JavaScript
Raw Permalink 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 { ref } from 'vue'
import { useWorkbenchComposerDate } from '../src/composables/useWorkbenchComposerDate.js'
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 workbenchDateStyles = readFileSync(
fileURLToPath(new URL('../src/assets/styles/components/personal-workbench-composer-date.css', import.meta.url)),
'utf8'
)
test('traditional workbench no longer renders the old composer date picker', () => {
assert.doesNotMatch(workbench, /aria-label="上传附件"[\s\S]*class="workbench-date-anchor"/)
assert.doesNotMatch(workbench, /aria-label="选择日期"/)
assert.doesNotMatch(workbench, /class="workbench-date-chip"/)
assert.doesNotMatch(workbench, /removeWorkbenchDateTag/)
assert.doesNotMatch(workbench, /composer-date-popover/)
assert.doesNotMatch(workbench, /setWorkbenchDateMode\('single'\)/)
assert.doesNotMatch(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/)
})
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)
})
test('workbench range end date changes keep the picker open until the user confirms', () => {
const draft = ref('')
let focusCount = 0
const dateRuntime = useWorkbenchComposerDate({
draft,
focusInput: () => {
focusCount += 1
}
})
dateRuntime.workbenchDatePickerOpen.value = true
dateRuntime.workbenchDateMode.value = 'range'
dateRuntime.workbenchRangeStartDate.value = '2026-02-20'
dateRuntime.workbenchRangeEndDate.value = '2026-03-23'
dateRuntime.handleWorkbenchDateInputChange('range-end')
assert.equal(dateRuntime.workbenchDatePickerOpen.value, true)
assert.equal(dateRuntime.workbenchDateTagLabel.value, '')
assert.equal(draft.value, '')
assert.equal(focusCount, 0)
dateRuntime.applyWorkbenchDateSelection()
assert.equal(dateRuntime.workbenchDatePickerOpen.value, false)
assert.equal(dateRuntime.workbenchDateTagLabel.value, '2026-02-20 至 2026-03-23')
assert.equal(draft.value, '')
assert.equal(dateRuntime.buildWorkbenchPromptText(), '2026-02-20 至 2026-03-23')
assert.equal(focusCount, 1)
})