add comment on info page

This commit is contained in:
Graham McIntire 2025-07-12 09:47:09 -05:00
parent ad88e34ab6
commit 68f0e77f37
No known key found for this signature in database
2 changed files with 82 additions and 0 deletions

View file

@ -127,6 +127,18 @@
<dd class="mt-1 text-sm font-semibold">{@packet.speed} MPH</dd>
</div>
<% end %>
<%= if @packet.comment do %>
<div class="col-span-2">
<dt class="text-xs font-medium opacity-70">{gettext("Comment")}</dt>
<dd class="mt-1 text-sm">
<%= if is_binary(@packet.comment) do %>
{Aprsme.EncodingUtils.sanitize_string(@packet.comment)}
<% else %>
{@packet.comment}
<% end %>
</dd>
</div>
<% end %>
</dl>
</div>
</div>

View file

@ -0,0 +1,70 @@
defmodule AprsmeWeb.InfoLiveTest do
use AprsmeWeb.ConnCase
import Phoenix.LiveViewTest
alias Aprsme.Packet
alias Aprsme.Repo
describe "show" do
test "displays comment field when packet has comment", %{conn: conn} do
{:ok, packet} =
Repo.insert(%Packet{
sender: "TEST-1",
base_callsign: "TEST",
ssid: "1",
lat: Decimal.new("42.3601"),
lon: Decimal.new("-71.0589"),
comment: "Mobile station on the move",
received_at: DateTime.truncate(DateTime.utc_now(), :second),
has_position: true,
location: %Geo.Point{coordinates: {-71.0589, 42.3601}}
})
{:ok, _view, html} = live(conn, ~p"/info/#{packet.sender}")
assert html =~ "Comment"
assert html =~ "Mobile station on the move"
end
test "does not display comment field when packet has no comment", %{conn: conn} do
{:ok, packet} =
Repo.insert(%Packet{
sender: "TEST-2",
base_callsign: "TEST",
ssid: "2",
lat: Decimal.new("42.3601"),
lon: Decimal.new("-71.0589"),
comment: nil,
received_at: DateTime.truncate(DateTime.utc_now(), :second),
has_position: true,
location: %Geo.Point{coordinates: {-71.0589, 42.3601}}
})
{:ok, _view, html} = live(conn, ~p"/info/#{packet.sender}")
refute html =~ "Comment"
end
test "displays comment with special characters", %{conn: conn} do
{:ok, packet} =
Repo.insert(%Packet{
sender: "TEST-3",
base_callsign: "TEST",
ssid: "3",
lat: Decimal.new("42.3601"),
lon: Decimal.new("-71.0589"),
comment: "Test comment with special chars: & < > \"",
received_at: DateTime.truncate(DateTime.utc_now(), :second),
has_position: true,
location: %Geo.Point{coordinates: {-71.0589, 42.3601}}
})
{:ok, _view, html} = live(conn, ~p"/info/#{packet.sender}")
assert html =~ "Comment"
assert html =~ "Test comment with special chars"
# Phoenix will HTML encode special characters automatically
end
end
end