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

import Label from "./Label";

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

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

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

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