Renames the rover-location status enum and every label that referenced it. Existing rows are migrated in place. Also touches the consumers: - Rover.Location enum + default - RoverLocationsLive index, status filter, form, show, badges - Rover.Compute and rover_live (only_ideal_locations → only_good_locations) - RoverPlanning context candidate filter (status == :good) - RoverPlanning.Show / Form copy - All rover-related tests
115 lines
3.6 KiB
Elixir
115 lines
3.6 KiB
Elixir
defmodule MicrowavepropWeb.RoverPlanningLiveTest do
|
|
use MicrowavepropWeb.ConnCase, async: true
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
alias Microwaveprop.AccountsFixtures
|
|
alias Microwaveprop.Rover
|
|
alias Microwaveprop.RoverPlanning
|
|
alias Microwaveprop.Terrain.ElevationClient
|
|
|
|
setup do
|
|
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
|
|
|
|
defp create_mission(user, name) do
|
|
{:ok, _} = Rover.create_location(user, %{lat: 32.0, lon: -97.0, status: :good})
|
|
|
|
{:ok, mission} =
|
|
RoverPlanning.create_mission(user, %{
|
|
"name" => name,
|
|
"band_mhz" => 10_000,
|
|
"only_known_good" => true,
|
|
"rover_height_ft" => 8.0,
|
|
"station_height_ft" => 30.0,
|
|
"stations" => %{"0" => %{"input" => "EM12kp", "position" => 0}}
|
|
})
|
|
|
|
mission
|
|
end
|
|
|
|
describe "index" do
|
|
test "anonymous visitor sees the table and a sign-in prompt", %{conn: conn} do
|
|
{:ok, _lv, html} = live(conn, ~p"/rover-planning")
|
|
assert html =~ "Rover Planning"
|
|
assert html =~ "Sign in"
|
|
end
|
|
|
|
test "logged-in user sees the New mission button", %{conn: conn} do
|
|
user = AccountsFixtures.user_fixture()
|
|
conn = log_in_user(conn, user)
|
|
{:ok, _lv, html} = live(conn, ~p"/rover-planning")
|
|
assert html =~ "New mission"
|
|
end
|
|
|
|
test "table shows existing missions and links to the show page", %{conn: conn} do
|
|
user = AccountsFixtures.user_fixture()
|
|
mission = create_mission(user, "Visible mission")
|
|
|
|
{:ok, _lv, html} = live(conn, ~p"/rover-planning")
|
|
assert html =~ "Visible mission"
|
|
assert html =~ ~s(href="/rover-planning/#{mission.id}")
|
|
end
|
|
end
|
|
|
|
describe "show" do
|
|
test "renders mission details + path table", %{conn: conn} do
|
|
user = AccountsFixtures.user_fixture()
|
|
mission = create_mission(user, "Detail mission")
|
|
|
|
{:ok, _lv, html} = live(conn, ~p"/rover-planning/#{mission.id}")
|
|
assert html =~ "Detail mission"
|
|
assert html =~ "Stationary stations"
|
|
assert html =~ "Path profiles"
|
|
end
|
|
|
|
test "redirects when mission missing", %{conn: conn} do
|
|
missing = Ecto.UUID.generate()
|
|
|
|
assert {:error, {:live_redirect, %{to: "/rover-planning"}}} =
|
|
live(conn, ~p"/rover-planning/#{missing}")
|
|
end
|
|
end
|
|
|
|
describe "form" do
|
|
test "anonymous user gets redirected to /rover-planning", %{conn: conn} do
|
|
assert {:error, {:live_redirect, %{to: "/rover-planning"}}} =
|
|
live(conn, ~p"/rover-planning/new")
|
|
end
|
|
|
|
test "logged-in user can create a mission with a callsign-input station",
|
|
%{conn: conn} do
|
|
user = AccountsFixtures.user_fixture()
|
|
{:ok, _} = Rover.create_location(user, %{lat: 32.0, lon: -97.0, status: :good})
|
|
conn = log_in_user(conn, user)
|
|
|
|
{:ok, lv, html} = live(conn, ~p"/rover-planning/new")
|
|
assert html =~ "Only check against known good locations"
|
|
assert html =~ ~s(checked)
|
|
|
|
{:error, {:live_redirect, %{to: redirect_to}}} =
|
|
lv
|
|
|> form("#mission-form",
|
|
mission: %{
|
|
name: "From form",
|
|
band_mhz: "10000",
|
|
only_known_good: "true",
|
|
rover_height_ft: "8.0",
|
|
station_height_ft: "30.0",
|
|
stations: %{
|
|
"0" => %{input: "EM12kp"}
|
|
}
|
|
}
|
|
)
|
|
|> render_submit()
|
|
|
|
assert redirect_to =~ ~r{^/rover-planning/[0-9a-f-]+$}
|
|
end
|
|
end
|
|
end
|