import { render, waitFor } from "@testing-library/react";
import { Parameters } from "./Parameters";
import addSnapshotSerializer from "../../../utils/snapshot";

const renderState = {
  EMPTY: 0,
  JUST_DATA: 1,
};

const renderParameters = async (rs) => {
  await waitFor(() => {
    /* render */
  });

  if (rs === renderState.EMPTY) {
    const { container } = render(<Parameters />);

    return container;
  }
  const params = {
    dataFunc: (val, handleValChange) => <div>val.toString()</div>,
  };
  const [data, handleDataChange] = [true, (_) => {}];

  if (rs === renderState.JUST_DATA) {
    const { container } = render(
      <Parameters
        params={params}
        data={data}
        handleDataChange={handleDataChange}
      />
    );

    return container;
  }
};

describe("Params", () => {
  beforeAll(() => {
    addSnapshotSerializer(expect);
  });

  it("Render empty", async () => {
    const container = await renderParameters(renderState.EMPTY);
    expect(container).toMatchSnapshot();
  });

  it("Render just data", async () => {
    const container = await renderParameters(renderState.JUST_DATA);
    expect(container).toMatchSnapshot();
  });
});
