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

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

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

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

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