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

describe('Editor', () => {
  it('renders with content', () => {
    render(<Editor content="Hello World" onChange={() => {}} />)
    const textarea = screen.getByDisplayValue('Hello World')
    expect(textarea).toBeInTheDocument()
  })

  it('calls onChange when content changes', () => {
    const handleChange = vi.fn()
    render(<Editor content="" onChange={handleChange} />)
    const textarea = screen.getByRole('textbox')
    fireEvent.change(textarea, { target: { value: 'New content' } })
    expect(handleChange).toHaveBeenCalledWith('New content')
  })

  it('shows placeholder when empty', () => {
    render(<Editor content="" onChange={() => {}} placeholder="Type here..." />)
    const textarea = screen.getByPlaceholderText('Type here...')
    expect(textarea).toBeInTheDocument()
  })

  it('is disabled when disabled prop is true', () => {
    render(<Editor content="" onChange={() => {}} disabled />)
    const textarea = screen.getByRole('textbox')
    expect(textarea).toBeDisabled()
  })
})
