import type { ReactNode } from 'react'
import { render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'

import { RootLayout } from './RootLayout'

const authProviderMock = vi.fn(({ children }: { children: ReactNode }) => (
  <div data-testid="auth-provider">{children}</div>
))

vi.mock('react-router-dom', () => ({
  Outlet: () => <div data-testid="root-outlet" />,
}))

vi.mock('./providers/AuthProvider', () => ({
  AuthProvider: (props: { children: ReactNode }) => authProviderMock(props),
}))

describe('RootLayout', () => {
  it('wraps the route outlet with the auth provider', () => {
    render(<RootLayout />)

    expect(screen.getByTestId('auth-provider')).toBeInTheDocument()
    expect(screen.getByTestId('root-outlet')).toBeInTheDocument()
    expect(authProviderMock).toHaveBeenCalledTimes(1)
  })
})
