✨ feat(core): 实现回收站条目展示逻辑及UI组件

* 新增 TrashItemInfo 组件以优化回收站列表项展示
* 封装 trashPresentation 工具类处理时间显示逻辑
* 调整 TrashView 布局,重构列表项渲染逻辑
* 新增回收站功能相关的集成测试与单元测试
* 更新测试文档以说明回收站日期格式化测试规则
* 更新 package.json 依赖配置
This commit is contained in:
orion committed 2026-09-16 18:01:23 +08:00
1 parent af009cf3c5
commit 614b9a2104
7 files changed
+243 -14

No files matched your search

+11
View File
@@ -24,3 +24,14 @@ natural height, visible retrieval records, no vertical record transform, rapid
reversals and final collapsed layout. It only toggles presentation and never
uploads, deletes, restores or changes file data. These checks do not measure
whole-project coverage or validate the storage implementation.
## Recycle bin information
- `npm run test:trash`: relative-time boundary tests and Vue SSR integration
checks for normal, urgent, permanent, purged and incomplete records.
- `npm run test:trash:coverage`: coverage of `src/utils/trashPresentation.ts` only.
Seven days is inclusive in both directions; older or more distant dates use
exact local date/time. Relative labels refresh every minute. Native title text
retains the exact date/time. The three-day cleanup warning is independent of
the seven-day formatting boundary. These tests do not modify backend data.
@@ -0,0 +1,40 @@
import { test, before, after } from 'node:test'
import assert from 'node:assert/strict'
import { createServer } from 'vite'
import { createSSRApp, h } from 'vue'
import { renderToString } from 'vue/server-renderer'
let server, Card
before(async () => {
server = await createServer({ server: { middlewareMode: true, watch: null }, appType: 'custom' })
Card = (await server.ssrLoadModule('/src/components/manage/TrashItemInfo.vue')).default
})
after(async () => { await server?.close() })
const now = new Date('2026-09-16T12:00:00+08:00').getTime()
const item = { id: 1, name: 'BNApp64-v3.13.5.apk', code: 'J5B33MHS', size: 327680000, trashReason: 'manual', trashedAt: '2026-09-14T16:51:32', trashExpiresAt: '2026-10-14T16:51:32' }
const render = (patch = {}, dark = false) => renderToString(createSSRApp({ render: () => h(Card, { item: { ...item, ...patch }, isDarkMode: dark, now }) }))
test('recoverable file renders grouped labels, relative and exact dates', async () => {
const html = await render()
for (const label of ['BNApp64-v3.13.5.apk', '可恢复', '原取件码', 'J5B33MHS', '文件大小', '312.5 MB', '移入原因', '手动删除', '移入时间', '2026-09-14 16:51:32', '自动清理时间', '2026-10-14 16:51:32', '1 天前']) assert.ok(html.includes(label), label)
assert.ok(html.includes('<dl'))
})
test('purged and permanent records do not show a misleading countdown', async () => {
const purged = await render({ isTrashPurged: true, trashPurgedAt: '2026-09-15T09:00:00' })
assert.ok(purged.includes('已清理') && purged.includes('文件不可恢复'))
assert.ok(!purged.includes('剩余') && !purged.includes('自动清理时间'))
const permanent = await render({ isTrashPermanent: true })
assert.ok(permanent.includes('永久保留') && permanent.includes('不自动清理'))
assert.ok(!permanent.includes('剩余'))
})
test('urgent status remains readable with explicit text in dark mode', async () => {
const html = await render({ trashExpiresAt: '2026-09-16T15:00:00+08:00', trashReason: 'expired' }, true)
assert.ok(html.includes('trash-item-info--dark') && html.includes('trash-tone-warning'))
assert.ok(html.includes('3 小时后') && html.includes('即将清理') && html.includes('已过期或次数用尽'))
})
test('missing metadata has safe fallbacks and filenames are escaped', async () => {
const html = await render({ name: '<script>alert(1)</script>', code: '', size: -1, trashedAt: null, trashExpiresAt: null })
assert.ok(html.includes('&lt;script&gt;') && !html.includes('<script>'))
assert.ok(html.includes('未记录') && html.includes('待确认'))
assert.ok(!html.includes('NaN'))
const unnamed = await render({ name: '', prefix: '', suffix: '', text: 'text record' })
assert.ok(unnamed.includes('未命名文件'))
})
+67
View File
@@ -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), '即将到达')
})