30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { formatBjTime } from './datetime';
|
|
|
|
// 北京时间渲染曾是反复出现的问题(微信Bot时间错乱、Token驾驶舱时间列不正确等)。
|
|
// 该测试固化「后端按北京时间存储、前端显式按 Asia/Shanghai 渲染」的契约。
|
|
describe('formatBjTime', () => {
|
|
it('空输入返回占位符 -', () => {
|
|
expect(formatBjTime(undefined)).toBe('-');
|
|
expect(formatBjTime(null)).toBe('-');
|
|
expect(formatBjTime('')).toBe('-');
|
|
});
|
|
|
|
it('无时区标记的时间戳按 Asia/Shanghai (+08:00) 渲染', () => {
|
|
// 2026-07-18T12:00:00 视为北京时间,渲染应含 12:00:00
|
|
const out = formatBjTime('2026-07-18T12:00:00');
|
|
expect(out).toContain('2026');
|
|
expect(out).toContain('12:00:00');
|
|
});
|
|
|
|
it('UTC(Z) 时间戳正确转换为北京时间 (+8)', () => {
|
|
// 2026-07-18T04:00:00Z = 北京时间 12:00:00
|
|
const out = formatBjTime('2026-07-18T04:00:00Z');
|
|
expect(out).toContain('12:00:00');
|
|
});
|
|
|
|
it('非法日期原样返回', () => {
|
|
expect(formatBjTime('not-a-date')).toBe('not-a-date');
|
|
});
|
|
});
|