liding
78 分钟以前 49cdc0884a9a4381cd968cffff65e2a332bc675a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
  }
})