补齐卡密聊天Hook清理滚动测试

This commit is contained in:
Christ committed 2026-08-15 11:34:44 +08:00
1 parent 7af60232e5
commit a2576f288a
3 files changed
+32

No files matched your search

@@ -80,6 +80,17 @@ describe('useCardsData 与 useCardBatchActions', /* 当前回调处理卡密库
);
expect(batchCreateMock).toHaveBeenCalledWith(expect.any(File), expect.objectContaining({ signal: expect.any(AbortSignal) }));
expect(batchHook.result.current.batchResult).toMatchObject({ created: 1 });
await act(
// createRetryAction 重试当前批量创建文件。
async () => batchHook.result.current.handleRetryBatchCreate(),
);
expect(batchCreateMock).toHaveBeenCalledTimes(2);
await act(
// closeAction 关闭批量操作弹窗并取消当前请求。
() => batchHook.result.current.closeBatchModal(),
);
expect(batchHook.result.current.showBatchModal).toBe(false);
batchHook.unmount();
});
test('库存加载和追加失败时保留可见错误', /* 当前回调验证卡密 Hook 的失败路径。 */ async () => {
+20
View File
@@ -230,6 +230,26 @@ describe('useChat', /* 当前回调处理聊天加载、分页、发送和实时
);
expect(hook.result.current.error).toBe('联系人读取失败');
getSessionPageMock.mockRejectedValueOnce(new Error('历史联系人失败'));
await act(
// moreContactsErrorAction 触发联系人分页错误。
async () => hook.result.current.loadMoreContacts(),
);
expect(hook.result.current.error).toBe('历史联系人失败');
// scrollContainer 是滚动策略测试使用的最小 DOM 容器。
const scrollContainer = { scrollHeight: 100, scrollTop: 20, clientHeight: 50 } as HTMLDivElement;
hook.result.current.scrollRef.current = scrollContainer;
await act(
// scrollAction 验证距离底部较远时不自动滚动。
() => hook.result.current.handleMessageScroll(),
);
scrollContainer.scrollTop = 60;
await act(
// nearBottomScrollAction 验证接近底部时启用自动滚动。
() => hook.result.current.handleMessageScroll(),
);
getMessagePageMock.mockRejectedValueOnce(new Error('消息读取失败'));
await act(
// chatSwitchAction 切换到不存在会话以触发消息读取错误。