import { Nullable } from "@reins/types";
import { render } from "@testing-library/react";

import { createForm } from "factory";

type InitialValues = {
  name: string | null;
  surname: string | null;
  age: number | null;
  address: Nullable<{
    street: string;
    city: string;
    country: string;
  }>;
};

const initialValues: InitialValues = {
  name: null,
  surname: null,
  age: null,
  address: null,
};

describe("useField [ Base ]", () => {
  const onSubmit = jest.fn();
  let form = createForm(initialValues);

  beforeEach(() => {
    form = createForm(initialValues);
    onSubmit.mockClear();
  });

  const Field1 = () => {
    const { field } = form.useField("name");
    return <div>{field.value}</div>;
  };

  const Field2 = () => {
    const { field } = form.useField("surname");
    return <div>{field.value}</div>;
  };

  const App = () => {
    return (
      <form.Form onSubmit={onSubmit}>
        <Field1 />
        <Field2 />
      </form.Form>
    );
  };

  it("should be true", async () => {
    const rendered = render(<App />);

    expect(rendered).toBeTruthy();
  });
});
