defmodule MicrowavepropWeb.LiveHelpersTest do
  use ExUnit.Case, async: true

  alias MicrowavepropWeb.LiveHelpers

  describe "parse_float/2" do
    test "returns default for nil and empty string" do
      assert LiveHelpers.parse_float(nil, 1.5) == 1.5
      assert LiveHelpers.parse_float("", 1.5) == 1.5
    end

    test "parses well-formed float strings" do
      assert LiveHelpers.parse_float("3.14", 0.0) == 3.14
      assert LiveHelpers.parse_float("-2.5", 0.0) == -2.5
    end

    test "parses integer strings to a float" do
      assert LiveHelpers.parse_float("42", 0.0) == 42.0
    end

    test "returns default on garbage input" do
      assert LiveHelpers.parse_float("nope", 7.0) == 7.0
    end

    test "accepts numbers via to_string conversion" do
      assert LiveHelpers.parse_float(2.5, 0.0) == 2.5
    end
  end

  describe "parse_int/2" do
    test "returns default for nil and empty string" do
      assert LiveHelpers.parse_int(nil, 5) == 5
      assert LiveHelpers.parse_int("", 5) == 5
    end

    test "parses integer strings" do
      assert LiveHelpers.parse_int("42", 0) == 42
      assert LiveHelpers.parse_int("-7", 0) == -7
    end

    test "returns default on garbage input" do
      assert LiveHelpers.parse_int("nope", 9) == 9
    end

    test "accepts integers via to_string conversion" do
      assert LiveHelpers.parse_int(42, 0) == 42
    end
  end
end
