// __tests__/utils/test-utils.tsx import { render, type RenderOptions } from '@testing-library/react'; import { type ReactElement, type ReactNode } from 'react'; import { ReactFlowProvider } from '@xyflow/react'; /** * Custom render function that wraps components with necessary providers * This ensures all components have access to ReactFlow context */ export function renderWithProviders( ui: ReactElement, options?: Omit ) { function Wrapper({ children }: { children: ReactNode }) { return {children}; } return render(ui, { wrapper: Wrapper, ...options }); } type SidebarRect = Partial; const defaultRect: DOMRect = { top: 0, left: 0, bottom: 100, right: 200, width: 200, height: 100, x: 0, y: 0, toJSON: () => {}, }; /** * Renders a component and injects a mock `#draggable-sidebar` * element required by Tooltip positioning logic. */ export function renderWithSidebar( ui: ReactElement, rect: SidebarRect = {}, options?: RenderOptions ) { const sidebar = document.createElement('div'); sidebar.id = 'draggable-sidebar'; sidebar.getBoundingClientRect = jest.fn(() => ({ ...defaultRect, ...rect, })); document.body.appendChild(sidebar); const result = render(ui, options); return { ...result, sidebar, }; } // Re-export everything from testing library //eslint-disable-next-line react-refresh/only-export-components export * from '@testing-library/react';