67223f8950
- F9 新增 useTablePaging composable 并接入 7 个工具页"匹配结果"表(只切渲染窗口, 不加选择语义;每页 100 条)+ 深色分页样式 - F6 历史任务抽屉渲染截断(默认 50 条 + "显示全部/收起"),全选口径改为当前可见条目 - F5 新增 task-progress-polling 适配器:等待任务终态的紧循环走 /tasks/progress/light, 异常或空响应回退重型 batch;已接入跟价/定时匹配的 waitForTaskTerminal - F12 背景图 bg.jpg 251KB → 166KB(1920 宽 + quality 80,image-set 仍优先 webp) - G3 抽出共享纯逻辑 task-queue-state(开始时间表序列化校验 + 记录缺失错误判定), 5 个工具页删除逐字重复实现 - 新增 4 个单测文件(分页切片/历史截断/轻量轮询归一/任务队列纯逻辑)
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { HISTORY_VISIBLE_LIMIT, sliceHistoryItems } from '../src/shared/utils/history-paging.ts'
|
|
|
|
test('未超上限时全量渲染且不显示展开入口', () => {
|
|
const items = Array.from({ length: 10 }, (_, i) => ({ key: `k${i}` }))
|
|
|
|
const slice = sliceHistoryItems(items, false)
|
|
|
|
assert.equal(slice.visible.length, 10)
|
|
assert.equal(slice.hiddenCount, 0)
|
|
assert.equal(slice.capped, false)
|
|
})
|
|
|
|
test('超过上限时只渲染前 N 条并给出剩余条数', () => {
|
|
const items = Array.from({ length: HISTORY_VISIBLE_LIMIT + 7 }, (_, i) => ({ key: `k${i}` }))
|
|
|
|
const slice = sliceHistoryItems(items, false)
|
|
|
|
assert.equal(slice.visible.length, HISTORY_VISIBLE_LIMIT)
|
|
assert.equal(slice.hiddenCount, 7)
|
|
assert.equal(slice.capped, true)
|
|
assert.equal(slice.visible[0].key, 'k0')
|
|
assert.equal(slice.visible.at(-1)?.key, `k${HISTORY_VISIBLE_LIMIT - 1}`)
|
|
})
|
|
|
|
test('展开全部后不再截断', () => {
|
|
const items = Array.from({ length: HISTORY_VISIBLE_LIMIT + 3 }, (_, i) => ({ key: `k${i}` }))
|
|
|
|
const slice = sliceHistoryItems(items, true)
|
|
|
|
assert.equal(slice.visible.length, items.length)
|
|
assert.equal(slice.hiddenCount, 0)
|
|
assert.equal(slice.capped, false)
|
|
})
|
|
|
|
test('恰好等于上限时不算截断', () => {
|
|
const items = Array.from({ length: HISTORY_VISIBLE_LIMIT }, (_, i) => ({ key: `k${i}` }))
|
|
|
|
const slice = sliceHistoryItems(items, false)
|
|
|
|
assert.equal(slice.capped, false)
|
|
assert.equal(slice.visible.length, HISTORY_VISIBLE_LIMIT)
|
|
})
|
|
|
|
test('空值与非法上限安全降级', () => {
|
|
assert.deepEqual(sliceHistoryItems(null, false), { visible: [], hiddenCount: 0, capped: false })
|
|
assert.deepEqual(sliceHistoryItems(undefined, false), { visible: [], hiddenCount: 0, capped: false })
|
|
assert.deepEqual(sliceHistoryItems([], false), { visible: [], hiddenCount: 0, capped: false })
|
|
|
|
const items = [{ key: 'a' }, { key: 'b' }]
|
|
const slice = sliceHistoryItems(items, false, 0)
|
|
assert.equal(slice.visible.length, 2, '非法上限回退到默认上限')
|
|
assert.equal(slice.capped, false)
|
|
})
|
|
|
|
test('自定义上限生效', () => {
|
|
const items = Array.from({ length: 5 }, (_, i) => i)
|
|
|
|
const slice = sliceHistoryItems(items, false, 2)
|
|
|
|
assert.deepEqual(slice.visible, [0, 1])
|
|
assert.equal(slice.hiddenCount, 3)
|
|
})
|