import React from "react";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";
import { ComboBoxProps } from "../ComboBoxProps";
import ComboBox from "../ComboBox";

describe("ComboBox Component", () => {
  const props: ComboBoxProps = {
    dataTestId: "test-id",
    accessKey: "key",
    adaptive: true,
    adaptiveFilter: "filter",
    adaptiveTitle: "title",
    allowCustom: false,
    ariaDescribedBy: "description",
    ariaLabelledBy: "label",
    className: "custom-class",
    clearButton: true,
    data: [
      { text: "Item1", value: 1 },
      { text: "Item2", value: 2 },
    ],
    dataItemKey: "value",
    defaultValue: { text: "Item1", value: 1 },
    dir: "ltr",
    disabled: false,
    fillMode: "solid",
    filter: "filter",
    filterable: true,
    footer: <div>Footer</div>,
    groupField: "group",
    groupMode: "modern",
    header: <div>Header</div>,
    iconClassName: "icon-class",
    id: "combobox-id",
    label: "label",
    loading: false,
    name: "combobox-name",
    opened: false,
    placeholder: "placeholder",
    popupSettings: { className: "popup-class" },
    required: false,
    rounded: "medium",
    size: "medium",
    skipDisabledItems: true,
    style: { color: "red" },
    suggest: false,
    svgIcon: {
      name: "exampleIcon",
      content:
        '<path d="M112 32c-26.5 0-48 21.5-48 48s21.5 48 48 48 48-21.5 48-48-21.5-48-48-48zM64 160v288h96V160H64zm128 0v288h96V288c0-32 32-32 32-32s32 0 32 32v160h96V290.9c0-66.5-13.6-130.9-96-130.9-36.2 0-62.9 32-64 44.9V160h-96z" />',
      viewBox: "0 0 24 24",
    },
    tabIndex: 0,
    textField: "text",
    title: "title",
    valid: true,
    validationMessage: "message",
    validityStyles: true,
    value: { text: "Item2", value: 2 },
  };

  it("renders all props correctly", () => {
    render(<ComboBox {...props} />);
  });

  it("matches the snapshot", () => {
    const { asFragment } = render(<ComboBox {...props} />);
    const fragment = asFragment();
    const cleanFragment = fragment.cloneNode(true) as HTMLElement;

    cleanFragment.querySelectorAll("[aria-owns]").forEach((el) => {
      el.removeAttribute("aria-owns");
    });

    expect(cleanFragment).toMatchSnapshot();
  });
});
