From 3c1ea5418406498655e975aac22b6fc10ffbc874 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 8 May 2026 13:33:13 -0500 Subject: [PATCH] Add coverage tests for HistoricalLoader low-zoom non-final and pending-bounds paths --- .../live/map_live/historical_loader_test.exs | 60 +++++++++++++++++++ 1 file changed, 60 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 e5a8217..696c50a 100644 --- a/test/aprsme_web/live/map_live/historical_loader_test.exs +++ b/test/aprsme_web/live/map_live/historical_loader_test.exs @@ -658,6 +658,66 @@ defmodule AprsmeWeb.MapLive.HistoricalLoaderTest do end end + describe "low zoom non-final batch returns socket without heat map" do + test "saturated low-zoom batch at offset 0 hits the non-final branch (line 368)" do + now = DateTime.utc_now() + # zoom 5 → batch_size 75. Return >= 75 packets so has_more = true. + packets = + for i <- 1..80 do + %{ + id: "lz-final-#{i}", + sender: "LZF-#{i}", + base_callsign: "LZF", + ssid: "1", + lat: 33.0 + i * 0.001, + lon: -96.0 + i * 0.001, + has_position: true, + symbol_table_id: "/", + symbol_code: ">", + received_at: DateTime.add(now, -i, :second), + path: "" + } + end + + Mox.stub(Aprsme.PacketsMock, :get_recent_packets, fn _opts -> packets end) + + socket = + build_socket(%{ + map_bounds: %{north: 34.0, south: 32.0, east: -95.0, west: -97.0}, + map_zoom: 5, + historical_loading: true, + loading_generation: 1, + total_batches: 5 + }) + + result = HistoricalLoader.load_historical_batch(socket, 0, nil) + # Saturated + total_batches >= 5 → non-final → handle_zoom_based_display + # with is_final_batch=false hits the else-branch returning socket. + assert is_map(result.assigns) + end + end + + describe "finish_historical_loading with pending_bounds set" do + test "sends :process_pending_bounds when pending_bounds is non-nil" do + socket = + build_socket(%{ + map_bounds: %{north: 34.0, south: 32.0, east: -95.0, west: -97.0}, + map_zoom: 10, + historical_loading: true, + loading_generation: 1, + total_batches: 4, + pending_bounds: %{north: 1.0, south: 0.0, east: 1.0, west: 0.0} + }) + + # batch_offset 3 with limit-1500 (zoom 10) and batch_size 500 → + # packets_so_far = 3 * 500 = 1500 ≥ max → finish_historical_loading. + result = HistoricalLoader.load_historical_batch(socket, 3, nil) + refute result.assigns.historical_loading + # process_pending_bounds was sent. + assert_received {:process_pending_bounds} + end + end + describe "schedules next batch when not final" do test "saturated batch with more rows triggers maybe_schedule_next_batch" do now = DateTime.utc_now()