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.
86 lines
3.6 KiB
Elixir
86 lines
3.6 KiB
Elixir
defmodule ToweropsWeb.StatusPageLiveHelpersTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias ToweropsWeb.StatusPageLive
|
|
|
|
describe "overall_color/1" do
|
|
test "maps each status to a tailwind background class" do
|
|
assert "bg-green-500" == StatusPageLive.overall_color(:operational)
|
|
assert "bg-yellow-500" == StatusPageLive.overall_color(:degraded)
|
|
assert "bg-orange-500" == StatusPageLive.overall_color(:partial_outage)
|
|
assert "bg-red-500" == StatusPageLive.overall_color(:major_outage)
|
|
assert "bg-blue-500" == StatusPageLive.overall_color(:maintenance)
|
|
end
|
|
|
|
test "unknown status falls back to gray" do
|
|
assert "bg-gray-500" == StatusPageLive.overall_color(:mystery)
|
|
assert "bg-gray-500" == StatusPageLive.overall_color(nil)
|
|
end
|
|
end
|
|
|
|
describe "overall_text/1" do
|
|
test "maps each status to a user-facing label" do
|
|
assert "All Systems Operational" == StatusPageLive.overall_text(:operational)
|
|
assert "Degraded Performance" == StatusPageLive.overall_text(:degraded)
|
|
assert "Partial System Outage" == StatusPageLive.overall_text(:partial_outage)
|
|
assert "Major System Outage" == StatusPageLive.overall_text(:major_outage)
|
|
assert "Scheduled Maintenance" == StatusPageLive.overall_text(:maintenance)
|
|
end
|
|
|
|
test "unknown status labeled Unknown" do
|
|
assert "Unknown" == StatusPageLive.overall_text(nil)
|
|
assert "Unknown" == StatusPageLive.overall_text(:whatever)
|
|
end
|
|
end
|
|
|
|
describe "component_color/1 (string keys)" do
|
|
test "maps each status" do
|
|
assert "bg-green-500" == StatusPageLive.component_color("operational")
|
|
assert "bg-yellow-500" == StatusPageLive.component_color("degraded")
|
|
assert "bg-orange-500" == StatusPageLive.component_color("partial_outage")
|
|
assert "bg-red-500" == StatusPageLive.component_color("major_outage")
|
|
assert "bg-blue-500" == StatusPageLive.component_color("maintenance")
|
|
end
|
|
|
|
test "unknown falls back to gray-400" do
|
|
assert "bg-gray-400" == StatusPageLive.component_color("unknown")
|
|
assert "bg-gray-400" == StatusPageLive.component_color(nil)
|
|
end
|
|
end
|
|
|
|
describe "component_label/1" do
|
|
test "humanizes known labels" do
|
|
assert "Operational" == StatusPageLive.component_label("operational")
|
|
assert "Degraded" == StatusPageLive.component_label("degraded")
|
|
assert "Partial Outage" == StatusPageLive.component_label("partial_outage")
|
|
assert "Major Outage" == StatusPageLive.component_label("major_outage")
|
|
assert "Maintenance" == StatusPageLive.component_label("maintenance")
|
|
end
|
|
|
|
test "unknown labels pass through" do
|
|
assert "foobar" == StatusPageLive.component_label("foobar")
|
|
end
|
|
end
|
|
|
|
describe "severity_color/1" do
|
|
test "critical, major, other" do
|
|
assert "text-red-600" == StatusPageLive.severity_color("critical")
|
|
assert "text-orange-600" == StatusPageLive.severity_color("major")
|
|
assert "text-yellow-600" == StatusPageLive.severity_color("minor")
|
|
assert "text-yellow-600" == StatusPageLive.severity_color(nil)
|
|
end
|
|
end
|
|
|
|
describe "incident_status_label/1" do
|
|
test "maps each workflow state" do
|
|
assert "Investigating" == StatusPageLive.incident_status_label("investigating")
|
|
assert "Identified" == StatusPageLive.incident_status_label("identified")
|
|
assert "Monitoring" == StatusPageLive.incident_status_label("monitoring")
|
|
assert "Resolved" == StatusPageLive.incident_status_label("resolved")
|
|
end
|
|
|
|
test "unknown labels pass through" do
|
|
assert "weird" == StatusPageLive.incident_status_label("weird")
|
|
end
|
|
end
|
|
end
|