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

// 简单的测试组件
const TestComponent = () => {
  return (
    <View className="test-component">
      <Text className="btn">点击我</Text>
    </View>
  )
}

describe('Taro 组件测试示例', () => {
  test('应该正确渲染组件', () => {
    render(<TestComponent />)

    const button = screen.getByText('点击我')
    expect(button).toBeInTheDocument()
    expect(button).toHaveClass('btn')
  })

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

    const InteractiveComponent = () => (
      <View className="test-component">
        <Text className="btn" onClick={handleClick}>点击我</Text>
      </View>
    )

    render(<InteractiveComponent />)

    const button = screen.getByText('点击我')
    fireEvent.click(button)

    expect(handleClick).toHaveBeenCalledTimes(1)
  })

  test('应该匹配快照', () => {
    const { container } = render(<TestComponent />)
    expect(container.firstChild).toMatchSnapshot()
  })
})