chore: create new tests for the UI, namely normnode, and one for all nodes
This commit is contained in:
41
test/test-utils/mocks.ts
Normal file
41
test/test-utils/mocks.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import React from 'react';
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
/**
|
||||
* Mock for @xyflow/react
|
||||
* Provides simplified versions of React Flow hooks and components
|
||||
*/
|
||||
jest.mock('@xyflow/react', () => ({
|
||||
useReactFlow: jest.fn(() => ({
|
||||
screenToFlowPosition: jest.fn((pos: any) => pos),
|
||||
getNode: jest.fn(),
|
||||
getNodes: jest.fn(() => []),
|
||||
getEdges: jest.fn(() => []),
|
||||
setNodes: jest.fn(),
|
||||
setEdges: jest.fn(),
|
||||
})),
|
||||
ReactFlowProvider: ({ children }: { children: React.ReactNode }) =>
|
||||
React.createElement('div', { 'data-testid': 'react-flow-provider' }, children),
|
||||
ReactFlow: ({ children, ...props }: any) =>
|
||||
React.createElement('div', { 'data-testid': 'react-flow', ...props }, children),
|
||||
Handle: ({ type, position, id }: any) =>
|
||||
React.createElement('div', { 'data-testid': `handle-${type}-${id}`, 'data-position': position }),
|
||||
Panel: ({ children, position }: any) =>
|
||||
React.createElement('div', { 'data-testid': 'panel', 'data-position': position }, children),
|
||||
Controls: () => React.createElement('div', { 'data-testid': 'controls' }),
|
||||
Background: () => React.createElement('div', { 'data-testid': 'background' }),
|
||||
}));
|
||||
|
||||
/**
|
||||
* Mock for @neodrag/react
|
||||
* Simplifies drag behavior for testing
|
||||
*/
|
||||
jest.mock('@neodrag/react', () => ({
|
||||
useDraggable: jest.fn((ref: any, options?: any) => {
|
||||
// Store the options so we can trigger them in tests
|
||||
if (ref && ref.current) {
|
||||
(ref.current as any)._dragOptions = options;
|
||||
}
|
||||
}),
|
||||
}));
|
||||
35
test/test-utils/test-utils.tsx
Normal file
35
test/test-utils/test-utils.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
// __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';
|
||||
import useFlowStore from '../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores';
|
||||
|
||||
/**
|
||||
* 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<RenderOptions, 'wrapper'>
|
||||
) {
|
||||
function Wrapper({ children }: { children: ReactNode }) {
|
||||
return <ReactFlowProvider>{children}</ReactFlowProvider>;
|
||||
}
|
||||
|
||||
return render(ui, { wrapper: Wrapper, ...options });
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to reset the Zustand store between tests
|
||||
* This ensures test isolation
|
||||
*/
|
||||
export function resetFlowStore() {
|
||||
useFlowStore.setState({
|
||||
nodes: [],
|
||||
edges: [],
|
||||
edgeReconnectSuccessful: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Re-export everything from testing library
|
||||
export * from '@testing-library/react';
|
||||
Reference in New Issue
Block a user