cmvr-wms/ruoyi-ui-vue3/tests/unit/date-display.test.mjs

30 lines
1.9 KiB
JavaScript
Raw Normal View History

import test from 'node:test'
import assert from 'node:assert/strict'
import {parseTime} from '../../src/utils/ruoyi.js'
import {formatDateTime,displayTimestamp} from '../../src/utils/display-format.js'
import {assistantDisplayValue} from '../../src/utils/business-assistant.js'
test('local API timestamps display without T, milliseconds or timezone suffixes',()=>{
for(const value of ['2026-10-26T12:01:54','2026-10-26T12:01:54.123456789','2026-10-26 12:01:54','2026/10/26 12:01:54'])assert.equal(formatDateTime(value),'2026-10-26 12:01:54')
assert.equal(formatDateTime('2026-10-26'),'2026-10-26')
assert.equal(parseTime('2026-10-26T12:01:54','{y}-{m}-{d}'),'2026-10-26')
})
test('ISO offsets retain their actual instant while plain dates stay local',()=>{
const instant=Date.UTC(2026,9,26,4,1,54)
const expected=parseTime(new Date(instant))
assert.equal(formatDateTime('2026-10-26T12:01:54.123456+08:00'),expected)
assert.equal(formatDateTime('2026-10-26T04:01:54Z'),expected)
assert.equal(formatDateTime(instant),expected)
assert.equal(formatDateTime(String(instant/1000)),expected)
assert.equal(formatDateTime(0),parseTime(new Date(0)))
assert.equal(formatDateTime('2024-02-29'),'2024-02-29')
})
test('missing and invalid values produce a placeholder instead of NaN or a thrown error',()=>{
for(const value of [null,undefined,'',' ','not a date','2026-02-30','2026-10-26T25:01:54',new Date(NaN),{},[],true,Symbol('invalid')])assert.equal(formatDateTime(value),'—')
})
test('generic query values format complete timestamps without changing business text or numbers',()=>{
assert.equal(assistantDisplayValue({time:'2026-10-26T12:01:54',quantity:12}),'time:2026-10-26 12:01:54;quantity:12')
assert.equal(assistantDisplayValue(['2026-10-26T12:01:54']),'2026-10-26 12:01:54')
for(const value of ['版本T1','文件-2026-10-26T12:01:54.txt','2026-10-26',1000])assert.equal(displayTimestamp(value),value)
})