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

import PresetSelector from "./PresetSelector";

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

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

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

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