defmodule AprsmeWeb.MapLive.IntegrationTest do use AprsmeWeb.ConnCase import Aprsme.PacketsFixtures import Phoenix.LiveViewTest describe "MapLive.Index with real packet data" do test "renders a map with pre-existing packets and simulates bounds_changed", %{conn: conn} do # Seed some packets in the bounds we'll scroll to. now = DateTime.utc_now() for i <- 1..3 do packet_fixture(%{ sender: "INT#{i}", base_callsign: "INT#{i}", ssid: "0", received_at: DateTime.add(now, -i * 60, :second), lat: Decimal.new("#{40 + i * 0.01}"), lon: Decimal.new("#{-74 - i * 0.01}"), has_position: true, path: "WIDE1-1" }) end {:ok, view, _html} = live(conn, "/?lat=40.0&lng=-74.0&z=11", on_error: :warn) # Fire a bounds_changed event covering the seeded region. bounds = %{ "bounds" => %{ "north" => 41.0, "south" => 39.5, "east" => -73.0, "west" => -74.5 } } assert render_hook(view, "bounds_changed", bounds) assert render_hook(view, "map_ready", %{}) # Allow async historical loading to run. Process.sleep(100) html = render(view) assert html =~ "aprs-map" end test "tracks a callsign that has a real packet", %{conn: conn} do _packet = packet_fixture(%{ sender: "TRACKME", base_callsign: "TRACKME", ssid: "0", received_at: DateTime.utc_now(), lat: Decimal.new("33.0"), lon: Decimal.new("-96.5"), has_position: true, path: "WIDE1-1" }) {:ok, view, _html} = live(conn, "/?call=TRACKME", on_error: :warn) assert render_hook(view, "map_ready", %{}) Process.sleep(100) html = render(view) assert html =~ "TRACKME" or html =~ "aprs-map" end test "callsign path route loads the tracked callsign", %{conn: conn} do _packet = packet_fixture(%{ sender: "PATH1", base_callsign: "PATH1", ssid: "0", received_at: DateTime.utc_now(), lat: Decimal.new("35.0"), lon: Decimal.new("-90.0"), has_position: true, path: "WIDE1-1" }) {:ok, _view, html} = live(conn, "/PATH1", on_error: :warn) assert html =~ "aprs-map" end test "spatial_packet arriving for an in-bounds callsign triggers display", %{conn: conn} do {:ok, view, _html} = live(conn, "/?lat=33.0&lng=-96.0&z=12", on_error: :warn) render_hook(view, "bounds_changed", %{ "bounds" => %{ "north" => 34.0, "south" => 32.0, "east" => -95.0, "west" => -97.0 } }) packet = %{ id: "sp-1", sender: "SP-1", base_callsign: "SP", ssid: "1", lat: 33.0, lon: -96.0, has_position: true, symbol_table_id: "/", symbol_code: ">", received_at: DateTime.utc_now(), path: "WIDE1-1", comment: "in bounds" } send(view.pid, {:spatial_packet, packet}) Process.sleep(50) assert render(view) =~ "aprs-map" end test "handles a batch of packets including out-of-bounds ones", %{conn: conn} do {:ok, view, _html} = live(conn, "/?lat=33.0&lng=-96.0&z=12", on_error: :warn) render_hook(view, "bounds_changed", %{ "bounds" => %{ "north" => 34.0, "south" => 32.0, "east" => -95.0, "west" => -97.0 } }) packets = [ %{ id: "b-1", sender: "IN-1", base_callsign: "IN", ssid: "1", lat: 33.5, lon: -96.0, has_position: true, symbol_table_id: "/", symbol_code: ">", received_at: DateTime.utc_now(), path: "" }, %{ id: "b-2", sender: "OUT-1", base_callsign: "OUT", ssid: "1", lat: 50.0, lon: -80.0, has_position: true, symbol_table_id: "/", symbol_code: ">", received_at: DateTime.utc_now(), path: "" } ] send(view.pid, {:packet_batch, packets}) Process.sleep(50) assert render(view) =~ "aprs-map" end end end