Eliminates the external wgrib2 C tool dependency that blocked HRRR processing. Implements Lambert Conformal projection, simple packing (Template 5.0), complex packing with spatial differencing (Template 5.3), and GRIB2 section parsing — enough to extract point values from HRRR grid data using only Elixir.
97 lines
2.5 KiB
Elixir
97 lines
2.5 KiB
Elixir
defmodule MicrowavepropWeb.SubmitLiveTest do
|
|
use MicrowavepropWeb.ConnCase, async: true
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
alias Microwaveprop.Radio.Qso
|
|
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 QSO"
|
|
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("#qso-form", qso: %{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("#qso-form",
|
|
qso: %{
|
|
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()
|
|
|
|
qso = Repo.one!(Qso)
|
|
assert qso.station1 == "W5XD"
|
|
assert qso.user_submitted == true
|
|
assert qso.pos1["lat"]
|
|
|
|
assert_redirect(lv, ~p"/qsos/#{qso.id}")
|
|
end
|
|
|
|
test "shows errors on invalid submit", %{conn: conn} do
|
|
{:ok, lv, _html} = live(conn, ~p"/submit")
|
|
|
|
html =
|
|
lv
|
|
|> form("#qso-form", qso: %{station1: ""})
|
|
|> render_submit()
|
|
|
|
assert html =~ "can't be blank"
|
|
end
|
|
end
|
|
end
|