prop/test/microwaveprop_web/live/submit_live_test.exs
Graham McIntire 254e64dedc
Rename qsos to contacts throughout codebase, keep DB table name
Rename all modules, functions, variables, routes, and UI text from
qso/qsos to contact/contacts. Database table stays as "qsos" to avoid
migration. Add /qsos -> /contacts redirects for old URLs.
2026-04-01 11:25:04 -05:00

97 lines
2.5 KiB
Elixir

defmodule MicrowavepropWeb.SubmitLiveTest do
use MicrowavepropWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Microwaveprop.Radio.Contact
alias Microwaveprop.Repo
alias Microwaveprop.Terrain.ElevationClient
alias Microwaveprop.Weather.HrrrClient
alias Microwaveprop.Weather.IemClient
setup do
Req.Test.stub(IemClient, fn conn ->
case conn.request_path do
"/cgi-bin/request/asos.py" -> Req.Test.text(conn, "#DEBUG,\nstation,valid,tmpf\n")
_ -> Req.Test.json(conn, %{"profiles" => []})
end
end)
Req.Test.stub(HrrrClient, fn conn ->
Plug.Conn.send_resp(conn, 404, "not found")
end)
Req.Test.stub(ElevationClient, fn conn ->
params = Plug.Conn.fetch_query_params(conn).query_params
lat_count = params["latitude"] |> String.split(",") |> length()
Req.Test.json(conn, %{"elevation" => List.duplicate(200.0, lat_count)})
end)
:ok
end
describe "mount" do
test "renders the submission form", %{conn: conn} do
{:ok, _lv, html} = live(conn, ~p"/submit")
assert html =~ "Submit Contact"
assert html =~ "Station 1"
assert html =~ "Station 2"
assert html =~ "Grid 1"
assert html =~ "Grid 2"
assert html =~ "Band"
assert html =~ "Mode"
end
end
describe "validate" do
test "shows validation errors on change", %{conn: conn} do
{:ok, lv, _html} = live(conn, ~p"/submit")
html =
lv
|> form("#contact-form", contact: %{station1: ""})
|> render_change()
assert html =~ "can't be blank"
end
end
describe "save" do
test "creates QSO and redirects on valid submit", %{conn: conn} do
{:ok, lv, _html} = live(conn, ~p"/submit")
lv
|> form("#contact-form",
contact: %{
station1: "W5XD",
station2: "K5TR",
qso_timestamp: "2026-03-28T18:00",
mode: "CW",
band: "1296",
grid1: "EM12",
grid2: "EM00",
submitter_email: "test@example.com"
}
)
|> render_submit()
contact = Repo.one!(Contact)
assert contact.station1 == "W5XD"
assert contact.user_submitted == true
assert contact.pos1["lat"]
assert_redirect(lv, ~p"/contacts/#{contact.id}")
end
test "shows errors on invalid submit", %{conn: conn} do
{:ok, lv, _html} = live(conn, ~p"/submit")
html =
lv
|> form("#contact-form", contact: %{station1: ""})
|> render_submit()
assert html =~ "can't be blank"
end
end
end