✨ feat: 完善文件状态、取件记录与表格交互

* 支持当前页下载状态的手动和定时检测,仅显示标签与检测时间
* 区分查件时间和下载点击时间,保留重复查件前的取件时间
* 将查件事件按时间并入现有取件记录,共用展开与收起
* 统一表头居中,支持拖拽和键盘调整列宽并限制最小宽度
* 修复筛选面板收起结束时顶部间距突然消失的顿挫
* 补充单元、集成与浏览器验证,覆盖查询下载、列宽和动画行为
This commit is contained in:
orion committed 2026-09-19 00:35:55 +08:00
1 parent 272741ee49
commit 4fefcd0f0a
29 files changed
+765 -41

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
import { test, before, after } from 'node:test'
import assert from 'node:assert/strict'
import { effectScope, ref, nextTick } from 'vue'
import { createServer } from 'vite'
let server, create, service, config
before(async () => {
server = await createServer({ server: { middlewareMode: true, watch: null }, appType: 'custom' })
create = (await server.ssrLoadModule('/src/composables/useDownloadChecks.ts')).useDownloadChecks
const exports = await server.ssrLoadModule('/src/services/index.ts')
service = exports.DownloadCheckService; config = exports.ConfigService
})
after(async () => await server?.close())
const ok = ids => ({ code: 200, detail: ids.map(id => ({id, status: 'available', message: 'ok', checkedAt: '2026-09-18T00:00:00Z'})) })
test('refresh batches large pages, preserves list on failure, and retries', async () => {
const scope = effectScope(), files = ref(Array.from({length: 45}, (_, i) => ({id: i + 1})))
const flow = scope.run(() => create(files)), original = service.check, batches = []
try {
service.check = async ids => { batches.push(ids.length); if (ids[0] === 21) throw Error('offline'); return ok(ids) }
await flow.refresh()
assert.deepEqual(batches, [20,20,5]); assert.equal(files.value.length, 45)
assert.equal(flow.statusFor(1).status, 'available'); assert.equal(flow.statusFor(21).status, 'unknown')
service.check = async ids => ok(ids); await flow.refresh()
assert.equal(flow.statusFor(21).status, 'available')
} finally { scope.stop(); service.check = original }
})
test('navigation cancels old checks and stale responses cannot change current page', async () => {
const scope = effectScope(), files = ref([{id: 1}]), flow = scope.run(() => create(files))
const original = service.check, pending = new Map(), signals = []
service.check = (ids, signal) => { signals.push(signal); return new Promise(resolve => pending.set(ids[0], resolve)) }
try {
const first = flow.refresh(); files.value = [{id: 2}]; await nextTick()
assert.equal(signals[0].aborted, true)
pending.get(2)(ok([2])); await new Promise(resolve => setImmediate(resolve))
pending.get(1)(ok([1])); await first
assert.deepEqual(Object.keys(flow.checks.value), ['2'])
assert.equal(flow.statusFor(2).status, 'available')
} finally { scope.stop(); service.check = original }
})
test('interval settings persist, save failures retain old value, manual refresh works with timer off', async () => {
const scope = effectScope(), flow = scope.run(() => create(ref([{id: 1}])))
const oldGet = config.getConfig, oldSave = config.updateConfig, oldCheck = service.check
try {
config.getConfig = async () => ({code: 200, detail: {downloadCheckInterval: 60}})
await flow.loadInterval(); assert.equal(flow.interval.value, 60)
config.updateConfig = async data => {assert.equal(data.downloadCheckInterval, 0); return {code:200}}
await flow.saveInterval(0); assert.equal(flow.interval.value, 0)
config.updateConfig = async () => {throw Error('offline')}
await flow.saveInterval(300); assert.equal(flow.interval.value, 0); assert.ok(flow.error.value)
service.check = async ids => ok(ids); await flow.refresh(); assert.equal(flow.statusFor(1).status,'available')
} finally {scope.stop();config.getConfig=oldGet;config.updateConfig=oldSave;service.check=oldCheck}
})
test('automatic timer refreshes and stops after scope disposal', async t => {
const scope=effectScope(), flow=scope.run(()=>create(ref([{id:1}]))), original=service.check
let calls=0
t.mock.timers.enable({apis:['setTimeout']})
try {
service.check=async ids=>{calls++;return ok(ids)}
await flow.refresh(); assert.equal(calls,1)
t.mock.timers.tick(300000); await new Promise(resolve=>setImmediate(resolve));assert.equal(calls,2)
scope.stop();t.mock.timers.tick(300000);assert.equal(calls,2)
} finally {scope.stop();service.check=original;t.mock.timers.reset()}
})
test('status component renders all states and the last checked time', async () => {
const {createSSRApp}=await import('vue'), {renderToString}=await import('vue/server-renderer')
const Component=(await server.ssrLoadModule('/src/components/manage/DownloadCheckStatus.vue')).default
for (const [status,label] of Object.entries({available:'可下载',unavailable:'不可下载',unknown:'未检测',checking:'检测中'})) {
const html=await renderToString(createSSRApp(Component,{result:{id:1,status,message:'reason',checkedAt:'2026-09-18T00:00:00Z'},dark:false}))
assert.ok(html.includes(label));assert.ok(!html.includes('reason'));assert.ok(html.includes('2026'))
}
})