import * as React from "react";
import { render, screen, fireEvent, cleanup } from "@testing-library/react";

import Description from "./Description";

const testId = "FormBuilder-Attributes-Description";
const props = {};

describe("Rendering", () => {
  it(`Should render in the dom`, () => {
    render(<Description {...props} />);
    expect(screen.queryByTestId(testId)).toBeTruthy();
  });
});

describe("Events", () => {
  it(`Should trigger onChange when the description field updates`, () => {
    const onChange = jest.fn();
    render(<Description {...props} onChange={onChange} />);
    fireEvent.change(screen.getByTestId(testId).querySelector("textarea"), {
      target: { value: "Testing" },
    });
    expect(onChange).toBeCalled();
  });

  it(`Should trigger onBlur when the description field loses focus`, () => {
    const onBlur = jest.fn();
    render(<Description {...props} onBlur={onBlur} />);
    fireEvent.blur(screen.getByTestId(testId).querySelector("textarea"));
    expect(onBlur).toBeCalled();
  });
});
