✨ feat(core): 实现回收站条目展示逻辑及UI组件
* 新增 TrashItemInfo 组件以优化回收站列表项展示 * 封装 trashPresentation 工具类处理时间显示逻辑 * 调整 TrashView 布局,重构列表项渲染逻辑 * 新增回收站功能相关的集成测试与单元测试 * 更新测试文档以说明回收站日期格式化测试规则 * 更新 package.json 依赖配置
This commit is contained in:
1 parent
af009cf3c5
commit
614b9a2104
7 files changed
+243
-14
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { getTrashPresentation, formatTrashTime } from '../src/utils/trashPresentation.ts'
|
||||
const now = new Date('2026-09-16T12:00:00+08:00').getTime()
|
||||
const day = 86400000
|
||||
const item = { id: 1, code: 'ABCD1234', size: 100, trashReason: 'manual' }
|
||||
const present = (patch = {}) => getTrashPresentation({ ...item, ...patch }, now)
|
||||
const expiry = days => new Date(now + days * day).toISOString()
|
||||
|
||||
test('normal retention shows date without duplicate countdown', () => {
|
||||
const p = present({ trashExpiresAt: expiry(27.3) })
|
||||
assert.equal(p.reminder, '')
|
||||
assert.equal(p.state, '可恢复')
|
||||
assert.equal(p.reason, '手动删除')
|
||||
assert.equal(p.tone, 'normal')
|
||||
})
|
||||
test('three-day boundary, under-one-day and elapsed deadline are distinct', () => {
|
||||
assert.equal(present({ trashExpiresAt: expiry(3) }).tone, 'warning')
|
||||
assert.equal(present({ trashExpiresAt: expiry(3.01) }).tone, 'normal')
|
||||
assert.equal(present({ trashExpiresAt: expiry(1) }).reminder, '即将清理')
|
||||
assert.equal(present({ trashExpiresAt: expiry(0.1) }).reminder, '即将清理')
|
||||
assert.equal(present({ trashExpiresAt: expiry(0) }).reminder, '等待清理')
|
||||
assert.equal(present({ trashExpiresAt: expiry(-1) }).state, '可恢复')
|
||||
})
|
||||
test('purged records take priority over permanent and stale expiry', () => {
|
||||
const p = present({ isTrashPurged: true, isTrashPermanent: true, trashExpiresAt: expiry(2), trashPurgedAt: expiry(-1) })
|
||||
assert.equal(p.state, '已清理')
|
||||
assert.equal(p.tone, 'muted')
|
||||
assert.equal(p.timeLabel, '清理时间')
|
||||
assert.equal(p.reminder, '')
|
||||
assert.match(p.note, /不可恢复/)
|
||||
})
|
||||
test('permanent records do not show a countdown', () => {
|
||||
const p = present({ isTrashPermanent: true })
|
||||
assert.equal(p.state, '永久保留')
|
||||
assert.equal(p.reminder, '')
|
||||
assert.equal(p.timeText, '不自动清理')
|
||||
})
|
||||
test('missing and invalid deadlines never imply permanent retention or NaN dates', () => {
|
||||
for (const trashExpiresAt of [undefined, null, '', 'invalid']) {
|
||||
const p = present({ trashExpiresAt })
|
||||
assert.equal(p.timeText, '待确认')
|
||||
assert.equal(p.reminder, '')
|
||||
}
|
||||
for (const date of [undefined, null, '', 'invalid']) assert.equal(formatTrashTime(date), '未记录')
|
||||
assert.match(formatTrashTime('2026-09-14T16:51:32'), /2026-09-14 16:51:32/)
|
||||
})
|
||||
test('expiry reason does not claim that count exhaustion was a manual deletion', () => {
|
||||
assert.equal(present({ trashReason: 'expired' }).reason, '已过期或次数用尽')
|
||||
assert.equal(present({ trashReason: 'unexpected' }).reason, '其他原因')
|
||||
assert.equal(present({ trashReason: null }).reason, '未记录')
|
||||
})
|
||||
|
||||
test('relative time uses seven days inclusively in both directions', () => {
|
||||
assert.equal(formatTrashTime(expiry(-2), now), '2 天前')
|
||||
assert.equal(formatTrashTime(expiry(3), now), '3 天后')
|
||||
assert.equal(formatTrashTime(expiry(-7), now), '7 天前')
|
||||
assert.equal(formatTrashTime(expiry(7), now), '7 天后')
|
||||
assert.match(formatTrashTime(expiry(-7.01), now), /^2026-/)
|
||||
assert.match(formatTrashTime(expiry(7.01), now), /^2026-/)
|
||||
})
|
||||
test('relative times handle hours, minutes and immediate deadlines', () => {
|
||||
assert.equal(formatTrashTime(new Date(now - 2 * 3600000).toISOString(), now), '2 小时前')
|
||||
assert.equal(formatTrashTime(new Date(now + 30 * 60000).toISOString(), now), '30 分钟后')
|
||||
assert.equal(formatTrashTime(new Date(now - 1000).toISOString(), now), '刚刚')
|
||||
assert.equal(formatTrashTime(new Date(now + 1000).toISOString(), now), '即将到达')
|
||||
})
|
||||
Reference in new issue
Block a user