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

import ErrorScreen from '@/components/ErrorScreen'

describe ('ErrorScreen', () => {
  it.each ([
    [403, '権限ないよ（笑）'],
    [404, 'ページないよ（笑）'],
    [500, '鯖でエラー出たって（嘲笑）'],
    [503, '鯖死んでるよ（泣）'],
  ]) ('renders status %s', (status, message) => {
    render (
        <HelmetProvider>
          <ErrorScreen status={status}/>
        </HelmetProvider>,
    )

    expect (screen.getByText (String (status))).toBeInTheDocument ()
    expect (screen.getByText (message)).toBeInTheDocument ()
    expect (screen.getByAltText ('逃げたギター')).toBeInTheDocument ()
  })

  it ('throws for unsupported statuses', () => {
    expect (() => render (
        <HelmetProvider>
          <ErrorScreen status={418}/>
        </HelmetProvider>,
    )).toThrow ()
  })
})
