✨ 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,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('<script>') && !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('未命名文件'))
|
||||
})
|
||||
Reference in new issue
Block a user