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

import Columns from "./Columns";

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

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

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

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