"use strict";
const data = require("./data.cjs");
const keyChain = require("./keyChain.cjs");
describe("initialDataIsCallback", () => {
  it("returns true if the state data passed to the form is a function", () => {
    const data$1 = () => ({});
    const result = data.initialDataIsCallback(data$1);
    expect(result).toBeTruthy();
  });
  it("returns false if the state data passed to the form is not a function", () => {
    const data$1 = {};
    const result = data.initialDataIsCallback(data$1);
    expect(result).toBeFalsy();
  });
});
describe("dataReducer", () => {
  beforeEach(() => {
    jest.clearAllMocks();
  });
  it("carries out a deep merge when the action is set-path", () => {
    const deepMergeSpy = jest.spyOn(keyChain, "mergeDeepFromKeyChain").mockReturnValue({ test: "newValue" });
    const state = {
      test: "value"
    };
    const result = data.dataReducer(state, {
      type: "set-path",
      keyChain: ["test"],
      value: "newValue"
    });
    expect(deepMergeSpy).toHaveBeenCalledTimes(1);
    expect(result).toEqual({
      test: "newValue"
    });
  });
  describe("set-one", () => {
    it("transforms one property in state when state is an array and the path reference is an index", () => {
      const state = ["value"];
      const result = data.dataReducer(state, {
        type: "set-one",
        propertyKey: 0,
        value: "newValue"
      });
      expect(result).toEqual(["newValue"]);
    });
    it("transforms one property in state when state is an object and the path reference is a key", () => {
      const state = {
        test: "value"
      };
      const result = data.dataReducer(state, {
        type: "set-one",
        propertyKey: "test",
        value: "newValue"
      });
      expect(result).toEqual({
        test: "newValue"
      });
    });
  });
  describe("set-all", () => {
    it("transforms all changed properties in state when state is an array", () => {
      const state = ["value1", "value2", "value3"];
      const result = data.dataReducer(state, {
        type: "set-all",
        data: ["newValue1", "newValue2", "value3", "value4"]
      });
      expect(result).toEqual(["newValue1", "newValue2", "value3", "value4"]);
    });
    it("transforms all changed properties in state when state is an object", () => {
      const state = { test1: "value1", test2: "value2", test3: "value3" };
      const result = data.dataReducer(state, {
        type: "set-all",
        data: { test1: "newValue1", test2: "newValue2", test3: "value3" }
      });
      expect(result).toEqual({
        test1: "newValue1",
        test2: "newValue2",
        test3: "value3"
      });
    });
  });
});
describe("hasTruthyProperty", () => {
  it("should return false when object is null, undefined or has no truthy properties", () => {
    expect(data.hasTruthyProperty(null)).toBe(false);
    expect(data.hasTruthyProperty(void 0)).toBe(false);
    expect(data.hasTruthyProperty({})).toBe(false);
    expect(data.hasTruthyProperty({ prop: false })).toBe(false);
    expect(data.hasTruthyProperty({ prop: 0 })).toBe(false);
    expect(data.hasTruthyProperty({ prop: "" })).toBe(false);
    expect(data.hasTruthyProperty({ prop: {} })).toBe(false);
  });
  it("should return true when object has a truthy property", () => {
    expect(data.hasTruthyProperty({ prop: true })).toBe(true);
    expect(data.hasTruthyProperty({ prop: 1 })).toBe(true);
    expect(data.hasTruthyProperty({ prop: "a" })).toBe(true);
  });
  it("should return true when nested object has a truthy property", () => {
    expect(data.hasTruthyProperty({ prop: { nestedProp: true } })).toBe(true);
    expect(data.hasTruthyProperty({ prop: { nestedProp: 1 } })).toBe(true);
    expect(data.hasTruthyProperty({ prop: { nestedProp: "a" } })).toBe(true);
  });
});
//# sourceMappingURL=data.spec.cjs.map
