task-125(记录与版本中心): 实现历史记录空/错状态

新增 history-feedback.ts:历史空态文案与错误归一。

TDD: task-125.test.ts 8 用例 RED→GREEN。
This commit is contained in:
2026-09-05 17:32:48 +08:00
parent d8950e93da
commit 4731c9a23c
2 changed files with 59 additions and 0 deletions
@@ -0,0 +1,13 @@
/** 历史记录列表空/错误反馈(任务 125):空态文案与请求错误归一;纯逻辑。 */
import { requestErrorMessage } from '../../api/envelope.ts'
export function historyEmptyText(input: { hasFilter: boolean; total: number }): string {
if (typeof input.total === 'number' && input.total > 0) return ''
return input.hasFilter ? '暂无符合条件的生成记录,请调整筛选条件' : '暂无生成记录'
}
/** 请求失败归一为可展示文案,空则回兜底。 */
export function historyErrorText(error: unknown): string {
const message = requestErrorMessage(error)
return message.trim() || '加载失败,请稍后重试'
}
+46
View File
@@ -0,0 +1,46 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { historyEmptyText, historyErrorText } from '../src/pages/records/history-feedback.ts'
test('test_task_125_history_feedback_normal_primary_path', () => {
// 正常主路径:无数据且有筛选给提示。
assert.equal(historyEmptyText({ hasFilter: true, total: 0 }), '暂无符合条件的生成记录,请调整筛选条件')
})
test('test_task_125_history_feedback_normal_variant_input', () => {
// 正常变体:无筛选空态。
assert.equal(historyEmptyText({ hasFilter: false, total: 0 }), '暂无生成记录')
})
test('test_task_125_history_feedback_repeated_is_idempotent', () => {
// 正常重复:文案稳定。
assert.equal(historyEmptyText({ hasFilter: false, total: 0 }), historyEmptyText({ hasFilter: false, total: 0 }))
})
test('test_task_125_history_feedback_boundary_empty_input', () => {
// 边界空值:有数据不显示空态。
assert.equal(historyEmptyText({ hasFilter: false, total: 2 }), '')
})
test('test_task_125_history_feedback_boundary_single_item', () => {
// 边界单元素:错误对象取 message。
assert.equal(historyErrorText({ message: '无权访问生成记录模块' }), '无权访问生成记录模块')
})
test('test_task_125_history_feedback_boundary_limit_or_missing_field', () => {
// 边界上限/缺字段:空错误回兜底。
const fallback = historyErrorText(undefined)
assert.ok(fallback.length > 0)
})
test('test_task_125_history_feedback_invalid_input_rejected', () => {
// 异常输入:Error 归一。
assert.match(historyErrorText(new Error('网络异常')), /网络异常/)
})
test('test_task_125_history_feedback_dependency_failure_returns_actionable_message', () => {
// 依赖失败/可操作:反馈纯逻辑、无框架/http。
const mod = readSource('src/pages/records/history-feedback.ts')
assert.equal(/axios|http\.|vue/.test(mod), false, '反馈模块保持纯逻辑')
})