diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index b2c328f..fa43082 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -661,3 +661,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成业务测试覆盖切片“AMap 脚本加载错误边界” | 新增高德脚本首次注入、已有脚本节点、加载完成但对象缺失、脚本错误和超时测试;通过 jsdom 与动态模块隔离验证加载器生命周期,不访问真实地图网络;前端测试、类型和注释门禁通过 | 下一步:补齐业务 Hook 的未覆盖错误分支 | | 2026-08-15 | 完成业务测试覆盖切片“请求层方法与取消/错误边界” | 新增 PUT/DELETE 请求、纯文本错误、损坏 JSON 错误体、外部 AbortSignal 及上传取消测试;验证统一错误消息、认证失败通知和超时/取消区分;前端请求测试、类型和注释门禁通过,纯 UI 组件不纳入覆盖率目标 | 下一步:补齐业务 Hook 的未覆盖错误分支 | | 2026-08-15 | 完成业务测试覆盖切片“请求层网络异常与上传载荷” | 补充普通请求/上传请求网络异常透传、上传失败响应和原始错误载荷保留测试;覆盖请求层非业务网络分支,不依赖真实服务;前端请求测试、类型和注释门禁通过 | 下一步:补齐业务 Hook 的未覆盖错误分支 | +| 2026-08-15 | 完成业务测试覆盖切片“账号自动化 Hook 失败与重试” | 补充任务设置读取失败、任务执行失败和失败重试测试,覆盖业务错误提示、重试动作和状态清理;不触发真实账号任务;前端 Hook 测试、类型和注释门禁通过 | 下一步:补齐 Accounts/Items/Notifications 等 Hook 的未覆盖错误分支 | diff --git a/frontend/app/features/accountAutomation/hooks.test.tsx b/frontend/app/features/accountAutomation/hooks.test.tsx index 84d42fe..9348dbe 100644 --- a/frontend/app/features/accountAutomation/hooks.test.tsx +++ b/frontend/app/features/accountAutomation/hooks.test.tsx @@ -102,4 +102,37 @@ describe('useAccountAutomation', /* 当前回调处理账号任务 Hook 的请 ); expect(runTaskMock).not.toHaveBeenCalled(); }); + + test('加载设置失败时展示业务错误', /* 当前回调验证首次读取失败分支。 */ async () => { + getSettingsMock.mockRejectedValueOnce(new Error('读取失败')); + // hook 是读取失败场景下的账号任务 Hook 渲染结果。 + const hook = renderHook(renderAutomationHook); + await waitFor( + // loadingAssertion 等待读取失败状态完成。 + () => expect(hook.result.current.loading).toBe(false), + ); + expect(hook.result.current.error).toBe('读取失败'); + }); + + test('执行失败后可通过 retry 重试', /* 当前回调验证执行失败与重试动作。 */ async () => { + // hook 是执行失败场景下的账号任务 Hook 渲染结果。 + const hook = renderHook(renderAutomationHook); + await waitFor( + // loadingAssertion 等待首次设置请求完成。 + () => expect(hook.result.current.loading).toBe(false), + ); + runTaskMock.mockRejectedValueOnce(new Error('执行失败')); + await act( + // runAction 执行预期失败的账号任务。 + async () => hook.result.current.run('auto_rate'), + ); + expect(hook.result.current.error).toBe('执行失败'); + expect(hook.result.current.retryAvailable).toBe(true); + await act( + // retryAction 触发最近一次执行动作的重试。 + async () => hook.result.current.retry(), + ); + expect(runTaskMock).toHaveBeenCalledTimes(2); + expect(hook.result.current.error).toBe(''); + }); });