补齐账号子模块异常登录测试

This commit is contained in:
Christ committed 2026-08-15 11:25:38 +08:00
1 parent f9debf687f
commit c698b4df5e
2 files changed
+63

No files matched your search

@@ -663,3 +663,4 @@ npm --prefix frontend run build
| 2026-08-15 | 完成业务测试覆盖切片“请求层网络异常与上传载荷” | 补充普通请求/上传请求网络异常透传、上传失败响应和原始错误载荷保留测试;覆盖请求层非业务网络分支,不依赖真实服务;前端请求测试、类型和注释门禁通过 | 下一步:补齐业务 Hook 的未覆盖错误分支 |
| 2026-08-15 | 完成业务测试覆盖切片“账号自动化 Hook 失败与重试” | 补充任务设置读取失败、任务执行失败和失败重试测试,覆盖业务错误提示、重试动作和状态清理;不触发真实账号任务;前端 Hook 测试、类型和注释门禁通过 | 下一步:补齐 Accounts/Items/Notifications 等 Hook 的未覆盖错误分支 |
| 2026-08-15 | 完成业务测试覆盖切片“商品批量发布 Hook 异常与轮询” | 补充类目推荐、批量预检、启动、取消、重试、最近结果和预检清理失败测试,并覆盖轮询完成后刷新商品/发货规则列表;使用 API 替身验证状态机,不触发真实商品文件或外部平台;前端 Hook 测试、类型和注释门禁通过 | 下一步:补齐 Accounts 子模块与 Notifications Hook 的未覆盖错误分支 |
| 2026-08-15 | 完成业务测试覆盖切片“账号子模块保存与密码登录异常” | 补充长期登录、AI、账号编辑、暂停保存失败,以及密码登录启动失败和状态查询失败测试;覆盖错误提示、状态收口和重试前置条件,不触发真实账号凭证或平台登录;前端 Hook 测试、类型和注释门禁通过 | 下一步:补齐 Notifications/Chat/Settings 等 Hook 的未覆盖错误分支 |
@@ -133,6 +133,34 @@ describe('useAccountSubmodules', /* 当前回调处理账号编辑、AI、通知
async () => hook.result.current.handleRestartPause(),
);
expect(pauseMock).toHaveBeenCalledWith('account-1', 60);
setLongLoginMock.mockRejectedValueOnce(new Error('长登录保存失败'));
await act(
// longLoginErrorAction 验证长期登录保存失败提示。
async () => hook.result.current.handleLongLoginToggle(),
);
expect(hook.result.current.longLogin.error).toBe('长登录保存失败');
updateAIMock.mockRejectedValueOnce(new Error('AI保存失败'));
await act(
// aiSaveErrorAction 验证 AI 设置保存失败后的状态清理。
async () => hook.result.current.handleSaveAISettings(),
);
expect(hook.result.current.saving).toBe(false);
updateAccountMock.mockRejectedValueOnce(new Error('账号保存失败'));
await act(
// editSaveErrorAction 验证账号编辑保存失败后的状态清理。
async () => hook.result.current.handleSaveEdit(),
);
expect(hook.result.current.saving).toBe(false);
pauseMock.mockRejectedValueOnce(new Error('暂停失败'));
await act(
// pauseErrorAction 验证重新暂停失败后的状态清理。
async () => hook.result.current.handleRestartPause(),
);
expect(hook.result.current.saving).toBe(false);
hook.unmount();
});
@@ -167,6 +195,40 @@ describe('useAccountSubmodules', /* 当前回调处理账号编辑、AI、通知
hook.unmount();
});
test('密码登录启动失败和状态查询失败时展示错误', /* 当前回调验证密码登录的异常状态转换。 */ async () => {
// setEditingAccount 是密码登录异常测试的账号状态替身。
const setEditingAccount = vi.fn();
// setActiveModal 是密码登录异常测试的弹窗状态替身。
const setActiveModal = vi.fn() as unknown as Dispatch<SetStateAction<AccountModalType>>;
// setEditForm 是密码登录异常测试的表单状态替身。
const setEditForm = vi.fn();
// loadAccounts 是密码登录异常测试的列表刷新替身。
const loadAccounts = vi.fn().mockResolvedValue(undefined);
// hook 是密码登录异常场景的 Hook 渲染结果。
const hook = renderHook(
// passwordErrorHookFactory 创建密码登录异常场景的子模块 Hook。
() => useAccountSubmodules({ editingAccount: accountFixture, setEditingAccount, setActiveModal, editForm: editFormFixture, setEditForm, loadAccounts }),
);
passwordLoginMock.mockResolvedValueOnce({ success: false, message: '账号密码错误' });
await act(
// startErrorAction 验证密码登录启动失败状态。
async () => hook.result.current.handlePasswordLogin(),
);
expect(hook.result.current.passwordLoginView.status).toBe('failed');
expect(hook.result.current.passwordLoginView.message).toBe('账号密码错误');
passwordLoginMock.mockResolvedValueOnce({ success: true, session_id: 'session-2', status: 'processing', message: '处理中' });
passwordStatusMock.mockRejectedValueOnce(new Error('状态查询失败'));
await act(
// statusErrorAction 验证密码登录状态查询失败转换。
async () => hook.result.current.handlePasswordLogin(),
);
expect(hook.result.current.passwordLoginView.status).toBe('failed');
expect(hook.result.current.passwordLoginView.message).toBe('状态查询失败');
hook.unmount();
});
test('绑定、长期登录和AI请求失败时保留可恢复状态', /* 当前回调验证账号子模块的失败隔离分支。 */ async () => {
// setEditingAccount 是失败场景的账号状态替身。
const setEditingAccount = vi.fn();