Files
OpenHands/frontend/__tests__/helpers
sp.wack cd2d0ee9a5 feat(frontend): Organizational support (#9496)
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Hiep Le <69354317+hieptl@users.noreply.github.com>
Co-authored-by: Abhay Mishra <grabhaymishra@gmail.com>
Co-authored-by: Hyun Han <62870362+smosco@users.noreply.github.com>
Co-authored-by: Nhan Nguyen <nhan13574@gmail.com>
Co-authored-by: Bharath A V <avbharath1221@gmail.com>
Co-authored-by: hieptl <hieptl.developer@gmail.com>
Co-authored-by: Chloe <chloe@openhands.com>
Co-authored-by: HeyItsChloe <54480367+HeyItsChloe@users.noreply.github.com>
2026-03-13 23:38:54 +07:00
..

Test Helpers

This directory contains reusable test utilities and components for the OpenHands frontend test suite.

Files

websocket-test-components.tsx

Contains React test components for accessing and displaying WebSocket-related store values:

  • ConnectionStatusComponent - Displays WebSocket connection state
  • EventStoreComponent - Displays event store values (events count, UI events count, latest event ID)
  • OptimisticUserMessageStoreComponent - Displays optimistic user message store values
  • ErrorMessageStoreComponent - Displays error message store values

These components are designed to be used in tests to verify that WebSocket events are properly processed and stored.

msw-websocket-setup.ts

Contains MSW (Mock Service Worker) setup utilities for WebSocket testing:

  • createWebSocketLink() - Creates a WebSocket link for MSW testing
  • createWebSocketMockServer() - Creates and configures an MSW server for WebSocket testing
  • createWebSocketTestSetup() - Creates a complete WebSocket testing setup
  • conversationWebSocketTestSetup() - Standard setup for conversation WebSocket handler tests

Usage

import {
  ConnectionStatusComponent,
  EventStoreComponent,
} from "./__tests__/helpers/websocket-test-components";
import { conversationWebSocketTestSetup } from "./__tests__/helpers/msw-websocket-setup";

// Set up MSW server
const { wsLink, server } = conversationWebSocketTestSetup();

// Render components with WebSocket context (helper function defined in test file)
renderWithWebSocketContext(<ConnectionStatusComponent />);

Benefits

  • Reusability: Test components and utilities can be shared across multiple test files
  • Maintainability: Changes to test setup only need to be made in one place
  • Consistency: Ensures consistent test setup across different WebSocket-related tests
  • Readability: Test files are cleaner and focus on test logic rather than setup boilerplate