"use strict";
const react_esm = require('./../../_node_modules/@testing-library/react/dist/@testing-library/react.esm.cjs');
const useChildForm = require("./useChildForm.cjs");
const useForm = require("./useForm.cjs");
describe("useChildForm", () => {
  const rootFormState = {
    field1: "test",
    field2: 4,
    field3: true,
    childTest: {
      childField1: "cf1-test",
      childField2: "cf2-test",
      childField3: "cf3-test"
    }
  };
  const useTestHook = () => {
    const { formProp: baseFormProp, formState: baseFormState } = useForm.useForm(rootFormState, {
      validationErrors: [{ key: "childTest.childField1", message: "an error" }]
    });
    const { formProp: childFormProp, formState: childFormState } = useChildForm.useChildForm(baseFormProp("childTest").bind());
    return { baseFormProp, baseFormState, childFormProp, childFormState };
  };
  it("should return the correct form state", () => {
    const { result } = react_esm.renderHook(() => useTestHook());
    expect(result.current.childFormState).toEqual(rootFormState.childTest);
  });
  it("should modify the child and root form state correctly on set", () => {
    var _a, _b, _c;
    const { result } = react_esm.renderHook(() => useTestHook());
    react_esm.act(() => {
      result.current.childFormProp("childField1").set("cf1-new");
    });
    expect((_a = result.current.childFormState) == null ? void 0 : _a.childField1).toBe("cf1-new");
    expect((_c = (_b = result.current.baseFormState) == null ? void 0 : _b.childTest) == null ? void 0 : _c.childField1).toBe("cf1-new");
  });
  it("should add passed in validation errors to the correct keys", () => {
    const { result } = react_esm.renderHook(() => useTestHook());
    expect(result.current.childFormProp("childField1").bind().myValidationErrors).toEqual([
      { key: "childField1", message: "an error" }
    ]);
    expect(result.current.childFormProp("childField2").bind().myValidationErrors).toEqual([]);
    expect(result.current.childFormProp("childField3").bind().myValidationErrors).toEqual([]);
  });
  it("should dispatch validation errors to the correct keys", () => {
    const { result } = react_esm.renderHook(() => useTestHook());
    react_esm.act(() => result.current.childFormProp("childField1").bind().addValidationError("error-2"));
    expect(result.current.childFormProp("childField1").bind().myValidationErrors).toEqual([
      { key: "childField1", message: "error-2" },
      { key: "childField1", message: "an error" }
    ]);
    expect(result.current.childFormProp("childField2").bind().myValidationErrors).toEqual([]);
    expect(result.current.childFormProp("childField3").bind().myValidationErrors).toEqual([]);
  });
  it("should dispatch touch state `true` for the correct keys", () => {
    const { result } = react_esm.renderHook(() => useTestHook());
    react_esm.act(() => result.current.childFormProp("childField1").bind().setTouched(true));
    expect(result.current.childFormProp("childField1").bind().isTouched).toBe(true);
    expect(result.current.childFormProp("childField2").bind().isTouched).toBe(false);
    expect(result.current.childFormProp("childField3").bind().isTouched).toBe(false);
  });
  it("should dispatch touch state `false` for the correct keys", () => {
    const { result } = react_esm.renderHook(() => useTestHook());
    react_esm.act(() => result.current.childFormProp("childField1").bind().setTouched(false));
    expect(result.current.childFormProp("childField1").bind().isTouched).toBe(false);
    expect(result.current.childFormProp("childField2").bind().isTouched).toBe(false);
    expect(result.current.childFormProp("childField3").bind().isTouched).toBe(false);
  });
  it("should return a keyChain property that conforms to the key chain back to the root of the child binder", () => {
    const { result } = react_esm.renderHook(() => useTestHook());
    expect(result.current.childFormProp("childField1").bind().keyChain).toEqual(["childField1"]);
    expect(result.current.childFormProp("childField2").bind().keyChain).toEqual(["childField2"]);
    expect(result.current.childFormProp("childField3").bind().keyChain).toEqual(["childField3"]);
  });
  it("should return a fullKeyChain property that conforms to the full key chain", () => {
    const { result } = react_esm.renderHook(() => useTestHook());
    expect(result.current.childFormProp("childField1").bind().fullKeyChain).toEqual(["childTest", "childField1"]);
    expect(result.current.childFormProp("childField2").bind().fullKeyChain).toEqual(["childTest", "childField2"]);
    expect(result.current.childFormProp("childField3").bind().fullKeyChain).toEqual(["childTest", "childField3"]);
  });
});
//# sourceMappingURL=useChildForm.spec.cjs.map
