Files
crawler-plugin/admin-frontend-vue/tests/task-125.test.ts
T
huangzd1997 4731c9a23c task-125(记录与版本中心): 实现历史记录空/错状态
新增 history-feedback.ts:历史空态文案与错误归一。

TDD: task-125.test.ts 8 用例 RED→GREEN。
2026-09-05 17:32:48 +08:00

47 lines
2.0 KiB
TypeScript

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, '反馈模块保持纯逻辑')
})