/**
 * 测试包装组件
 * 提供测试环境所需的Provider包装
 */

import React from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { BrowserRouter } from 'react-router';

interface TestWrapperProps {
  children: React.ReactNode;
  queryClient?: QueryClient;
  withRouter?: boolean;
}

const TestWrapper: React.FC<TestWrapperProps> = ({
  children,
  queryClient,
  withRouter = true,
}) => {
  const testQueryClient = queryClient || new QueryClient({
    defaultOptions: {
      queries: {
        retry: false,
        gcTime: 0,
      },
    },
  });

  const content = (
    <QueryClientProvider client={testQueryClient}>
      {children}
    </QueryClientProvider>
  );

  if (withRouter) {
    return <BrowserRouter>{content}</BrowserRouter>;
  }

  return content;
};

export default TestWrapper;