134 lines
4.9 KiB
Elixir
134 lines
4.9 KiB
Elixir
defmodule ToweropsWeb.StatusPageLiveTest do
|
|
use ToweropsWeb.ConnCase, async: true
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
alias ToweropsWeb.StatusPageLive
|
|
|
|
describe "overall_color/1" do
|
|
test "operational returns green" do
|
|
assert StatusPageLive.overall_color(:operational) == "bg-green-500"
|
|
end
|
|
|
|
test "degraded returns yellow" do
|
|
assert StatusPageLive.overall_color(:degraded) == "bg-yellow-500"
|
|
end
|
|
|
|
test "partial_outage returns orange" do
|
|
assert StatusPageLive.overall_color(:partial_outage) == "bg-orange-500"
|
|
end
|
|
|
|
test "major_outage returns red" do
|
|
assert StatusPageLive.overall_color(:major_outage) == "bg-red-500"
|
|
end
|
|
|
|
test "maintenance returns blue" do
|
|
assert StatusPageLive.overall_color(:maintenance) == "bg-blue-500"
|
|
end
|
|
|
|
test "unknown returns gray" do
|
|
assert StatusPageLive.overall_color(:unknown) == "bg-gray-500"
|
|
end
|
|
end
|
|
|
|
describe "overall_text/1" do
|
|
test "returns correct text for each status" do
|
|
assert StatusPageLive.overall_text(:operational) == "All Systems Operational"
|
|
assert StatusPageLive.overall_text(:degraded) == "Degraded Performance"
|
|
assert StatusPageLive.overall_text(:partial_outage) == "Partial System Outage"
|
|
assert StatusPageLive.overall_text(:major_outage) == "Major System Outage"
|
|
assert StatusPageLive.overall_text(:maintenance) == "Scheduled Maintenance"
|
|
assert StatusPageLive.overall_text(:unknown) == "Unknown"
|
|
end
|
|
end
|
|
|
|
describe "component_color/1" do
|
|
test "maps each status to correct color" do
|
|
assert StatusPageLive.component_color("operational") == "bg-green-500"
|
|
assert StatusPageLive.component_color("degraded") == "bg-yellow-500"
|
|
assert StatusPageLive.component_color("partial_outage") == "bg-orange-500"
|
|
assert StatusPageLive.component_color("major_outage") == "bg-red-500"
|
|
assert StatusPageLive.component_color("maintenance") == "bg-blue-500"
|
|
end
|
|
|
|
test "unknown status returns gray-400" do
|
|
assert StatusPageLive.component_color("unknown_status") == "bg-gray-400"
|
|
end
|
|
end
|
|
|
|
describe "component_label/1" do
|
|
test "maps each status to correct label" do
|
|
assert StatusPageLive.component_label("operational") == "Operational"
|
|
assert StatusPageLive.component_label("degraded") == "Degraded"
|
|
assert StatusPageLive.component_label("partial_outage") == "Partial Outage"
|
|
assert StatusPageLive.component_label("major_outage") == "Major Outage"
|
|
assert StatusPageLive.component_label("maintenance") == "Maintenance"
|
|
end
|
|
|
|
test "returns unknown status as-is" do
|
|
assert StatusPageLive.component_label("unusual") == "unusual"
|
|
end
|
|
end
|
|
|
|
describe "severity_color/1" do
|
|
test "maps each severity to correct color" do
|
|
assert StatusPageLive.severity_color("critical") == "text-red-600"
|
|
assert StatusPageLive.severity_color("major") == "text-orange-600"
|
|
assert StatusPageLive.severity_color("warning") == "text-yellow-600"
|
|
assert StatusPageLive.severity_color("info") == "text-yellow-600"
|
|
end
|
|
end
|
|
|
|
describe "incident_status_label/1" do
|
|
test "maps each status to correct label" do
|
|
assert StatusPageLive.incident_status_label("investigating") == "Investigating"
|
|
assert StatusPageLive.incident_status_label("identified") == "Identified"
|
|
assert StatusPageLive.incident_status_label("monitoring") == "Monitoring"
|
|
assert StatusPageLive.incident_status_label("resolved") == "Resolved"
|
|
end
|
|
|
|
test "returns unknown status as-is" do
|
|
assert StatusPageLive.incident_status_label("unknown") == "unknown"
|
|
end
|
|
end
|
|
|
|
describe "mount" do
|
|
test "renders 404 for unknown slug", %{conn: conn} do
|
|
{:ok, view, _html} = live(conn, ~p"/status/unknown-slug-12345")
|
|
refute has_element?(view, "#status-page")
|
|
end
|
|
|
|
test "renders the status page when slug exists", %{conn: conn} do
|
|
user = Towerops.AccountsFixtures.user_fixture()
|
|
{:ok, org} = Towerops.Organizations.create_organization(%{name: "SP Org"}, user.id)
|
|
|
|
{:ok, config} =
|
|
Towerops.StatusPages.create_config(%{
|
|
organization_id: org.id,
|
|
slug: "sp-#{System.unique_integer([:positive])}",
|
|
company_name: "Acme Co",
|
|
enabled: true
|
|
})
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/status/#{config.slug}")
|
|
assert html =~ "Acme Co"
|
|
end
|
|
|
|
test ":status_updated PubSub message refreshes assigns", %{conn: conn} do
|
|
user = Towerops.AccountsFixtures.user_fixture()
|
|
{:ok, org} = Towerops.Organizations.create_organization(%{name: "Push Org"}, user.id)
|
|
|
|
{:ok, config} =
|
|
Towerops.StatusPages.create_config(%{
|
|
organization_id: org.id,
|
|
slug: "push-#{System.unique_integer([:positive])}",
|
|
company_name: "Push Inc",
|
|
enabled: true
|
|
})
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/status/#{config.slug}")
|
|
send(view.pid, {:status_updated, %{}})
|
|
assert render(view) =~ "Push Inc"
|
|
end
|
|
end
|
|
end
|