prop/test/microwaveprop_web/live/beacon_live_test.exs
Graham McIntire b656e015bf Beacon power in mW, settings tweaks
- Rename beacons.power_watts to power_mw (migration multiplies existing
  values by 1000); form/list/show all relabeled to "Power (mW)"
- Fix Add-monitor button alignment on /users/settings by rendering the
  label above and putting the input and button in a plain flex row so
  the input wrapper margin no longer offsets the button
- Extend the settings page re-auth window from 10 minutes to 24 hours
2026-04-08 12:45:35 -05:00

94 lines
2.8 KiB
Elixir

defmodule MicrowavepropWeb.BeaconLiveTest do
use MicrowavepropWeb.ConnCase
import Microwaveprop.AccountsFixtures
import Microwaveprop.BeaconsFixtures
import Phoenix.LiveViewTest
alias Microwaveprop.Accounts
defp promote_to_admin(user) do
{:ok, user} = Accounts.admin_update_user(user, %{is_admin: true})
user
end
defp admin_user_fixture do
promote_to_admin(user_fixture())
end
describe "Index (public)" do
test "lists beacons without logging in", %{conn: conn} do
beacon = beacon_fixture(user_fixture())
{:ok, _view, html} = live(conn, ~p"/beacons")
assert html =~ "Beacons"
assert html =~ beacon.callsign
end
test "non-admin does not see the New Beacon button", %{conn: conn} do
user = user_fixture()
conn = log_in_user(conn, user)
{:ok, _view, html} = live(conn, ~p"/beacons")
refute html =~ "New Beacon"
end
test "admin sees the New Beacon button", %{conn: conn} do
conn = log_in_user(conn, admin_user_fixture())
{:ok, _view, html} = live(conn, ~p"/beacons")
assert html =~ "New Beacon"
end
end
describe "Show (public)" do
test "renders beacon details without logging in", %{conn: conn} do
beacon = beacon_fixture(user_fixture())
{:ok, _view, html} = live(conn, ~p"/beacons/#{beacon}")
assert html =~ beacon.callsign
assert html =~ "#{beacon.frequency_mhz}"
end
end
describe "Form (admin only)" do
test "redirects non-admin away from /beacons/new", %{conn: conn} do
user = user_fixture()
conn = log_in_user(conn, user)
assert {:error, {:redirect, %{to: "/"}}} = live(conn, ~p"/beacons/new")
end
test "redirects anonymous user away from /beacons/new", %{conn: conn} do
assert {:error, {:redirect, %{to: "/users/log-in"}}} = live(conn, ~p"/beacons/new")
end
test "admin creates a beacon", %{conn: conn} do
conn = log_in_user(conn, admin_user_fixture())
{:ok, form_live, _html} = live(conn, ~p"/beacons/new")
attrs = valid_beacon_attrs()
assert {:ok, _view, html} =
form_live
|> form("#beacon-form", beacon: attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/beacons")
assert html =~ "Beacon created"
assert html =~ attrs.callsign
end
test "admin edits a beacon", %{conn: conn} do
admin = admin_user_fixture()
beacon = beacon_fixture(admin)
conn = log_in_user(conn, admin)
{:ok, form_live, _} = live(conn, ~p"/beacons/#{beacon}/edit")
assert {:ok, _view, html} =
form_live
|> form("#beacon-form", beacon: %{power_mw: 25_000.0})
|> render_submit()
|> follow_redirect(conn, ~p"/beacons")
assert html =~ "Beacon updated"
end
end
end