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.
157 lines
4.8 KiB
Elixir
157 lines
4.8 KiB
Elixir
defmodule ToweropsWeb.SiteLive.ShowHelpersTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias ToweropsWeb.SiteLive.Show
|
|
|
|
describe "qoe_color/1 and qoe_bg/1" do
|
|
test "nil is gray" do
|
|
assert String.contains?(Show.qoe_color(nil), "gray")
|
|
assert String.contains?(Show.qoe_bg(nil), "gray")
|
|
end
|
|
|
|
test "high score green" do
|
|
assert String.contains?(Show.qoe_color(9.0), "green")
|
|
assert String.contains?(Show.qoe_bg(9.0), "green")
|
|
end
|
|
|
|
test "mid score yellow" do
|
|
assert String.contains?(Show.qoe_color(7.0), "yellow")
|
|
assert String.contains?(Show.qoe_bg(7.0), "yellow")
|
|
end
|
|
|
|
test "low score red" do
|
|
assert String.contains?(Show.qoe_color(3.0), "red")
|
|
assert String.contains?(Show.qoe_bg(3.0), "red")
|
|
end
|
|
end
|
|
|
|
describe "capacity_bar_color/1" do
|
|
test "nil is gray" do
|
|
assert "bg-gray-300" == Show.capacity_bar_color(nil)
|
|
end
|
|
|
|
test "high score green" do
|
|
assert "bg-green-500" == Show.capacity_bar_color(80)
|
|
end
|
|
|
|
test "mid score yellow" do
|
|
assert "bg-yellow-500" == Show.capacity_bar_color(50)
|
|
end
|
|
|
|
test "low score red" do
|
|
assert "bg-red-500" == Show.capacity_bar_color(20)
|
|
end
|
|
end
|
|
|
|
describe "status_dot_class/1" do
|
|
test "up/down/other" do
|
|
assert "bg-green-500" == Show.status_dot_class(:up)
|
|
assert "bg-red-500" == Show.status_dot_class(:down)
|
|
assert "bg-gray-400" == Show.status_dot_class(:unknown)
|
|
end
|
|
end
|
|
|
|
describe "time_ago/1" do
|
|
test "nil returns em-dash" do
|
|
assert "—" == Show.time_ago(nil)
|
|
end
|
|
|
|
test "returns a string ending in 'ago' for past datetimes" do
|
|
dt = DateTime.add(DateTime.utc_now(), -60, :second)
|
|
assert String.ends_with?(Show.time_ago(dt), "ago")
|
|
end
|
|
end
|
|
|
|
describe "format_response_time/1" do
|
|
test "nil returns em-dash" do
|
|
assert "—" == Show.format_response_time(nil)
|
|
end
|
|
|
|
test "sub-ms shows <1ms" do
|
|
assert "<1ms" == Show.format_response_time(0.5)
|
|
end
|
|
|
|
test "normal ms rounded" do
|
|
assert "42ms" == Show.format_response_time(41.7)
|
|
assert "100ms" == Show.format_response_time(100)
|
|
end
|
|
|
|
test "non-number returns em-dash" do
|
|
assert "—" == Show.format_response_time("abc")
|
|
assert "—" == Show.format_response_time(:atom)
|
|
end
|
|
end
|
|
|
|
describe "change_size_label/1 + change_size_color/1" do
|
|
test "Small / gray under 100" do
|
|
assert "Small" == Show.change_size_label(50)
|
|
assert String.contains?(Show.change_size_color(50), "gray")
|
|
end
|
|
|
|
test "Medium / yellow 100-499" do
|
|
assert "Medium" == Show.change_size_label(200)
|
|
assert String.contains?(Show.change_size_color(200), "yellow")
|
|
end
|
|
|
|
test "Large / red 500+" do
|
|
assert "Large" == Show.change_size_label(500)
|
|
assert String.contains?(Show.change_size_color(1000), "red")
|
|
end
|
|
end
|
|
|
|
describe "insight_urgency_class/1 + insight_urgency_icon/1" do
|
|
test "critical maps to red + warning triangle" do
|
|
assert String.contains?(Show.insight_urgency_class("critical"), "red")
|
|
assert "hero-exclamation-triangle" == Show.insight_urgency_icon("critical")
|
|
end
|
|
|
|
test "warning maps to yellow + warning circle" do
|
|
assert String.contains?(Show.insight_urgency_class("warning"), "yellow")
|
|
assert "hero-exclamation-circle" == Show.insight_urgency_icon("warning")
|
|
end
|
|
|
|
test "other maps to blue + info circle" do
|
|
assert String.contains?(Show.insight_urgency_class("info"), "blue")
|
|
assert "hero-information-circle" == Show.insight_urgency_icon("info")
|
|
end
|
|
end
|
|
|
|
describe "alert_severity/1" do
|
|
test "maps known alert types" do
|
|
assert "critical" == Show.alert_severity(:device_down)
|
|
assert "info" == Show.alert_severity(:device_up)
|
|
assert "warning" == Show.alert_severity(:other)
|
|
end
|
|
end
|
|
|
|
describe "format_capacity/1" do
|
|
test "Gbps/Mbps/Kbps/bps transitions" do
|
|
assert "1.5 Gbps" == Show.format_capacity(1_500_000_000)
|
|
assert "50.0 Mbps" == Show.format_capacity(50_000_000)
|
|
assert "5.0 Kbps" == Show.format_capacity(5_000)
|
|
assert "500 bps" == Show.format_capacity(500)
|
|
end
|
|
|
|
test "non-number returns dash" do
|
|
assert "-" == Show.format_capacity(nil)
|
|
assert "-" == Show.format_capacity("abc")
|
|
end
|
|
end
|
|
|
|
describe "utilization_bar_color/1 and utilization_text_color/1" do
|
|
test "90%+ red" do
|
|
assert "bg-red-500" == Show.utilization_bar_color(95)
|
|
assert String.contains?(Show.utilization_text_color(95), "red")
|
|
end
|
|
|
|
test "70-90 yellow" do
|
|
assert "bg-yellow-500" == Show.utilization_bar_color(80)
|
|
assert String.contains?(Show.utilization_text_color(80), "yellow")
|
|
end
|
|
|
|
test "under 70 green" do
|
|
assert "bg-green-500" == Show.utilization_bar_color(40)
|
|
assert String.contains?(Show.utilization_text_color(40), "green")
|
|
end
|
|
end
|
|
end
|