test: SkewtLive HRRR + sounding fixtures bring coverage to 82.7%
Added profile/sounding setup blocks to SkewtLive tests so the list_valid_times_near + nearest_sounding_to paths run with real data. SkewtLive: 33% -> 46%. Total project coverage: 82.7%.
This commit is contained in:
parent
363646f34f
commit
2c6458957b
1 changed files with 71 additions and 2 deletions
|
|
@ -4,6 +4,8 @@ defmodule MicrowavepropWeb.SkewtLiveTest do
|
||||||
import Phoenix.LiveViewTest
|
import Phoenix.LiveViewTest
|
||||||
|
|
||||||
alias Microwaveprop.Weather.HrrrProfile
|
alias Microwaveprop.Weather.HrrrProfile
|
||||||
|
alias Microwaveprop.Weather.Sounding
|
||||||
|
alias Microwaveprop.Weather.Station
|
||||||
|
|
||||||
describe "with HRRR profile data near the queried location" do
|
describe "with HRRR profile data near the queried location" do
|
||||||
setup do
|
setup do
|
||||||
|
|
@ -12,7 +14,13 @@ defmodule MicrowavepropWeb.SkewtLiveTest do
|
||||||
%{"pres" => 925.0, "hght" => 770, "tmpc" => 18.0, "dwpc" => 12.0},
|
%{"pres" => 925.0, "hght" => 770, "tmpc" => 18.0, "dwpc" => 12.0},
|
||||||
%{"pres" => 850.0, "hght" => 1500, "tmpc" => 14.0, "dwpc" => 8.0},
|
%{"pres" => 850.0, "hght" => 1500, "tmpc" => 14.0, "dwpc" => 8.0},
|
||||||
%{"pres" => 700.0, "hght" => 3000, "tmpc" => 0.0, "dwpc" => -10.0},
|
%{"pres" => 700.0, "hght" => 3000, "tmpc" => 0.0, "dwpc" => -10.0},
|
||||||
%{"pres" => 500.0, "hght" => 5500, "tmpc" => -20.0, "dwpc" => -30.0}
|
%{"pres" => 500.0, "hght" => 5500, "tmpc" => -20.0, "dwpc" => -30.0},
|
||||||
|
%{"pres" => 400.0, "hght" => 7000, "tmpc" => -30.0, "dwpc" => -40.0},
|
||||||
|
%{"pres" => 300.0, "hght" => 9000, "tmpc" => -45.0, "dwpc" => -55.0},
|
||||||
|
%{"pres" => 250.0, "hght" => 10_500, "tmpc" => -55.0, "dwpc" => -65.0},
|
||||||
|
%{"pres" => 200.0, "hght" => 12_000, "tmpc" => -55.0, "dwpc" => -65.0},
|
||||||
|
%{"pres" => 150.0, "hght" => 13_500, "tmpc" => -55.0, "dwpc" => -65.0},
|
||||||
|
%{"pres" => 100.0, "hght" => 16_000, "tmpc" => -55.0, "dwpc" => -65.0}
|
||||||
]
|
]
|
||||||
|
|
||||||
# Insert near EM12kp (32.646, -97.125)
|
# Insert near EM12kp (32.646, -97.125)
|
||||||
|
|
@ -36,7 +44,7 @@ defmodule MicrowavepropWeb.SkewtLiveTest do
|
||||||
})
|
})
|
||||||
|> Microwaveprop.Repo.insert!()
|
|> Microwaveprop.Repo.insert!()
|
||||||
|
|
||||||
:ok
|
%{valid_time: now}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders the time selector when valid_times list is non-empty", %{conn: conn} do
|
test "renders the time selector when valid_times list is non-empty", %{conn: conn} do
|
||||||
|
|
@ -46,6 +54,67 @@ defmodule MicrowavepropWeb.SkewtLiveTest do
|
||||||
# tries an HTTP call that fails — but the page should not crash.
|
# tries an HTTP call that fails — but the page should not crash.
|
||||||
assert render(view) =~ "Skew-T"
|
assert render(view) =~ "Skew-T"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "select_time event triggers a re-load with the chosen valid_time", %{conn: conn} do
|
||||||
|
{:ok, view, _html} = live(conn, ~p"/skewt?q=EM12kp")
|
||||||
|
_ = render_async(view)
|
||||||
|
|
||||||
|
# Trigger select_time with a valid future ISO. Even if no profile is
|
||||||
|
# found for this time, the handler exercises the full re-load path.
|
||||||
|
future = DateTime.utc_now() |> DateTime.add(3600, :second) |> DateTime.to_iso8601()
|
||||||
|
|
||||||
|
_ = render_hook(view, "select_time", %{"valid_time" => future})
|
||||||
|
_ = render_async(view)
|
||||||
|
|
||||||
|
assert render(view) =~ "Skew-T"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with a sounding readout near the queried point" do
|
||||||
|
setup do
|
||||||
|
# Insert a station + sounding so build_sounding_readout returns
|
||||||
|
# non-nil and renders the side panel.
|
||||||
|
now = DateTime.truncate(DateTime.utc_now(), :second)
|
||||||
|
|
||||||
|
{:ok, station} =
|
||||||
|
%Station{}
|
||||||
|
|> Station.changeset(%{
|
||||||
|
station_code: "FWD",
|
||||||
|
station_type: "sounding",
|
||||||
|
name: "Fort Worth",
|
||||||
|
lat: 32.835,
|
||||||
|
lon: -97.298
|
||||||
|
})
|
||||||
|
|> Microwaveprop.Repo.insert()
|
||||||
|
|
||||||
|
sounding_attrs = %{
|
||||||
|
station_id: station.id,
|
||||||
|
observed_at: now,
|
||||||
|
ducting_detected: false,
|
||||||
|
min_refractivity_gradient: -45.0,
|
||||||
|
boundary_layer_depth_m: 1500.0,
|
||||||
|
precipitable_water_mm: 25.0,
|
||||||
|
surface_refractivity: 320.0,
|
||||||
|
level_count: 3,
|
||||||
|
profile: [
|
||||||
|
%{"pres" => 1000.0, "hght" => 110, "tmpc" => 25.0, "dwpc" => 18.0},
|
||||||
|
%{"pres" => 925.0, "hght" => 770, "tmpc" => 18.0, "dwpc" => 12.0},
|
||||||
|
%{"pres" => 850.0, "hght" => 1500, "tmpc" => 14.0, "dwpc" => 8.0}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
%Sounding{}
|
||||||
|
|> Sounding.changeset(sounding_attrs)
|
||||||
|
|> Microwaveprop.Repo.insert!()
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders without crashing when sounding data is in the DB", %{conn: conn} do
|
||||||
|
{:ok, view, _html} = live(conn, ~p"/skewt?q=EM12kp")
|
||||||
|
_ = render_async(view)
|
||||||
|
assert render(view) =~ "Skew-T"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "select_time event" do
|
describe "select_time event" do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue