towerops/test/towerops_web/live/maintenance_live/show_test.exs
Graham McIntire 4ea64cb550 test: lift coverage from 85.84% → 86.28%
Adds focused tests across multiple modules to push toward the 87% threshold:

- CoreComponents: pagination/1 (multi-page, ellipsis, params),
  list/1 (slot rendering), and signal_badge/1 across all RSSI bands.
- ApiDocs/GraphQLDocs controllers: bypass-the-router pattern so the
  "scope-with-organization" branches are actually exercised (the public
  routes are unscoped, so the org branch is unreachable via get/2).
- Mix.Tasks.Unused: text + JSON output, --only / --skip filters.
- Mix.Tasks.JobCleanupTask: prod path with phoenix snmp enabled vs
  disabled (uses :job_cleanup_settle_ms = 0 to avoid the 1s sleep).
- Member resolver: success path for remove/update_role on non-owner
  membership, and the changeset-error branch for an invalid role.
- Check resolver: unauthenticated fallback clauses for list / get /
  create / update / delete.
- RfLinks: nil-signal sort ordering, :unknown classification for
  nil/nil signal+snr, :degraded filter, capacity_utilization edge
  cases (max_rate 0/missing, both rates nil).
- StatusHelpers: status_emoji + title_with_status across green / red
  branches (warning is unreachable given the active-alerts query).
- ApiTokens: spawn_async_update/2 path with env != :test.
- ImpactAnalysis: to_json/1 across nil and populated levels.
- Maintenance: query helpers (default-arity wrappers, active range)
  and Show LiveView delete event redirecting to /maintenance.
- Coverage map: probe_point event handler.
- InvitationQuery: default-arity pending/1.
2026-05-08 17:44:18 -05:00

45 lines
1.2 KiB
Elixir

defmodule ToweropsWeb.MaintenanceLive.ShowTest do
use ToweropsWeb.ConnCase, async: false
import Phoenix.LiveViewTest
alias Towerops.Maintenance
setup :register_and_log_in_user_with_sudo
describe "delete event" do
test "deletes the window and navigates back to the index", %{conn: conn, user: user} do
org = Towerops.OrganizationsFixtures.organization_fixture(user.id)
window = create_window(org.id, user.id)
conn = put_session(conn, :current_organization_id, org.id)
{:ok, view, _html} = live(conn, ~p"/maintenance/#{window.id}")
assert {:error, {:live_redirect, %{to: to}}} = render_click(view, "delete")
assert to =~ "/maintenance"
assert_raise Ecto.NoResultsError, fn ->
Maintenance.get_window!(window.id)
end
end
end
defp create_window(org_id, user_id) do
now = DateTime.truncate(DateTime.utc_now(), :second)
starts = DateTime.add(now, 60, :second)
ends = DateTime.add(now, 3600, :second)
{:ok, window} =
Maintenance.create_window(%{
organization_id: org_id,
created_by_id: user_id,
name: "Test window",
starts_at: starts,
ends_at: ends,
reason: "showing test"
})
window
end
end