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

import Label from '@/components/common/Label'

describe ('Label', () => {
  it ('renders a plain label', () => {
    render (<Label>名前</Label>)

    expect (screen.getByText ('名前')).toBeInTheDocument ()
  })

  it ('renders and toggles the optional checkbox', () => {
    const handleChange = vi.fn ()

    render (
        <Label checkBox={{ label: '不明', checked: false, onChange: handleChange }}>
          日時
        </Label>,
    )

    fireEvent.click (screen.getByRole ('checkbox', { name: '不明' }))

    expect (handleChange).toHaveBeenCalledTimes (1)
  })
})
