import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import Editor from '../Editor';

describe('Editor Component', () => {
  it('renders textarea', () => {
    render(
      <Editor content="Test content" onChange={() => {}} />
    );
    const textarea = screen.getByPlaceholderText(/Start writing your markdown here/i);
    expect(textarea).toBeInTheDocument();
  });

  it('displays provided content', () => {
    render(
      <Editor content="# Heading" onChange={() => {}} />
    );
    const textarea = screen.getByDisplayValue('# Heading');
    expect(textarea).toBeInTheDocument();
  });

  it('handles content changes', () => {
    const handleChange = jest.fn();
    render(
      <Editor content="" onChange={handleChange} />
    );
    const textarea = screen.getByPlaceholderText(/Start writing your markdown here/i);
    fireEvent.change(textarea, { target: { value: 'New content' } });
    expect(handleChange).toHaveBeenCalledWith('New content');
  });

  it('disables when prop is true', () => {
    render(
      <Editor content="Test" onChange={() => {}} disabled={true} />
    );
    const textarea = screen.getByPlaceholderText(/Start writing your markdown here/i);
    expect(textarea).toBeDisabled();
  });
});
