import { describe, it, expect, vi } from 'vitest'
import { fireEvent, render } from '@testing-library/react'
import { Actions, Options } from './widget-actions'

describe('<Actions>', () => {
  it('renders children and applies the widget-wrapper-actions class', () => {
    const { container, getByText } = render(
      <Actions>
        <button>act</button>
      </Actions>,
    )
    expect(getByText('act')).toBeTruthy()
    expect(container.querySelector('.widget-wrapper-actions')).not.toBeNull()
  })

  it('stops click propagation', () => {
    const onWrapperClick = vi.fn()
    const { getByText } = render(
      <button type='button' onClick={onWrapperClick}>
        <Actions>
          <span>btn</span>
        </Actions>
      </button>,
    )
    fireEvent.click(getByText('btn'))
    expect(onWrapperClick).not.toHaveBeenCalled()
  })
})

describe('<Options>', () => {
  it('renders children', () => {
    const { getByText } = render(
      <Options>
        <span>opt</span>
      </Options>,
    )
    expect(getByText('opt')).toBeTruthy()
  })

  it('stops click propagation', () => {
    const onWrapperClick = vi.fn()
    const { getByText } = render(
      <button type='button' onClick={onWrapperClick}>
        <Options>
          <span>opt</span>
        </Options>
      </button>,
    )
    fireEvent.click(getByText('opt'))
    expect(onWrapperClick).not.toHaveBeenCalled()
  })
})
