From c264a9bc3da28e899a66c34eadcc0c1cad8ec11f Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 24 Apr 2026 08:32:28 -0500 Subject: [PATCH] test: HistoricalLoader RF path + low-zoom heat map paths --- .../live/map_live/historical_loader_test.exs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/aprsme_web/live/map_live/historical_loader_test.exs b/test/aprsme_web/live/map_live/historical_loader_test.exs index 811f140..8f8a192 100644 --- a/test/aprsme_web/live/map_live/historical_loader_test.exs +++ b/test/aprsme_web/live/map_live/historical_loader_test.exs @@ -312,6 +312,83 @@ defmodule AprsmeWeb.MapLive.HistoricalLoaderTest do end end + describe "tracking a callsign drives maybe_include_latest_packet and RF path loading" do + test "first batch with a tracked callsign + packets triggers RF path scheduling" do + now = DateTime.utc_now() + + Mox.stub(Aprsme.PacketsMock, :get_recent_packets, fn _opts -> + [ + %{ + id: "rf-1", + sender: "RFME-1", + base_callsign: "RFME", + ssid: "1", + lat: 33.5, + lon: -96.5, + has_position: true, + symbol_table_id: "/", + symbol_code: ">", + received_at: now, + path: "K5ABC-1*,WIDE1-1" + } + ] + end) + + socket = + build_socket(%{ + map_bounds: %{north: 34.0, south: 32.0, east: -95.0, west: -97.0}, + map_zoom: 10, + tracked_callsign: "RFME-1", + historical_loading: true, + loading_generation: 1 + }) + + _ = HistoricalLoader.load_historical_batch(socket, 0, nil) + # RF path scheduling sends a :load_rf_path_station_packets after 100ms. + # Wait a bit, then check the mailbox. + Process.sleep(120) + assert_received {:load_rf_path_station_packets, _stations} + end + end + + describe "low zoom with packets path" do + test "low zoom accumulates historical_packets without pushing markers" do + now = DateTime.utc_now() + + Mox.stub(Aprsme.PacketsMock, :get_recent_packets, fn _opts -> + [ + %{ + id: "lz-1", + sender: "LZ1", + base_callsign: "LZ", + ssid: "1", + lat: 33.5, + lon: -96.5, + has_position: true, + symbol_table_id: "/", + symbol_code: ">", + received_at: now, + path: "" + } + ] + end) + + socket = + build_socket(%{ + map_bounds: %{north: 34.0, south: 32.0, east: -95.0, west: -97.0}, + # zoom <= 8 uses heat map path. + map_zoom: 5, + historical_loading: true, + loading_generation: 1, + total_batches: 3 + }) + + result = HistoricalLoader.load_historical_batch(socket, 0, nil) + # Packet should be merged into historical_packets map. + assert map_size(result.assigns.historical_packets) >= 1 + end + end + describe "max packets-for-zoom limit" do test "finishes loading when batch_offset * batch_size exceeds zoom limit" do # At zoom 10, limit=1500, batch_size=500. A batch_offset of 3 exceeds