towerops/test/towerops_web/live/device_live/tabs_smoke_test.exs
Graham McIntire 3ca0834ef0 tests: raise coverage to 70% via helper promotion + new unit/property tests
Promoted pure presentation and utility helpers from `defp` to `def @doc false`
across ~20 LiveViews, Oban workers, and sync modules so they're reachable from
unit tests. Refactored several `cond` blocks into idiomatic function heads with
guards. Added ~250 new test cases in new files under test/towerops and
test/towerops_web, including DB-backed tests for CnMaestro.Sync and
AlertNotificationWorker, and removed dead LiveView tab components and
CapacityLive (no callers anywhere in lib/test).

Configured mix.exs test_coverage.ignore_modules to exclude vendored third-party
code (SnmpKit, protobuf-generated Towerops.Agent.*, Absinthe GraphQL types,
Phoenix HTML modules, Inspect protocol impls) from coverage calculations —
these are not our project code.

Coverage: 66.93% → 70.09%. Full suite: 10,127 tests, 0 failures.
2026-04-24 09:49:06 -05:00

74 lines
2.3 KiB
Elixir

defmodule ToweropsWeb.DeviceLive.TabsSmokeTest do
@moduledoc """
Smoke tests exercising each DeviceLive.Show tab render. Each tab is backed by
a large component module (overview_tab, ports_tab, etc). Hitting each tab path
pulls those components into coverage even for an empty device.
"""
use ToweropsWeb.ConnCase, async: true
import Phoenix.LiveViewTest
setup do
user = Towerops.AccountsFixtures.user_fixture(enable_totp: true)
{:ok, org} = Towerops.Organizations.create_organization(%{name: "Tabs Org"}, user.id)
device =
Towerops.DevicesFixtures.device_fixture(%{
organization_id: org.id,
name: "Tabs Device",
ip_address: "192.168.77.77"
})
%{user: user, org: org, device: device}
end
defp assert_tab_mounts(conn, user, device, tab) do
conn = log_in_user(conn, user)
url = "/devices/#{device.id}?tab=#{tab}"
# Dump the LiveView flash/error if mount fails so we can see what's happening.
case live(conn, url) do
{:ok, _view, html} ->
assert is_binary(html)
{:error, {:redirect, %{to: to}}} ->
IO.puts("redirected to #{to}")
flunk("expected mount, got redirect to #{to}")
{:error, {:live_redirect, %{to: to}}} ->
IO.puts("live_redirected to #{to}")
flunk("expected mount, got live_redirect to #{to}")
other ->
flunk("unexpected result: #{inspect(other)}")
end
end
test "overview tab", %{conn: conn, user: user, device: device} do
assert_tab_mounts(conn, user, device, "overview")
end
test "ports tab", %{conn: conn, user: user, device: device} do
assert_tab_mounts(conn, user, device, "ports")
end
test "checks tab", %{conn: conn, user: user, device: device} do
assert_tab_mounts(conn, user, device, "checks")
end
test "backups tab", %{conn: conn, user: user, device: device} do
assert_tab_mounts(conn, user, device, "backups")
end
test "wireless tab", %{conn: conn, user: user, device: device} do
assert_tab_mounts(conn, user, device, "wireless")
end
test "preseem tab", %{conn: conn, user: user, device: device} do
assert_tab_mounts(conn, user, device, "preseem")
end
test "gaiia tab", %{conn: conn, user: user, device: device} do
assert_tab_mounts(conn, user, device, "gaiia")
end
end