1.5 KiB · text History 9c0fc16
defmodule LambentExWeb.VersionsTest do
  use LambentExWeb.ConnCase

  import Phoenix.LiveViewTest

  @pubsub LambentEx.PubSub

  defp publish(devices) do
    Phoenix.PubSub.broadcast(@pubsub, "scan-82667777", {:devices_pub, devices})
  end

  test "versions are listed for the devices that report one", %{conn: conn} do
    {:ok, live, _html} = live(conn, "/cfg/devices/versions")

    publish(%{
      "cc:cc:cc:cc:cc:01" => %{
        "ip" => {10, 0, 0, 11},
        "sox" => 2,
        "type" => "7777-flex",
        "ver" => "0.1.0+ci20260916.gb81a582"
      },
      # a legacy device has no version to report and is not listed
      "cc:cc:cc:cc:cc:02" => %{"ip" => {10, 0, 0, 12}, "sox" => 0, "type" => "7777-8266"}
    })

    html = render(live)
    assert html =~ "0.1.0+ci20260916.gb81a582"
    assert html =~ "10.0.0.11"
    refute html =~ "cc:cc:cc:cc:cc:02"
  end

  test "a flex device with no version yet shows as unknown", %{conn: conn} do
    {:ok, live, _html} = live(conn, "/cfg/devices/versions")

    publish(%{
      "cc:cc:cc:cc:cc:03" => %{"ip" => {10, 0, 0, 13}, "sox" => 2, "type" => "7777-flex"}
    })

    assert render(live) =~ "unknown"
  end

  test "the page can ask every device what it runs", %{conn: conn} do
    {:ok, live, html} = live(conn, "/cfg/devices/versions")

    assert html =~ "Re-probe"

    publish(%{
      "cc:cc:cc:cc:cc:04" => %{"ip" => {10, 0, 0, 14}, "sox" => 2, "type" => "7777-flex"}
    })

    html = live |> element(~s(button[phx-click="refresh"])) |> render_click()
    assert html =~ "what they run"
  end
end