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

import EmptyState from './EmptyState'

describe('EmptyState', () => {
  const defaultProps = {
    primaryText: 'No Data Available',
  }

  it('renders with primary text', () => {
    render(<EmptyState {...defaultProps} />)

    const component = screen.getByTestId('empty-state-component')
    expect(component).toBeInTheDocument()

    const primaryText = screen.getByTestId('empty-state-primary-text')
    expect(primaryText).toBeInTheDocument()
    expect(primaryText).toHaveTextContent('No Data Available')
  })

  it('renders with secondary text when provided', () => {
    const secondaryText = 'Please try again later'
    render(<EmptyState {...defaultProps} secondaryText={secondaryText} />)

    const secondaryTextElement = screen.getByTestId(
      'empty-state-secondary-text',
    )
    expect(secondaryTextElement).toBeInTheDocument()
    expect(secondaryTextElement).toHaveTextContent(secondaryText)
  })

  it('renders with icon when provided', () => {
    render(<EmptyState {...defaultProps} icon='info' />)

    const icon = screen.getByTestId('icon-info')
    expect(icon).toBeInTheDocument()
  })

  it('renders with button when buttonProps are provided', () => {
    const buttonProps = {
      children: 'Refresh',
      onClick: () => {},
    }
    render(<EmptyState {...defaultProps} buttonProps={buttonProps} />)

    const button = screen.getByRole('button', { name: 'Refresh' })
    expect(button).toBeInTheDocument()
  })

  it('does not render secondary text when not provided', () => {
    render(<EmptyState {...defaultProps} />)

    const secondaryText = screen.queryByTestId('empty-state-secondary-text')
    expect(secondaryText).not.toBeInTheDocument()
  })

  it('does not render icon when not provided', () => {
    render(<EmptyState {...defaultProps} />)

    const icon = screen.queryByTestId('icon-info')
    expect(icon).not.toBeInTheDocument()
  })

  it('does not render button when buttonProps are not provided', () => {
    render(<EmptyState {...defaultProps} />)

    const button = screen.queryByRole('button')
    expect(button).not.toBeInTheDocument()
  })
})
