2026-05-30 15:46:51 +08:00
|
|
|
|
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 workbenchDateStyles = readFileSync(
|
|
|
|
|
|
fileURLToPath(new URL('../src/assets/styles/components/personal-workbench-composer-date.css', import.meta.url)),
|
|
|
|
|
|
'utf8'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-06-18 22:12:24 +08:00
|
|
|
|
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/)
|
2026-05-30 15:46:51 +08:00
|
|
|
|
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)
|
|
|
|
|
|
})
|