prop/test/microwaveprop_web/live/rover_locations_live_test.exs
Graham McIntire 140351c0f6
feat(rover-locations): add /rover-locations page with CRUD
New globally-shared list of rover-friendly (or off-limits) parking
spots. Anyone can view; logged-in users can add new locations and
edit/delete their own. Each location stores lat/lon, free-text notes,
and a status enum (:ideal | :off_limits).

  * Microwaveprop.Rover.Location schema + migration
  * Rover.list_locations/0, create_location/2, update_location/3,
    delete_location/2 (mutations require User; ownership-scoped)
  * /rover-locations LiveView in the public live_session — Add button
    is disabled for anonymous visitors, Edit/Delete buttons render
    only on the user's own entries
  * Tests for context + LiveView covering anonymous read, owner-only
    edit/delete, and form submission
2026-04-26 13:08:27 -05:00

71 lines
2.1 KiB
Elixir

defmodule MicrowavepropWeb.RoverLocationsLiveTest do
use MicrowavepropWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Microwaveprop.Rover
describe "anonymous visitor" do
test "can view the locations page", %{conn: conn} do
{:ok, _lv, html} = live(conn, ~p"/rover-locations")
assert html =~ "Rover Locations"
assert html =~ "Sign in"
end
test "shows existing locations from any user", %{conn: conn} do
user = Microwaveprop.AccountsFixtures.user_fixture()
{:ok, _} =
Rover.create_location(user, %{
lat: 32.5,
lon: -97.5,
status: :ideal,
notes: "great hill"
})
{:ok, _lv, html} = live(conn, ~p"/rover-locations")
assert html =~ "Ideal"
assert html =~ "great hill"
end
test "Add button is disabled for anonymous users", %{conn: conn} do
{:ok, _lv, html} = live(conn, ~p"/rover-locations")
assert html =~ ~s(disabled)
assert html =~ "Add location"
end
end
describe "logged-in user" do
setup :register_and_log_in_user
test "can add a new location", %{conn: conn} do
{:ok, lv, _html} = live(conn, ~p"/rover-locations")
lv |> element("button", "+ Add location") |> render_click()
lv
|> form("#location-form",
location: %{lat: "32.5", lon: "-97.5", status: "ideal", notes: "test note"}
)
|> render_submit()
html = render(lv)
assert html =~ "test note"
end
test "can edit and delete only their own location", %{conn: conn, user: user} do
other = Microwaveprop.AccountsFixtures.user_fixture()
{:ok, mine} = Rover.create_location(user, %{lat: 32.0, lon: -97.0, status: :ideal})
{:ok, theirs} = Rover.create_location(other, %{lat: 33.0, lon: -98.0, status: :off_limits})
{:ok, lv, html} = live(conn, ~p"/rover-locations")
assert html =~ "location-#{mine.id}"
assert html =~ "location-#{theirs.id}"
# Edit/Delete buttons rendered for owned location only.
assert has_element?(lv, "#location-#{mine.id} button", "Edit")
refute has_element?(lv, "#location-#{theirs.id} button", "Edit")
end
end
end