test: additional MapLive.Index handle_info + InfoLive path decoders

This commit is contained in:
Graham McIntire 2026-04-23 18:08:05 -05:00
parent 6777b61764
commit 5f64a43304
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
3 changed files with 117 additions and 0 deletions

View file

@ -111,6 +111,41 @@ defmodule AprsmeWeb.InfoLive.ShowFullRenderTest do
assert html =~ "WXONLY"
end
test "renders a station with a rich APRS path exercising decoders", %{conn: conn} do
_packet =
packet_fixture(%{
sender: "PATH2",
base_callsign: "PATH2",
ssid: "0",
received_at: DateTime.utc_now(),
lat: Decimal.new("30.0"),
lon: Decimal.new("-90.0"),
has_position: true,
# Mixes q-construct, WIDE, TRACE, RELAY, TCPIP, generic digi, and bare station.
path: "WIDE1-1,WIDE2-2,TRACE3-3,RELAY,TCPIP*,K5ABC-1,N0CALL,qAC"
})
{:ok, _lv, html} = live(conn, ~p"/info/PATH2", on_error: :warn)
assert html =~ "PATH2"
end
test "renders a station with a packet that has a nil path", %{conn: conn} do
_packet =
packet_fixture(%{
sender: "NOPATH",
base_callsign: "NOPATH",
ssid: "0",
received_at: DateTime.utc_now(),
lat: Decimal.new("30.0"),
lon: Decimal.new("-90.0"),
has_position: true,
path: nil
})
{:ok, _lv, html} = live(conn, ~p"/info/NOPATH", on_error: :warn)
assert html =~ "NOPATH"
end
test "posts a postgres_packet broadcast to InfoLive.Show without crashing", %{conn: conn} do
_packet =
packet_fixture(%{

View file

@ -166,6 +166,36 @@ defmodule AprsmeWeb.InfoLive.ShowHelpersTest do
end
end
describe "haversine/4 with Decimal input" do
test "handles Decimal-valued coordinates" do
result =
Show.haversine(
Decimal.new("40.0"),
Decimal.new("-100.0"),
Decimal.new("41.0"),
Decimal.new("-99.0")
)
assert is_float(result)
assert result > 0
end
end
describe "format_distance/2 rounding" do
test "rounds to 2 decimal places in metric mode" do
# 1.234567 km → "1.23 km"
assert Show.format_distance(1.234567, "fr") == "1.23 km"
end
test "0 km in metric mode prints 0 m" do
assert Show.format_distance(0.0, "de") == "0.0 m"
end
test "0 km in English mode prints 0 ft" do
assert Show.format_distance(0.0, "en") == "0.0 ft"
end
end
describe "position_changed_for_test/2" do
test "returns true when current packet is nil" do
assert Show.position_changed_for_test(nil, %{lat: 1.0, lon: 1.0})

View file

@ -606,6 +606,58 @@ defmodule AprsmeWeb.MapLive.IndexTest do
assert render(view) =~ "aprs-map"
end
test "handles drain_connections with small to_drain value", %{conn: conn} do
{:ok, view, _html} = live(conn, "/", on_error: :warn)
# to_drain * 10 << 100, likely no-op; still should keep process alive.
send(view.pid, {:drain_connections, 1})
Process.sleep(30)
assert Process.alive?(view.pid)
end
test "handles clear_rf_path via direct send", %{conn: conn} do
{:ok, view, _html} = live(conn, "/", on_error: :warn)
send(view.pid, :clear_rf_path)
Process.sleep(30)
assert Process.alive?(view.pid)
end
test "handles load_historical_batch with stale generation", %{conn: conn} do
{:ok, view, _html} = live(conn, "/", on_error: :warn)
# Send with a generation that probably doesn't match — should just be ignored.
send(view.pid, {:load_historical_batch, 0, 99_999})
Process.sleep(30)
assert Process.alive?(view.pid)
end
test "handles load_historical_batch with backward-compat 2-arg form", %{conn: conn} do
{:ok, view, _html} = live(conn, "/", on_error: :warn)
send(view.pid, {:load_historical_batch, 0})
Process.sleep(30)
assert Process.alive?(view.pid)
end
test "handles historical_loading_timeout with stale generation", %{conn: conn} do
{:ok, view, _html} = live(conn, "/", on_error: :warn)
send(view.pid, {:historical_loading_timeout, 99_999})
Process.sleep(30)
assert Process.alive?(view.pid)
end
test "handles process_pending_bounds with no pending", %{conn: conn} do
{:ok, view, _html} = live(conn, "/", on_error: :warn)
send(view.pid, {:process_pending_bounds})
Process.sleep(30)
assert Process.alive?(view.pid)
end
test "handles load_rf_path_station_packets with empty list", %{conn: conn} do
{:ok, view, _html} = live(conn, "/", on_error: :warn)
send(view.pid, {:load_rf_path_station_packets, []})
Process.sleep(30)
assert Process.alive?(view.pid)
end
test "handles postgres_packet broadcast via batcher", %{conn: conn} do
{:ok, view, _html} = live(conn, "/?lat=33.0&lng=-96.0&z=12", on_error: :warn)