"use strict";

var _testUtilities = require("testUtilities");
var _useInputValue = require("./use-input-value");
describe("useInputValue", function () {
  it("returns initial value", function () {
    var _renderHook = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({
          value: "initial"
        });
      }),
      result = _renderHook.result;
    var _result$current = result.current,
      inputValue = _result$current[0];
    expect(inputValue).toBe("initial");
  });
  it("returns empty string as default value", function () {
    var _renderHook2 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook2.result;
    var _result$current2 = result.current,
      inputValue = _result$current2[0];
    expect(inputValue).toBe("");
  });
  it("returns isDirty as false initially", function () {
    var _renderHook3 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook3.result;
    var _result$current3 = result.current,
      isDirty = _result$current3[3];
    expect(isDirty).toBe(false);
  });
  it("updates value on change", function () {
    var _renderHook4 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook4.result;
    var _result$current4 = result.current,
      handleChange = _result$current4[1];
    var mockEvent = {
      target: {
        value: "new value"
      }
    };
    (0, _testUtilities.act)(function () {
      handleChange(mockEvent);
    });
    expect(result.current[0]).toBe("new value");
  });
  it("sets isDirty to true after first change", function () {
    var _renderHook5 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook5.result;
    var _result$current5 = result.current,
      handleChange = _result$current5[1];
    var mockEvent = {
      target: {
        value: "changed"
      }
    };
    (0, _testUtilities.act)(function () {
      handleChange(mockEvent);
    });
    expect(result.current[3]).toBe(true);
  });
  it("calls onChange callback when provided", function () {
    var onChange = jest.fn();
    var _renderHook6 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({
          onChange: onChange
        });
      }),
      result = _renderHook6.result;
    var _result$current6 = result.current,
      handleChange = _result$current6[1];
    var mockEvent = {
      target: {
        value: "test"
      }
    };
    (0, _testUtilities.act)(function () {
      handleChange(mockEvent);
    });
    expect(onChange).toHaveBeenCalledWith(mockEvent);
  });
  it("respects maxChars limit", function () {
    var _renderHook7 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({
          maxChars: 5
        });
      }),
      result = _renderHook7.result;
    var _result$current7 = result.current,
      handleChange = _result$current7[1];
    var mockEvent = {
      target: {
        value: "toolong"
      },
      preventDefault: jest.fn(),
      stopPropagation: jest.fn()
    };
    (0, _testUtilities.act)(function () {
      handleChange(mockEvent);
    });
    expect(result.current[0]).toBe("");
    expect(mockEvent.preventDefault).toHaveBeenCalled();
    expect(mockEvent.stopPropagation).toHaveBeenCalled();
  });
  it("allows input within maxChars limit", function () {
    var _renderHook8 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({
          maxChars: 10
        });
      }),
      result = _renderHook8.result;
    var _result$current8 = result.current,
      handleChange = _result$current8[1];
    var mockEvent = {
      target: {
        value: "short"
      }
    };
    (0, _testUtilities.act)(function () {
      handleChange(mockEvent);
    });
    expect(result.current[0]).toBe("short");
  });
  it("generates maxChars indicator", function () {
    var _renderHook9 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({
          maxChars: 10
        });
      }),
      result = _renderHook9.result;
    var _result$current9 = result.current,
      handleChange = _result$current9[1],
      maxCharsIndicator = _result$current9[2];
    expect(maxCharsIndicator).toBe("0/10");
    var mockEvent = {
      target: {
        value: "test"
      }
    };
    (0, _testUtilities.act)(function () {
      handleChange(mockEvent);
    });
    expect(result.current[2]).toBe("4/10");
  });
  it("returns empty maxChars indicator when no limit", function () {
    var _renderHook0 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook0.result;
    var _result$current0 = result.current,
      maxCharsIndicator = _result$current0[2];
    expect(maxCharsIndicator).toBe("");
  });
  it("resets value and dirty state", function () {
    var _renderHook1 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook1.result;
    var _result$current1 = result.current,
      handleChange = _result$current1[1],
      resetValue = _result$current1[4].resetValue;
    var mockEvent = {
      target: {
        value: "test"
      }
    };
    (0, _testUtilities.act)(function () {
      handleChange(mockEvent);
    });
    expect(result.current[0]).toBe("test");
    expect(result.current[3]).toBe(true);
    (0, _testUtilities.act)(function () {
      resetValue("reset");
    });
    expect(result.current[0]).toBe("reset");
    expect(result.current[3]).toBe(false);
  });
  it("resets to empty string by default", function () {
    var _renderHook10 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({
          value: "initial"
        });
      }),
      result = _renderHook10.result;
    var _result$current10 = result.current,
      resetValue = _result$current10[4].resetValue;
    (0, _testUtilities.act)(function () {
      resetValue();
    });
    expect(result.current[0]).toBe("");
  });
  it("provides setValue helper", function () {
    var _renderHook11 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook11.result;
    var _result$current11 = result.current,
      setValue = _result$current11[4].setValue;
    (0, _testUtilities.act)(function () {
      setValue("direct set");
    });
    expect(result.current[0]).toBe("direct set");
  });
  it("provides setIsDirty helper", function () {
    var _renderHook12 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook12.result;
    var _result$current12 = result.current,
      setIsDirty = _result$current12[4].setIsDirty;
    (0, _testUtilities.act)(function () {
      setIsDirty(true);
    });
    expect(result.current[3]).toBe(true);
  });
  it("maintains stable function references", function () {
    var _renderHook13 = (0, _testUtilities.renderHook)(function () {
        return (0, _useInputValue.useInputValue)({});
      }),
      result = _renderHook13.result,
      rerender = _renderHook13.rerender;
    var _result$current13 = result.current,
      initialHandleChange = _result$current13[1];
    rerender();
    var _result$current14 = result.current,
      newHandleChange = _result$current14[1];
    expect(newHandleChange).toBe(initialHandleChange);
  });
});