import { render, screen, fireEvent } from '@testing-library/react'
import { Button } from '@tarojs/components'

describe('Button 组件测试', () => {
  test('应该正确渲染按钮', () => {
    render(<Button>测试按钮</Button>)

    const button = screen.getByRole('button')
    expect(button).toBeInTheDocument()
    expect(button).toHaveTextContent('测试按钮')
  })

  test('应该响应点击事件', () => {
    const handleClick = jest.fn()

    render(<Button onClick={handleClick}>可点击按钮</Button>)

    const button = screen.getByRole('button')
    fireEvent.click(button)

    expect(handleClick).toHaveBeenCalledTimes(1)
  })

  test('应该禁用按钮', () => {
    render(<Button disabled>禁用按钮</Button>)

    const button = screen.getByRole('button')
    expect(button).toBeDisabled()
  })

  test('应该应用自定义类名', () => {
    render(<Button className="custom-class">自定义按钮</Button>)

    const button = screen.getByRole('button')
    expect(button).toHaveClass('custom-class')
  })
})