import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { OAuthCallbackPage } from './OAuthCallbackPage';
import { useOAuthCallback } from '../hooks/useOAuthCallback';

// Mock the hook
vi.mock('../hooks/useOAuthCallback', () => ({
  useOAuthCallback: vi.fn(),
}));

const wrapper = ({ children }: { children: React.ReactNode }) => (
  <MemoryRouter>{children}</MemoryRouter>
);

describe('OAuthCallbackPage', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('should render loading message', () => {
    vi.mocked(useOAuthCallback).mockReturnValue(undefined as any);

    render(<OAuthCallbackPage />, { wrapper });

    expect(screen.getByText('Connexion en cours...')).toBeInTheDocument();
    expect(screen.getByText('Veuillez patienter...')).toBeInTheDocument();
    expect(
      screen.getByText('Finalisation de votre connexion...'),
    ).toBeInTheDocument();
  });

  it('should call useOAuthCallback hook', () => {
    vi.mocked(useOAuthCallback).mockReturnValue(undefined as any);

    render(<OAuthCallbackPage />, { wrapper });

    expect(useOAuthCallback).toHaveBeenCalled();
  });
});
