prop/test/microwaveprop_web/live/rover_locations_live/show_test.exs
Graham McIntire d44351366a
feat(rover): /rover-locations/:id detail page with map + marker
Each row now has a View link (and the location cell links too) to a
new show LiveView that renders the full record alongside a Leaflet
map centered on the marker. Owners get a Delete button there as well.
2026-05-02 17:02:00 -05:00

68 lines
2.2 KiB
Elixir

defmodule MicrowavepropWeb.RoverLocationsLive.ShowTest do
use MicrowavepropWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Microwaveprop.Rover
describe "show" do
test "renders the location and a map container", %{conn: conn} do
user = Microwaveprop.AccountsFixtures.user_fixture()
{:ok, loc} =
Rover.create_location(user, %{
lat: 32.5,
lon: -97.5,
status: :ideal,
notes: "great spot"
})
{:ok, lv, html} = live(conn, ~p"/rover-locations/#{loc.id}")
assert html =~ "Rover Location"
assert html =~ "great spot"
assert html =~ "EM12gm"
assert has_element?(lv, "#location-map-#{loc.id}[phx-hook=LocationMap]")
end
test "redirects when the location does not exist", %{conn: conn} do
missing_id = Ecto.UUID.generate()
assert {:error, {:live_redirect, %{to: "/rover-locations"}}} =
live(conn, ~p"/rover-locations/#{missing_id}")
end
test "redirects when the id is not a valid UUID", %{conn: conn} do
assert {:error, {:live_redirect, %{to: "/rover-locations"}}} =
live(conn, ~p"/rover-locations/not-a-uuid")
end
test "owner sees a Delete button; visitors do not", %{conn: conn} do
user = Microwaveprop.AccountsFixtures.user_fixture()
{:ok, loc} = Rover.create_location(user, %{lat: 32.5, lon: -97.5, status: :ideal})
# Anonymous: no Delete
{:ok, _lv, html} = live(conn, ~p"/rover-locations/#{loc.id}")
refute html =~ "Delete"
# Owner: Delete present
conn = log_in_user(conn, user)
{:ok, _lv, html} = live(conn, ~p"/rover-locations/#{loc.id}")
assert html =~ "Delete"
end
test "owner can delete from the show page and is redirected", %{conn: conn} do
user = Microwaveprop.AccountsFixtures.user_fixture()
{:ok, loc} = Rover.create_location(user, %{lat: 32.5, lon: -97.5, status: :ideal})
conn = log_in_user(conn, user)
{:ok, lv, _html} = live(conn, ~p"/rover-locations/#{loc.id}")
assert {:ok, _index_lv, _html} =
lv
|> element("button", "Delete")
|> render_click()
|> follow_redirect(conn, ~p"/rover-locations")
end
end
end