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

import LinkSelector from "./LinkSelector";

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

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

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

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