import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { Tooltip, TooltipTrigger, TooltipContent } from './tooltip';
import React from 'react';

// Mocking Portal
vi.mock('@radix-ui/react-tooltip', async () => {
  const actual = await vi.importActual('@radix-ui/react-tooltip');
  return {
    ...actual,
    Portal: ({ children }: { children: React.ReactNode }) => (
      <div data-testid="portal">{children}</div>
    ),
  };
});

describe('Tooltip', () => {
  it('renders correctly', () => {
    render(
      <Tooltip>
        <TooltipTrigger>Hover me</TooltipTrigger>
        <TooltipContent>Tooltip info</TooltipContent>
      </Tooltip>
    );

    expect(screen.getByText('Hover me')).toBeInTheDocument();
  });

  it('shows content when open is true', () => {
    render(
      <Tooltip open={true}>
        <TooltipTrigger>Hover me</TooltipTrigger>
        <TooltipContent>Tooltip info</TooltipContent>
      </Tooltip>
    );

    expect(screen.getAllByText('Tooltip info')[0]).toBeInTheDocument();
  });
});
