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

import TabGroup, { Tab } from '@/components/common/TabGroup'

describe ('TabGroup', () => {
  it ('uses the init tab and switches tabs when clicked', () => {
    render (
        <TabGroup>
          <Tab name="A">Alpha</Tab>
          <Tab name="B" init>Beta</Tab>
        </TabGroup>,
    )

    expect (screen.queryByText ('Alpha')).not.toBeInTheDocument ()
    expect (screen.getByText ('Beta')).toBeInTheDocument ()

    fireEvent.click (screen.getByText ('A'))

    expect (screen.getByText ('Alpha')).toBeInTheDocument ()
    expect (screen.queryByText ('Beta')).not.toBeInTheDocument ()
  })
})
