d8950e93da
新增 history-preview.ts:从历史记录提取结果图/长图并限制数量,避免大内容阻塞。 TDD: task-124.test.ts 8 用例 RED→GREEN。
69 lines
2.7 KiB
TypeScript
69 lines
2.7 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import { buildPreviewDescriptor } from '../src/pages/records/history-preview.ts'
|
|
|
|
function item(over: Record<string, unknown>) {
|
|
return {
|
|
id: 1,
|
|
userId: null,
|
|
username: '',
|
|
createdAt: '',
|
|
panelType: 'x',
|
|
originalUrls: [],
|
|
resultUrls: [],
|
|
longImageUrl: '',
|
|
...over,
|
|
}
|
|
}
|
|
|
|
test('test_task_124_history_preview_normal_primary_path', () => {
|
|
// 正常主路径:预览取结果图与长图。
|
|
const descriptor = buildPreviewDescriptor(item({ resultUrls: ['https://a/1.png', 'http://b/2.png'], longImageUrl: 'https://long.png' }), 10)
|
|
assert.deepEqual(descriptor.images, ['https://a/1.png', 'http://b/2.png', 'https://long.png'])
|
|
})
|
|
|
|
test('test_task_124_history_preview_normal_variant_input', () => {
|
|
// 正常变体:非 http 地址过滤。
|
|
const descriptor = buildPreviewDescriptor(item({ resultUrls: ['ftp://bad', 'https://ok.png'] }), 10)
|
|
assert.deepEqual(descriptor.images, ['https://ok.png'])
|
|
})
|
|
|
|
test('test_task_124_history_preview_repeated_is_idempotent', () => {
|
|
// 正常重复:预览构建稳定、不改记录。
|
|
const record = item({ resultUrls: ['https://a.png'] })
|
|
assert.deepEqual(buildPreviewDescriptor(record, 10), buildPreviewDescriptor(record, 10))
|
|
assert.equal((record as { resultUrls: string[] }).resultUrls.length, 1)
|
|
})
|
|
|
|
test('test_task_124_history_preview_boundary_empty_input', () => {
|
|
// 边界空值:无图预览回空。
|
|
const descriptor = buildPreviewDescriptor(item({}), 10)
|
|
assert.deepEqual(descriptor.images, [])
|
|
})
|
|
|
|
test('test_task_124_history_preview_boundary_single_item', () => {
|
|
// 边界单元素:单图预览。
|
|
const descriptor = buildPreviewDescriptor(item({ resultUrls: ['https://a.png'] }), 10)
|
|
assert.equal(descriptor.images.length, 1)
|
|
})
|
|
|
|
test('test_task_124_history_preview_boundary_limit_or_missing_field', () => {
|
|
// 边界上限:超上限截断。
|
|
const urls = Array.from({ length: 30 }, (_, i) => `https://a/${i}.png`)
|
|
const descriptor = buildPreviewDescriptor(item({ resultUrls: urls }), 10)
|
|
assert.equal(descriptor.images.length, 10)
|
|
})
|
|
|
|
test('test_task_124_history_preview_invalid_input_rejected', () => {
|
|
// 异常输入:空记录预览为空。
|
|
assert.deepEqual(buildPreviewDescriptor(null as never, 10).images, [])
|
|
})
|
|
|
|
test('test_task_124_history_preview_dependency_failure_returns_actionable_message', () => {
|
|
// 依赖失败/可操作:预览纯逻辑、无框架/http;限制长度避免大内容阻塞。
|
|
const mod = readSource('src/pages/records/history-preview.ts')
|
|
assert.equal(/axios|http\.|vue/.test(mod), false, '预览保持纯逻辑')
|
|
assert.match(mod, /limit/)
|
|
})
|