Files
order_site/apps/frontend/tests/deadline-countdown.test.ts
yml2213andCursor 1239393fc2 perf: 筛选统计去掉 JSON 兜底,并补上 orders 覆盖索引
去掉 work_orders 堆访问后,JOIN 会把 orders 整表扫进 Hash Right Join。
领取页在快照新鲜时不再打上游;快手出网统一 10 秒超时。倒计时改为自适应间隔。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 15:05:38 +08:00

36 lines
1.2 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
DEADLINE_FAST_TICK_MS,
DEADLINE_SLOW_TICK_MS,
resolveDeadlineCountdown,
} from '../src/utils/deadline-countdown.ts'
const now = Date.parse('2026-10-01T06:00:00.000Z')
test('deadline under one minute ticks every second and keeps the seconds label', () => {
const view = resolveDeadlineCountdown('2026-10-01T06:00:45.000Z', now)
assert.equal(view.tickMs, DEADLINE_FAST_TICK_MS)
assert.equal(view.label, '剩余 45 秒')
assert.equal(view.color, 'orange')
})
test('deadline over one minute ticks every 30 seconds and hides seconds', () => {
const near = resolveDeadlineCountdown('2026-10-01T06:02:20.000Z', now)
assert.equal(near.tickMs, DEADLINE_SLOW_TICK_MS)
assert.equal(near.label, '剩余 2 分')
assert.equal(near.color, 'orange')
const far = resolveDeadlineCountdown('2026-10-01T06:12:20.000Z', now)
assert.equal(far.label, '剩余 12 分')
assert.equal(far.color, 'blue')
})
test('expired deadline stops the one-second timer', () => {
const view = resolveDeadlineCountdown('2026-10-01T05:59:00.000Z', now)
assert.equal(view.label, '已超时')
assert.equal(view.color, 'red')
assert.equal(view.tickMs, DEADLINE_SLOW_TICK_MS)
})