Skip to content

πŸ™Œ OpenHands: AI-Driven Development

hotfix(frontend): Wrap WS tests in query provider for migration changes (#7504)

sp.wack500e09f12b10
diff --git a/frontend/__tests__/context/ws-client-provider.test.tsx b/frontend/__tests__/context/ws-client-provider.test.tsx
index 7b5cec4a9c..777cbd1225 100644
--- a/frontend/__tests__/context/ws-client-provider.test.tsx
+++ b/frontend/__tests__/context/ws-client-provider.test.tsx
@@ -1,47 +1,51 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
-import { render, screen, waitFor } from "@testing-library/react";
+import { render, waitFor } from "@testing-library/react";
+import React from "react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import * as ChatSlice from "#/state/chat-slice";
import {
updateStatusWhenErrorMessagePresent,
WsClientProvider,
useWsClient,
} from "#/context/ws-client-provider";
-import React from "react";
describe("Propagate error message", () => {
it("should do nothing when no message was passed from server", () => {
const addErrorMessageSpy = vi.spyOn(ChatSlice, "addErrorMessage");
- updateStatusWhenErrorMessagePresent(null)
- updateStatusWhenErrorMessagePresent(undefined)
- updateStatusWhenErrorMessagePresent({})
- updateStatusWhenErrorMessagePresent({message: null})
+ updateStatusWhenErrorMessagePresent(null);
+ updateStatusWhenErrorMessagePresent(undefined);
+ updateStatusWhenErrorMessagePresent({});
+ updateStatusWhenErrorMessagePresent({ message: null });
expect(addErrorMessageSpy).not.toHaveBeenCalled();
});
it("should display error to user when present", () => {
- const message = "We have a problem!"
- const addErrorMessageSpy = vi.spyOn(ChatSlice, "addErrorMessage")
- updateStatusWhenErrorMessagePresent({message})
+ const message = "We have a problem!";
+ const addErrorMessageSpy = vi.spyOn(ChatSlice, "addErrorMessage");
+ updateStatusWhenErrorMessagePresent({ message });
expect(addErrorMessageSpy).toHaveBeenCalledWith({
message,
status_update: true,
- type: 'error'
- });
+ type: "error",
+ });
});
it("should display error including translation id when present", () => {
- const message = "We have a problem!"
- const addErrorMessageSpy = vi.spyOn(ChatSlice, "addErrorMessage")
- updateStatusWhenErrorMessagePresent({message, data: {msg_id: '..id..'}})
+ const message = "We have a problem!";
+ const addErrorMessageSpy = vi.spyOn(ChatSlice, "addErrorMessage");
+ updateStatusWhenErrorMessagePresent({
+ message,
+ data: { msg_id: "..id.." },
+ });
expect(addErrorMessageSpy).toHaveBeenCalledWith({
message,
- id: '..id..',
+ id: "..id..",
status_update: true,
- type: 'error'
- });
+ type: "error",
+ });
});
});
@@ -51,24 +55,22 @@ const mockOn = vi.fn();
const mockOff = vi.fn();
const mockDisconnect = vi.fn();
-vi.mock("socket.io-client", () => {
- return {
- io: vi.fn(() => ({
- emit: mockEmit,
- on: mockOn,
- off: mockOff,
- disconnect: mockDisconnect,
- io: {
- opts: {
- query: {},
- },
+vi.mock("socket.io-client", () => ({
+ io: vi.fn(() => ({
+ emit: mockEmit,
+ on: mockOn,
+ off: mockOff,
+ disconnect: mockDisconnect,
+ io: {
+ opts: {
+ query: {},
},
- })),
- };
-});
+ },
+ })),
+}));
// Mock component to test the hook
-const TestComponent = () => {
+function TestComponent() {
const { send } = useWsClient();
React.useEffect(() => {
@@ -77,7 +79,7 @@ const TestComponent = () => {
}, [send]);
return <div>Test Component</div>;
-};
+}
describe("WsClientProvider", () => {
beforeEach(() => {
@@ -85,18 +87,27 @@ describe("WsClientProvider", () => {
});
it("should emit oh_user_action event when send is called", async () => {
- const { getByText } = render(
- <WsClientProvider conversationId="test-conversation-id">
- <TestComponent />
- </WsClientProvider>
- );
+ const { getByText } = render(<TestComponent />, {
+ wrapper: ({ children }) => (
+ <QueryClientProvider client={new QueryClient()}>
+ <WsClientProvider conversationId="test-conversation-id">
+ {children}
+ </WsClientProvider>
+ </QueryClientProvider>
+ ),
+ });
// Assert
expect(getByText("Test Component")).toBeInTheDocument();
// Wait for the emit call to happen (useEffect needs time to run)
- await waitFor(() => {
- expect(mockEmit).toHaveBeenCalledWith("oh_user_action", { type: "test_event" });
- }, { timeout: 1000 });
+ await waitFor(
+ () => {
+ expect(mockEmit).toHaveBeenCalledWith("oh_user_action", {
+ type: "test_event",
+ });
+ },
+ { timeout: 1000 },
+ );
});
});