✨ 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

+2
View File
@@ -5,6 +5,8 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"test:trash": "node --experimental-strip-types --test tests/trashPresentation.test.mjs tests/trashPresentation.integration.test.mjs",
"test:trash:coverage": "node --experimental-strip-types --test --experimental-test-coverage --test-coverage-include=src/utils/trashPresentation.ts tests/trashPresentation.test.mjs",
"test:motion": "node --experimental-strip-types --test tests/detailMotion.test.mjs", "test:motion": "node --experimental-strip-types --test tests/detailMotion.test.mjs",
"test:motion:coverage": "node --experimental-strip-types --test --experimental-test-coverage --test-coverage-include=src/utils/detailMotion.ts tests/detailMotion.test.mjs", "test:motion:coverage": "node --experimental-strip-types --test --experimental-test-coverage --test-coverage-include=src/utils/detailMotion.ts tests/detailMotion.test.mjs",
"build": "run-s check:architecture type-check build-only", "build": "run-s check:architecture type-check build-only",
+69
View File
@@ -0,0 +1,69 @@
<template>
<div class="trash-item-info min-w-0" :class="{ 'trash-item-info--dark': isDarkMode }">
<div class="flex min-w-0 items-start gap-3">
<div class="trash-file-icon flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl" :class="`trash-tone-${info.tone}`">
<component :is="item.isTrashPurged ? FileX2Icon : item.text != null ? FileTextIcon : FileIcon" class="h-5 w-5" aria-hidden="true" />
</div>
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-center gap-x-2.5 gap-y-1.5">
<p class="trash-file-name min-w-0 text-sm font-semibold leading-6 sm:text-base">{{ name }}</p>
<span class="trash-state shrink-0 rounded-full border px-2.5 py-0.5 text-xs font-medium" :class="`trash-tone-${info.tone}`">{{ info.state }}</span>
</div>
<dl class="trash-file-meta mt-2 flex flex-wrap gap-x-5 gap-y-2 text-xs leading-5">
<div class="flex flex-wrap gap-x-1.5"><dt>原取件码</dt><dd class="font-mono font-medium tracking-wide">{{ item.code || '未记录' }}</dd></div>
<div class="flex gap-x-1.5"><dt>文件大小</dt><dd>{{ sizeText }}</dd></div>
<div class="flex flex-wrap gap-x-1.5"><dt>移入原因</dt><dd>{{ info.reason }}</dd></div>
</dl>
</div>
</div>
<div class="trash-time-panel mt-3 rounded-2xl border px-3 py-2.5 sm:ml-14">
<dl class="grid min-w-0 gap-3 text-xs sm:grid-cols-2">
<div class="min-w-0">
<dt class="trash-time-label flex items-center gap-1.5"><Clock3Icon class="h-3.5 w-3.5" aria-hidden="true" />移入时间</dt>
<dd class="mt-1.5 font-medium tabular-nums"><time :datetime="item.trashedAt || undefined" :title="formatTrashTime(item.trashedAt)">{{ formatTrashTime(item.trashedAt, now) }}</time></dd>
</div>
<div class="min-w-0">
<dt class="trash-time-label flex items-center gap-1.5"><CalendarClockIcon class="h-3.5 w-3.5" aria-hidden="true" />{{ info.timeLabel }}</dt>
<dd class="mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-1 font-medium tabular-nums">
<span :title="item.isTrashPermanent && !item.isTrashPurged ? undefined : formatTrashTime(item.isTrashPurged ? item.trashPurgedAt : item.trashExpiresAt)">{{ info.timeText }}</span>
<span v-if="info.reminder" class="trash-remaining rounded-full px-2 py-0.5 text-[11px]" :class="`trash-tone-${info.tone}`">{{ info.reminder }}</span>
</dd>
</div>
</dl>
<p v-if="info.note" class="trash-time-label mt-2 text-xs leading-5">{{ info.note }}</p>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { CalendarClockIcon, Clock3Icon, FileIcon, FileTextIcon, FileX2Icon } from 'lucide-vue-next'
import type { TrashFileItem } from '@/types'
import { formatFileSize } from '@/utils/common'
import { formatTrashTime, getTrashPresentation } from '@/utils/trashPresentation'
const props = defineProps<{ item: TrashFileItem; isDarkMode: boolean; now: number }>()
const info = computed(() => getTrashPresentation(props.item, props.now))
const name = computed(() => props.item.name || `${props.item.prefix || ''}${props.item.suffix || ''}` || '未命名文件')
const sizeText = computed(() => {
const size = Number(props.item.size)
return Number.isFinite(size) && size >= 0 ? formatFileSize(size, 1) : '未记录'
})
</script>
<style scoped>
.trash-item-info { color: #294851; --trash-muted: #617980; --trash-line: #d7e3e5; --trash-surface: #edf3f6; }
.trash-item-info--dark { color: #dbe9ee; --trash-muted: #a9bdc2; --trash-line: #40545c; --trash-surface: #26383f; }
.trash-file-name { overflow-wrap: anywhere; }
.trash-file-meta dt, .trash-time-label { color: var(--trash-muted); }
.trash-time-panel { background: var(--trash-surface); border-color: var(--trash-line); }
.trash-state { border-color: var(--trash-line); }
.trash-tone-normal { background: #e4f0ed; color: #355e56; }
.trash-tone-warning { background: #fff0d8; color: #885512; }
.trash-tone-permanent { background: #eeebf8; color: #62528e; }
.trash-tone-muted { background: #e8edef; color: #596b73; }
.trash-item-info--dark .trash-tone-normal { background: #29473f; color: #c0e5d8; }
.trash-item-info--dark .trash-tone-warning { background: #514026; color: #f5d599; }
.trash-item-info--dark .trash-tone-permanent { background: #3e3556; color: #ddd2f6; }
.trash-item-info--dark .trash-tone-muted { background: #344249; color: #bbc9cf; }
</style>
+44
View File
@@ -0,0 +1,44 @@
import type { TrashFileItem } from '../types/trash'
const parseTime = (value?: string | null) => value ? new Date(value).getTime() : NaN
export function formatTrashTime(value?: string | null, now?: number): string {
const timestamp = parseTime(value)
if (!Number.isFinite(timestamp)) return '未记录'
const delta = now === undefined ? Infinity : timestamp - now
const distance = Math.abs(delta)
if (distance <= 7 * 86400000) {
if (distance < 60000) return delta <= 0 ? '刚刚' : '即将到达'
const unit = distance >= 86400000 ? '天' : distance >= 3600000 ? '小时' : '分钟'
const divisor = distance >= 86400000 ? 86400000 : distance >= 3600000 ? 3600000 : 60000
return `${Math.floor(distance / divisor)} ${unit}${delta < 0 ? '前' : '后'}`
}
const date = new Date(timestamp)
const pad = (n: number) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}
export function getTrashPresentation(item: TrashFileItem, now: number) {
const reason = item.trashReason === 'manual' ? '手动删除'
: item.trashReason === 'expired' ? '已过期或次数用尽'
: item.trashReason ? '其他原因' : '未记录'
if (item.isTrashPurged) return {
state: '已清理', tone: 'muted', reason, reminder: '',
timeLabel: '清理时间', timeText: formatTrashTime(item.trashPurgedAt, now),
note: '文件不可恢复,审计记录和取件历史仍保留。'
}
if (item.isTrashPermanent) return {
state: '永久保留', tone: 'permanent', reason, reminder: '',
timeLabel: '清理计划', timeText: '不自动清理', note: ''
}
const deadline = parseTime(item.trashExpiresAt)
const valid = Number.isFinite(deadline)
const remainingMs = deadline - now
const reminder = !valid || remainingMs > 3 * 86400000 ? '' : remainingMs <= 0 ? '等待清理' : '即将清理'
return {
state: '可恢复', tone: valid && remainingMs <= 3 * 86400000 ? 'warning' : 'normal',
reason, reminder, timeLabel: '自动清理时间',
timeText: valid ? formatTrashTime(item.trashExpiresAt, now) : '待确认',
note: valid && remainingMs <= 0 ? '已到清理时间,等待后台处理。' : ''
}
}
+10 -14
View File
@@ -44,16 +44,11 @@
<article <article
v-for="item in items" v-for="item in items"
:key="item.id" :key="item.id"
class="fcb-interactive-row group grid gap-3 px-4 py-4 sm:grid-cols-[auto_minmax(0,1fr)_auto] sm:items-center sm:px-6" class="fcb-interactive-row group grid gap-3 px-4 py-4 xl:grid-cols-[minmax(0,1fr)_auto] sm:items-center sm:px-6"
:class="isDarkMode ? 'hover:bg-[#253941]/60' : 'hover:bg-[#f2f8f8]'" :class="isDarkMode ? 'hover:bg-[#253941]/60' : 'hover:bg-[#f2f8f8]'"
> >
<div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl" :class="item.isTrashPurged ? (isDarkMode ? 'bg-[#30383c] text-[#aab7ba]' : 'bg-[#edf0f1] text-[#61747a]') : (isDarkMode ? 'bg-amber-950/45 text-amber-300' : 'bg-amber-50 text-amber-700')"><FileX2Icon class="h-5 w-5" /></div> <TrashItemInfo :item="item" :is-dark-mode="isDarkMode" :now="now" />
<div class="min-w-0"> <div class="flex flex-wrap items-center gap-2 sm:pl-14 xl:justify-end xl:pl-0">
<div class="flex flex-wrap items-center gap-2"><p class="break-all text-sm font-semibold" :class="primaryTextClass">{{ fileName(item) }}</p><span class="rounded-full border px-2 py-0.5 text-[11px] font-medium" :class="badgeClass">{{ stateLabel(item) }}</span></div>
<div class="mt-1 flex flex-wrap gap-x-3 gap-y-1 text-xs" :class="mutedTextClass"><span>旧取件码 {{ item.code }}</span><span>{{ formatFileSize(Number(item.size || 0), 1) }}</span><span>移入 {{ formatTimestamp(item.trashedAt || '') }}</span></div>
<p class="mt-1 text-xs" :class="mutedTextClass">{{ expiryLabel(item) }}</p>
</div>
<div class="flex flex-wrap items-center gap-2 sm:justify-end">
<BaseButton v-if="!item.isTrashPurged" size="sm" variant="success" :loading="busyId === item.id && busyAction === 'restore'" @click="restore(item)"><template #icon><RotateCcwIcon class="mr-2 h-4 w-4" /></template>恢复</BaseButton> <BaseButton v-if="!item.isTrashPurged" size="sm" variant="success" :loading="busyId === item.id && busyAction === 'restore'" @click="restore(item)"><template #icon><RotateCcwIcon class="mr-2 h-4 w-4" /></template>恢复</BaseButton>
<BaseButton v-if="!item.isTrashPurged" size="sm" variant="outline" :loading="busyId === item.id && busyAction === 'retention'" @click="makePermanent(item)"><template #icon><InfinityIcon class="mr-2 h-4 w-4" /></template>永久保留</BaseButton> <BaseButton v-if="!item.isTrashPurged" size="sm" variant="outline" :loading="busyId === item.id && busyAction === 'retention'" @click="makePermanent(item)"><template #icon><InfinityIcon class="mr-2 h-4 w-4" /></template>永久保留</BaseButton>
<BaseButton v-if="!item.isTrashPurged" size="sm" variant="danger" :loading="busyId === item.id && busyAction === 'purge'" @click="purge(item)"><template #icon><EraserIcon class="mr-2 h-4 w-4" /></template>物理清理</BaseButton> <BaseButton v-if="!item.isTrashPurged" size="sm" variant="danger" :loading="busyId === item.id && busyAction === 'purge'" @click="purge(item)"><template #icon><EraserIcon class="mr-2 h-4 w-4" /></template>物理清理</BaseButton>
@@ -67,14 +62,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue' import { computed, onMounted, onUnmounted, ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { EraserIcon, FileX2Icon, InfinityIcon, RefreshCwIcon, RotateCcwIcon, Settings2Icon, ShieldCheckIcon, Trash2Icon } from 'lucide-vue-next' import { EraserIcon, InfinityIcon, RefreshCwIcon, RotateCcwIcon, Settings2Icon, ShieldCheckIcon, Trash2Icon } from 'lucide-vue-next'
import BaseButton from '@/components/common/BaseButton.vue' import BaseButton from '@/components/common/BaseButton.vue'
import TrashItemInfo from '@/components/manage/TrashItemInfo.vue'
import DataPagination from '@/components/common/DataPagination.vue' import DataPagination from '@/components/common/DataPagination.vue'
import { useAdminTrash, useInjectedDarkMode } from '@/composables' import { useAdminTrash, useInjectedDarkMode } from '@/composables'
import type { TrashFileItem } from '@/types' import type { TrashFileItem } from '@/types'
import { formatFileSize, formatTimestamp } from '@/utils/common'
const isDarkMode = useInjectedDarkMode() const isDarkMode = useInjectedDarkMode()
const router = useRouter() const router = useRouter()
@@ -87,16 +82,17 @@ const isLoading = ref(false)
const errorText = ref('') const errorText = ref('')
const busyId = ref<number | null>(null) const busyId = ref<number | null>(null)
const busyAction = ref('') const busyAction = ref('')
const now = ref(Date.now())
let clockTimer: ReturnType<typeof setInterval> | undefined
onMounted(() => { clockTimer = setInterval(() => { now.value = Date.now() }, 60_000) })
onUnmounted(() => { clearInterval(clockTimer) })
const primaryTextClass = computed(() => isDarkMode.value ? 'text-white' : 'text-[#1f3c45]') const primaryTextClass = computed(() => isDarkMode.value ? 'text-white' : 'text-[#1f3c45]')
const mutedTextClass = computed(() => isDarkMode.value ? 'text-[#a9bdc2]' : 'text-[#617980]') const mutedTextClass = computed(() => isDarkMode.value ? 'text-[#a9bdc2]' : 'text-[#617980]')
const panelClass = computed(() => isDarkMode.value ? 'border-[#40545c] bg-[#202f36]/90' : 'border-[#d7e3e5] bg-[#f8fbfb]') const panelClass = computed(() => isDarkMode.value ? 'border-[#40545c] bg-[#202f36]/90' : 'border-[#d7e3e5] bg-[#f8fbfb]')
const dividerClass = computed(() => isDarkMode.value ? 'divide-[#40545c] border-[#40545c]' : 'divide-[#d7e3e5] border-[#d7e3e5]') const dividerClass = computed(() => isDarkMode.value ? 'divide-[#40545c] border-[#40545c]' : 'divide-[#d7e3e5] border-[#d7e3e5]')
const badgeClass = computed(() => isDarkMode.value ? 'border-[#50666f] text-[#b8d6de]' : 'border-[#c8d8dc] text-[#4e6c75]')
const recoverableCount = computed(() => items.value.filter(item => !item.isTrashPurged).length) const recoverableCount = computed(() => items.value.filter(item => !item.isTrashPurged).length)
const purgedCount = computed(() => items.value.filter(item => item.isTrashPurged).length) const purgedCount = computed(() => items.value.filter(item => item.isTrashPurged).length)
const fileName = (item: TrashFileItem) => item.name || `${item.prefix || ''}${item.suffix || ''}` || '未命名文件' const fileName = (item: TrashFileItem) => item.name || `${item.prefix || ''}${item.suffix || ''}` || '未命名文件'
const stateLabel = (item: TrashFileItem) => item.isTrashPurged ? '仅审计记录' : item.isTrashPermanent ? '永久保留' : '可恢复'
const expiryLabel = (item: TrashFileItem) => item.isTrashPurged ? `文件本体已于 ${formatTimestamp(item.trashPurgedAt || '')} 清理` : item.isTrashPermanent ? '不会自动清理文件本体' : `预计清理:${formatTimestamp(item.trashExpiresAt || '')}`
const openRetentionSettings = () => { void router.push({ path: '/admin/settings', hash: '#settings-upload' }) } const openRetentionSettings = () => { void router.push({ path: '/admin/settings', hash: '#settings-upload' }) }
const loadTrash = async () => { isLoading.value = true; errorText.value = ''; try { const detail = await fetchTrash({ page: page.value, size: size.value }); items.value = detail?.data || []; total.value = Number(detail?.total || 0) } catch (error: unknown) { errorText.value = (error as { response?: { data?: { detail?: string } } })?.response?.data?.detail || '回收站加载失败,请稍后重试。' } finally { isLoading.value = false } } const loadTrash = async () => { isLoading.value = true; errorText.value = ''; try { const detail = await fetchTrash({ page: page.value, size: size.value }); items.value = detail?.data || []; total.value = Number(detail?.total || 0) } catch (error: unknown) { errorText.value = (error as { response?: { data?: { detail?: string } } })?.response?.data?.detail || '回收站加载失败,请稍后重试。' } finally { isLoading.value = false } }
+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 reversals and final collapsed layout. It only toggles presentation and never
uploads, deletes, restores or changes file data. These checks do not measure uploads, deletes, restores or changes file data. These checks do not measure
whole-project coverage or validate the storage implementation. 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), '即将到达')
})