test: broader InfoLive rendering + PacketReplay update_filters branches
This commit is contained in:
parent
b8a2574415
commit
1b9743191a
2 changed files with 128 additions and 0 deletions
|
|
@ -279,6 +279,59 @@ defmodule Aprsme.PacketReplayTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "handle_call/3 extra branches" do
|
||||
setup do
|
||||
{:ok, state} = PacketReplay.init(user_id: "extra", bounds: [0, 0, 1, 1])
|
||||
|
||||
receive do
|
||||
:start_replay -> :ok
|
||||
after
|
||||
0 -> :ok
|
||||
end
|
||||
|
||||
{:ok, state: state}
|
||||
end
|
||||
|
||||
test "pause with no active timer flips paused flag", %{state: state} do
|
||||
state = %{state | replay_timer: nil}
|
||||
assert {:reply, :ok, new_state} = PacketReplay.handle_call(:pause, self(), state)
|
||||
assert new_state.paused
|
||||
assert is_nil(new_state.replay_timer)
|
||||
end
|
||||
|
||||
test "update_filters accepts valid bounds format", %{state: state} do
|
||||
filters = [bounds: [-74.0, 40.0, -73.0, 41.0]]
|
||||
|
||||
assert {:reply, :ok, new_state} =
|
||||
PacketReplay.handle_call({:update_filters, filters}, self(), state)
|
||||
|
||||
assert new_state.bounds == [-74.0, 40.0, -73.0, 41.0]
|
||||
end
|
||||
|
||||
test "update_filters with nil bounds keeps existing", %{state: state} do
|
||||
filters = [bounds: nil]
|
||||
|
||||
assert {:reply, :ok, new_state} =
|
||||
PacketReplay.handle_call({:update_filters, filters}, self(), state)
|
||||
|
||||
# nil bounds → filter branch keeps the old bounds via state.bounds.
|
||||
# After Map.put, new_state.bounds is nil, then the guard checks
|
||||
# is_nil(bounds) and keeps new_state as-is (so bounds stays nil).
|
||||
assert is_nil(new_state.bounds) or new_state.bounds == state.bounds
|
||||
end
|
||||
|
||||
test "update_filters cancels an active timer", %{state: state} do
|
||||
timer = Process.send_after(self(), :noop, 60_000)
|
||||
state = %{state | replay_timer: timer}
|
||||
|
||||
assert {:reply, :ok, new_state} =
|
||||
PacketReplay.handle_call({:update_filters, [callsign: "X"]}, self(), state)
|
||||
|
||||
# Timer should be gone from state and cancelled.
|
||||
assert is_nil(new_state.replay_timer)
|
||||
end
|
||||
end
|
||||
|
||||
describe "handle_info(:start_replay, ...)" do
|
||||
test "broadcasts replay_started then stops when no matching packets" do
|
||||
{:ok, state} = PacketReplay.init(user_id: "empty_stream", bounds: [0, 0, 1, 1])
|
||||
|
|
|
|||
|
|
@ -231,6 +231,81 @@ defmodule AprsmeWeb.InfoLive.ShowFullRenderTest do
|
|||
assert Process.alive?(lv.pid)
|
||||
end
|
||||
|
||||
test "renders a packet with rich metadata (altitude, course, speed, comment, device)", %{
|
||||
conn: conn
|
||||
} do
|
||||
_packet =
|
||||
packet_fixture(%{
|
||||
sender: "RICH1",
|
||||
base_callsign: "RICH1",
|
||||
ssid: "0",
|
||||
received_at: DateTime.utc_now(),
|
||||
lat: Decimal.new("33.0"),
|
||||
lon: Decimal.new("-96.5"),
|
||||
has_position: true,
|
||||
altitude: 300.5,
|
||||
course: 90,
|
||||
speed: 25.0,
|
||||
comment: "Some comment text",
|
||||
device_identifier: "APRS",
|
||||
path: "WIDE1-1,WIDE2-2,K5ABC*"
|
||||
})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/info/RICH1", on_error: :warn)
|
||||
assert html =~ "RICH1"
|
||||
assert html =~ "Some comment text"
|
||||
end
|
||||
|
||||
test "renders a packet with an object_name", %{conn: conn} do
|
||||
_packet =
|
||||
packet_fixture(%{
|
||||
sender: "OBJSRC",
|
||||
base_callsign: "OBJSRC",
|
||||
ssid: "0",
|
||||
received_at: DateTime.utc_now(),
|
||||
lat: Decimal.new("33.0"),
|
||||
lon: Decimal.new("-96.5"),
|
||||
has_position: true,
|
||||
object_name: "K5SGD",
|
||||
data_type: "object",
|
||||
path: "WIDE1-1"
|
||||
})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/info/OBJSRC", on_error: :warn)
|
||||
assert html =~ "OBJSRC"
|
||||
end
|
||||
|
||||
test "renders when the station has other SSIDs active", %{conn: conn} do
|
||||
now = DateTime.utc_now()
|
||||
|
||||
_p1 =
|
||||
packet_fixture(%{
|
||||
sender: "MULTI-1",
|
||||
base_callsign: "MULTI",
|
||||
ssid: "1",
|
||||
received_at: now,
|
||||
lat: Decimal.new("33.0"),
|
||||
lon: Decimal.new("-96.5"),
|
||||
has_position: true,
|
||||
path: "WIDE1-1"
|
||||
})
|
||||
|
||||
_p2 =
|
||||
packet_fixture(%{
|
||||
sender: "MULTI-2",
|
||||
base_callsign: "MULTI",
|
||||
ssid: "2",
|
||||
received_at: DateTime.add(now, -60, :second),
|
||||
lat: Decimal.new("33.1"),
|
||||
lon: Decimal.new("-96.6"),
|
||||
has_position: true,
|
||||
path: "WIDE1-1"
|
||||
})
|
||||
|
||||
{:ok, _lv, html} = live(conn, ~p"/info/MULTI-1", on_error: :warn)
|
||||
assert html =~ "MULTI-1"
|
||||
end
|
||||
|
||||
test "posts a postgres_packet broadcast to InfoLive.Show without crashing", %{conn: conn} do
|
||||
_packet =
|
||||
packet_fixture(%{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue