From 4731c9a23c3510652758e69c8d32d0640dd811fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Sat, 5 Sep 2026 17:32:48 +0800 Subject: [PATCH] =?UTF-8?q?task-125(=E8=AE=B0=E5=BD=95=E4=B8=8E=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=AD=E5=BF=83):=20=E5=AE=9E=E7=8E=B0=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=B0=E5=BD=95=E7=A9=BA/=E9=94=99=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 history-feedback.ts:历史空态文案与错误归一。 TDD: task-125.test.ts 8 用例 RED→GREEN。 --- .../src/pages/records/history-feedback.ts | 13 ++++++ admin-frontend-vue/tests/task-125.test.ts | 46 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 admin-frontend-vue/src/pages/records/history-feedback.ts create mode 100644 admin-frontend-vue/tests/task-125.test.ts diff --git a/admin-frontend-vue/src/pages/records/history-feedback.ts b/admin-frontend-vue/src/pages/records/history-feedback.ts new file mode 100644 index 00000000..7e8b9ab7 --- /dev/null +++ b/admin-frontend-vue/src/pages/records/history-feedback.ts @@ -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() || '加载失败,请稍后重试' +} diff --git a/admin-frontend-vue/tests/task-125.test.ts b/admin-frontend-vue/tests/task-125.test.ts new file mode 100644 index 00000000..760606d8 --- /dev/null +++ b/admin-frontend-vue/tests/task-125.test.ts @@ -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, '反馈模块保持纯逻辑') +})