From 3eec54439b09073b2f014b9a6a53e54bb7de47cc Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 23 Apr 2026 17:05:58 -0500 Subject: [PATCH] test: add MapLive.Index zoom threshold and tracking tests --- test/aprsme_web/live/map_live/index_test.exs | 83 ++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/test/aprsme_web/live/map_live/index_test.exs b/test/aprsme_web/live/map_live/index_test.exs index b572b9a..ab7459d 100644 --- a/test/aprsme_web/live/map_live/index_test.exs +++ b/test/aprsme_web/live/map_live/index_test.exs @@ -445,4 +445,87 @@ defmodule AprsmeWeb.MapLive.IndexTest do assert html =~ "K5ABC" or html =~ "aprs-map" end end + + describe "MapLive.Index zoom and map state changes" do + test "update_map_state crossing heat map threshold (high → low zoom)", %{conn: conn} do + {:ok, view, _html} = live(conn, "/?lat=40.5&lng=-98.5&z=10", on_error: :warn) + + # Drop from zoom 10 → 6 — crosses the zoom-8 heat-map threshold. + assert render_hook(view, "update_map_state", %{ + "center" => %{"lat" => 40.5, "lng" => -98.5}, + "zoom" => 6 + }) + end + + test "update_map_state crossing heat map threshold (low → high zoom)", %{conn: conn} do + {:ok, view, _html} = live(conn, "/?lat=40.5&lng=-98.5&z=5", on_error: :warn) + + # Jump from zoom 5 → 12 — crosses the threshold in the other direction. + assert render_hook(view, "update_map_state", %{ + "center" => %{"lat" => 40.5, "lng" => -98.5}, + "zoom" => 12 + }) + end + + test "update_map_state with string zoom value", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + + assert render_hook(view, "update_map_state", %{ + "center" => %{"lat" => "40.5", "lng" => "-98.5"}, + "zoom" => "10" + }) + end + + test "update_map_state clamps extreme zoom values", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + + assert render_hook(view, "update_map_state", %{ + "center" => %{"lat" => 0.0, "lng" => 0.0}, + "zoom" => 99 + }) + end + + test "bounds_changed with very zoomed-in bounds", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + + assert render_hook(view, "bounds_changed", %{ + "bounds" => %{ + "north" => 40.75, + "south" => 40.74, + "east" => -73.98, + "west" => -73.99 + } + }) + end + end + + describe "MapLive.Index tracking flow" do + test "track_callsign with whitespace trims and uppercases", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + # Mixed case + whitespace — should be normalized. + assert render_hook(view, "track_callsign", %{"callsign" => " k5abc "}) + end + + test "clear_tracking works after starting tracking", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + render_hook(view, "track_callsign", %{"callsign" => "W1XYZ"}) + assert render_hook(view, "clear_tracking", %{}) + end + + test "update_trail_duration with various values", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + + for dur <- ["1", "2", "6", "12", "24"] do + assert render_hook(view, "update_trail_duration", %{"trail_duration" => dur}) + end + end + + test "update_historical_hours with various values", %{conn: conn} do + {:ok, view, _html} = live(conn, "/", on_error: :warn) + + for hrs <- ["1", "2", "6", "12", "24"] do + assert render_hook(view, "update_historical_hours", %{"historical_hours" => hrs}) + end + end + end end