diff --git a/test/aprsme_web/live/map_live/integration_test.exs b/test/aprsme_web/live/map_live/integration_test.exs index 28b0191..1375514 100644 --- a/test/aprsme_web/live/map_live/integration_test.exs +++ b/test/aprsme_web/live/map_live/integration_test.exs @@ -756,6 +756,107 @@ defmodule AprsmeWeb.MapLive.IntegrationTest do assert render_hook(view, "clear_and_reload_markers", %{}) end + test ":initialize_replay reschedules itself when map_bounds is nil", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + render_hook(view, "map_ready", %{}) + + # Force map_bounds to nil so handle_info_initialize_replay hits the + # else-branch (line 1042) that schedules :initialize_replay later. + :sys.replace_state(view.pid, fn channel_state -> + inner_socket = channel_state.socket + + new_socket = %{ + inner_socket + | assigns: + inner_socket.assigns + |> Map.put(:map_bounds, nil) + |> Map.put(:historical_loaded, false) + } + + %{channel_state | socket: new_socket} + end) + + send(view.pid, :initialize_replay) + Process.sleep(20) + assert render(view) =~ "aprs-map" + end + + test "process_bounds_update with out-of-bounds visible_packets exercises remove_markers_batch", %{conn: conn} do + {:ok, view, _html} = live(conn, "/?lat=33.0&lng=-96.0&z=10", on_error: :warn) + render_hook(view, "map_ready", %{}) + + # Seed visible_packets with packets outside the next-bounds region. + visible = %{ + "FAR-0" => %{ + sender: "FAR", + base_callsign: "FAR", + ssid: "0", + lat: 60.0, + lon: -120.0, + has_position: true, + received_at: DateTime.utc_now() + }, + "ALSO-0" => %{ + sender: "ALSO", + base_callsign: "ALSO", + ssid: "0", + lat: 70.0, + lon: -130.0, + has_position: true, + received_at: DateTime.utc_now() + } + } + + :sys.replace_state(view.pid, fn channel_state -> + inner_socket = channel_state.socket + + new_socket = %{ + inner_socket + | assigns: + inner_socket.assigns + |> Map.put(:visible_packets, visible) + |> Map.put(:initial_bounds_loaded, true) + } + + %{channel_state | socket: new_socket} + end) + + # Send bounds that exclude the seeded packets — process_bounds_update + # should call remove_markers_batch with all of them as marker_ids. + send(view.pid, {:process_bounds_update, %{north: 34.0, south: 32.0, east: -95.0, west: -97.0}}) + Process.sleep(50) + assert render(view) =~ "aprs-map" + end + + test "{:load_rf_path_station_packets, _} with seeded packets builds and adds markers", %{conn: conn} do + packet_fixture(%{ + sender: "RFST1", + base_callsign: "RFST1", + ssid: "0", + received_at: DateTime.utc_now(), + lat: Decimal.new("33.0"), + lon: Decimal.new("-96.0"), + has_position: true, + path: "" + }) + + packet_fixture(%{ + sender: "RFST2", + base_callsign: "RFST2", + ssid: "0", + received_at: DateTime.utc_now(), + lat: Decimal.new("33.5"), + lon: Decimal.new("-96.5"), + has_position: true, + path: "" + }) + + {:ok, view, _html} = live(conn, "/?lat=33.0&lng=-96.0&z=12", on_error: :warn) + send(view.pid, {:load_rf_path_station_packets, ["RFST1", "RFST2"]}) + Process.sleep(50) + assert render(view) =~ "aprs-map" + end + test "{:packet_batch, _} at low zoom (untracked) triggers heat map branch", %{conn: conn} do {:ok, view, _html} = live(conn, "/?lat=33.0&lng=-96.0&z=6", on_error: :warn) render_hook(view, "map_ready", %{})