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

HTMLCanvasElement.prototype.getContext = (() => ({ measureText: () => ({ width: 0 }) })) as unknown as typeof HTMLCanvasElement.prototype.getContext

describe('ScrollArea', () => {
  it('renders children', () => {
    render(<ScrollArea data-testid="scroll">Body</ScrollArea>)
    expect(screen.getByText('Body')).toBeTruthy()
  })

  it('applies the gap token var and min-width overflow guard', () => {
    render(<ScrollArea data-testid="scroll" gap="5">Body</ScrollArea>)
    const scroll = screen.getByTestId('scroll')
    expect(scroll.style.getPropertyValue('--scroll-gap')).toBe('var(--mod-space-5)')
    expect(scroll.style.paddingBlock).toBe('var(--scroll-gap)')
    expect(scroll.style.minWidth).toBe('0px')
  })

  it('stays axe-clean', async () => {
    const { container } = render(<ScrollArea>Body</ScrollArea>)
    await expect(axe(container)).resolves.toHaveNoViolations()
  })
})
