import test from 'node:test'
|
import assert from 'node:assert/strict'
|
import { readDetectionTimeRange, isCompleteDetectionTimeRange, toDetectionTimePayload } from '../src/utils/detectionTimeRange.js'
|
|
test('历史单日记录以同日范围回显,保存时补齐结束日期', () => {
|
const range = readDetectionTimeRange({ detectionTime: '2026-10-20' })
|
assert.deepEqual(range, ['2026-10-20', '2026-10-20'])
|
assert.equal(isCompleteDetectionTimeRange(range), true)
|
assert.deepEqual(toDetectionTimePayload(range), {
|
detectionTime: '2026-10-20', detectionEndTime: '2026-10-20',
|
})
|
})
|
|
test('跨月范围保存后能完整回显', () => {
|
const range = ['2026-09-30', '2026-10-23']
|
assert.equal(isCompleteDetectionTimeRange(range), true)
|
assert.deepEqual(readDetectionTimeRange(toDetectionTimePayload(range)), range)
|
})
|
|
test('清空范围时同时清空开始和结束日期', () => {
|
assert.deepEqual(toDetectionTimePayload(null), { detectionTime: null, detectionEndTime: null })
|
assert.equal(readDetectionTimeRange(toDetectionTimePayload(null)), null)
|
assert.equal(isCompleteDetectionTimeRange(null), false)
|
})
|
|
test('未选完整范围或结束日期早于开始日期时不能提交', () => {
|
for (const range of [[], ['2026-10-23'], ['2026-10-23', null], ['2026-10-23', '2026-10-20']]) {
|
assert.equal(isCompleteDetectionTimeRange(range), false)
|
}
|
})
|