π OpenHands: AI-Driven Development
test(frontend): add missing HTTP mocks for conversation history preloading (#12549)
sp.wackcc5d5c233592
diff --git a/frontend/__tests__/conversation-websocket-handler.test.tsx b/frontend/__tests__/conversation-websocket-handler.test.tsxindex 2784c9d726..6e6dadaca4 100644--- a/frontend/__tests__/conversation-websocket-handler.test.tsx+++ b/frontend/__tests__/conversation-websocket-handler.test.tsx@@ -40,6 +40,18 @@ import { conversationWebSocketTestSetup } from "./helpers/msw-websocket-setup";import { useEventStore } from "#/stores/use-event-store";import { isV1Event } from "#/types/v1/type-guards";+// Mock useUserConversation to return V1 conversation data+vi.mock("#/hooks/query/use-user-conversation", () => ({+ useUserConversation: vi.fn(() => ({+ data: {+ conversation_version: "V1",+ status: "RUNNING",+ },+ isLoading: false,+ error: null,+ })),+}));+// MSW WebSocket mock setupconst { wsLink, server: mswServer } = conversationWebSocketTestSetup();@@ -667,6 +679,16 @@ describe("Conversation WebSocket Handler", () => {// Set up MSW to mock both the HTTP API and WebSocket connectionmswServer.use(+ // Mock events search for history preloading+ http.get(+ `http://localhost:3000/api/v1/conversation/${conversationId}/events/search`,+ async () => {+ await new Promise((resolve) => setTimeout(resolve, 10));+ return HttpResponse.json({+ items: mockHistoryEvents,+ });+ },+ ),http.get(`http://localhost:3000/api/conversations/${conversationId}/events/count`,() => HttpResponse.json(expectedEventCount),@@ -703,11 +725,6 @@ describe("Conversation WebSocket Handler", () => {`http://localhost:3000/api/conversations/${conversationId}`,);- // Initially should be loading history- expect(screen.getByTestId("is-loading-history")).toHaveTextContent(- "true",- );-// Wait for all events to be receivedawait waitFor(() => {expect(screen.getByTestId("events-received")).toHaveTextContent("3");@@ -726,6 +743,14 @@ describe("Conversation WebSocket Handler", () => {// Set up MSW to mock both the HTTP API and WebSocket connectionmswServer.use(+ // Mock empty events search+ http.get(+ `http://localhost:3000/api/v1/conversation/${conversationId}/events/search`,+ () =>+ HttpResponse.json({+ items: [],+ }),+ ),http.get(`http://localhost:3000/api/conversations/${conversationId}/events/count`,() => HttpResponse.json(0),@@ -775,6 +800,16 @@ describe("Conversation WebSocket Handler", () => {// Set up MSW to mock both the HTTP API and WebSocket connectionmswServer.use(+ // Mock events search for history preloading (50 events)+ http.get(+ `http://localhost:3000/api/v1/conversation/${conversationId}/events/search`,+ async () => {+ await new Promise((resolve) => setTimeout(resolve, 10));+ return HttpResponse.json({+ items: mockHistoryEvents,+ });+ },+ ),http.get(`http://localhost:3000/api/conversations/${conversationId}/events/count`,() => HttpResponse.json(expectedEventCount),@@ -810,11 +845,6 @@ describe("Conversation WebSocket Handler", () => {`http://localhost:3000/api/conversations/${conversationId}`,);- // Initially should be loading history- expect(screen.getByTestId("is-loading-history")).toHaveTextContent(- "true",- );-// Wait for all events to be receivedawait waitFor(() => {expect(screen.getByTestId("events-received")).toHaveTextContent("50");diff --git a/frontend/__tests__/hooks/query/use-conversation-history.test.tsx b/frontend/__tests__/hooks/query/use-conversation-history.test.tsxindex 50048aeda7..42b34b62ef 100644--- a/frontend/__tests__/hooks/query/use-conversation-history.test.tsx+++ b/frontend/__tests__/hooks/query/use-conversation-history.test.tsx@@ -1,5 +1,3 @@-// @vitest-environment happy-dom-import { describe, it, expect, afterEach, vi } from "vitest";import React from "react";import { renderHook, waitFor } from "@testing-library/react";