fix(weather): use Map.get for fallback comment access; add WeatherLive render tests
This commit is contained in:
parent
031b56fa7e
commit
6f142a7391
2 changed files with 66 additions and 1 deletions
|
|
@ -182,7 +182,7 @@
|
||||||
</dl>
|
</dl>
|
||||||
<div class="mt-2 text-xs text-gray-500 dark:text-gray-400">
|
<div class="mt-2 text-xs text-gray-500 dark:text-gray-400">
|
||||||
<strong>{gettext("Raw comment")}:</strong> {@weather_packet.comment ||
|
<strong>{gettext("Raw comment")}:</strong> {@weather_packet.comment ||
|
||||||
@weather_packet["comment"]}
|
Map.get(@weather_packet, "comment")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,71 @@ defmodule AprsmeWeb.WeatherLive.CallsignViewTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "mount with existing weather packet" do
|
||||||
|
import Aprsme.PacketsFixtures
|
||||||
|
|
||||||
|
test "renders weather data when a weather packet exists", %{conn: conn} do
|
||||||
|
_p =
|
||||||
|
packet_fixture(%{
|
||||||
|
sender: "WXSTA-1",
|
||||||
|
base_callsign: "WXSTA",
|
||||||
|
ssid: "1",
|
||||||
|
received_at: DateTime.utc_now(),
|
||||||
|
lat: Decimal.new("33.0"),
|
||||||
|
lon: Decimal.new("-96.0"),
|
||||||
|
has_position: true,
|
||||||
|
has_weather: true,
|
||||||
|
data_type: "weather",
|
||||||
|
temperature: 72.5,
|
||||||
|
humidity: 55,
|
||||||
|
pressure: 1013.0,
|
||||||
|
wind_speed: 5.5,
|
||||||
|
wind_direction: 180,
|
||||||
|
wind_gust: 10.0,
|
||||||
|
rain_1h: 0.0,
|
||||||
|
rain_24h: 0.25,
|
||||||
|
rain_since_midnight: 0.1,
|
||||||
|
comment: "A brief note"
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, _lv, html} = live(conn, ~p"/weather/WXSTA-1", on_error: :warn)
|
||||||
|
assert html =~ "WXSTA-1"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "broadcast of new weather packet for tracked callsign updates the view", %{conn: conn} do
|
||||||
|
_p =
|
||||||
|
packet_fixture(%{
|
||||||
|
sender: "WXTRK-1",
|
||||||
|
base_callsign: "WXTRK",
|
||||||
|
ssid: "1",
|
||||||
|
received_at: DateTime.add(DateTime.utc_now(), -3600, :second),
|
||||||
|
lat: Decimal.new("33.0"),
|
||||||
|
lon: Decimal.new("-96.0"),
|
||||||
|
has_weather: true,
|
||||||
|
temperature: 70.0,
|
||||||
|
humidity: 50
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, lv, _html} = live(conn, ~p"/weather/WXTRK-1", on_error: :warn)
|
||||||
|
|
||||||
|
# Newer packet for the SAME callsign with weather data — should trigger update.
|
||||||
|
new_packet = %{
|
||||||
|
sender: "WXTRK-1",
|
||||||
|
received_at: DateTime.utc_now(),
|
||||||
|
temperature: 72.0,
|
||||||
|
humidity: 55,
|
||||||
|
pressure: 1015.0,
|
||||||
|
wind_speed: 3,
|
||||||
|
wind_direction: 90,
|
||||||
|
rain_1h: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
send(lv.pid, {:postgres_packet, new_packet})
|
||||||
|
Process.sleep(50)
|
||||||
|
assert Process.alive?(lv.pid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "live packet broadcast handling" do
|
describe "live packet broadcast handling" do
|
||||||
test "ignores non-matching postgres_packet broadcasts", %{conn: conn} do
|
test "ignores non-matching postgres_packet broadcasts", %{conn: conn} do
|
||||||
{:ok, lv, _html} = live(conn, ~p"/weather/OWNCALL", on_error: :warn)
|
{:ok, lv, _html} = live(conn, ~p"/weather/OWNCALL", on_error: :warn)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue