test: GaiiaReconciliationLive + ActivityFeedLive helpers and events

This commit is contained in:
Graham McIntire 2026-05-08 13:39:01 -05:00
parent 76de672ac8
commit 1b35177c1b
3 changed files with 118 additions and 11 deletions

View file

@ -57,15 +57,4 @@ defmodule Towerops.Profiles.MibCacheTest do
assert is_integer(MibCache.size())
end
end
describe "init/1" do
test "creates the ETS table when it does not yet exist" do
# Drop and re-init to exercise the create branch.
_ = if pid = Process.whereis(MibCache), do: GenServer.stop(pid, :normal)
_ = :ets.info(:mib_cache) != :undefined && :ets.delete(:mib_cache)
assert {:ok, _state} = MibCache.init([])
assert :ets.info(:mib_cache) != :undefined
end
end
end

View file

@ -0,0 +1,82 @@
defmodule ToweropsWeb.ActivityFeedLiveTest do
use ToweropsWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias ToweropsWeb.ActivityFeedLive
setup :register_and_log_in_user
setup %{user: user} do
{:ok, organization} =
Towerops.Organizations.create_organization(%{name: "Activity Org"}, user.id)
%{organization: organization}
end
describe "mount and renders" do
test "renders the activity feed page", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/activity")
assert html =~ "Activity"
end
test "deep-linking to ?type=alert_fired filters", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/activity?type=alert_fired")
assert html =~ "Activity"
end
test "deep-linking to ?type=alert_resolved filters", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/activity?type=alert_resolved")
assert html =~ "Activity"
end
test "deep-linking to ?type=device_event filters", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/activity?type=device_event")
assert html =~ "Activity"
end
test "toggle_type events keep the view alive", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/activity")
_ = render_hook(view, "toggle_type", %{"type" => "alert_fired"})
_ = render_hook(view, "toggle_type", %{"type" => "config_change"})
_ = render_hook(view, "toggle_type", %{"type" => "alert_fired"})
assert render(view) =~ "Activity"
end
test "search filters the feed", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/activity")
_ = render_hook(view, "search", %{"search" => "router"})
assert render(view) =~ "Activity"
end
end
describe "severity / type helpers" do
test "severity_dot_color covers critical/warning/info combinations" do
assert ActivityFeedLive.severity_dot_color(:critical, :anything) =~ "bg-red"
assert ActivityFeedLive.severity_dot_color(:warning, :anything) =~ "bg-yellow"
assert ActivityFeedLive.severity_dot_color(:info, :alert_resolved) =~ "bg-green"
assert ActivityFeedLive.severity_dot_color(:info, :sync) =~ "bg-blue"
assert ActivityFeedLive.severity_dot_color(:info, :device_added) =~ "bg-cyan"
assert ActivityFeedLive.severity_dot_color(:info, :other) =~ "bg-gray"
assert ActivityFeedLive.severity_dot_color(nil, nil) =~ "bg-gray"
end
test "severity_icon_color covers all branches" do
assert ActivityFeedLive.severity_icon_color(:critical, :x) =~ "text-red"
assert ActivityFeedLive.severity_icon_color(:warning, :x) =~ "text-yellow"
assert ActivityFeedLive.severity_icon_color(:info, :alert_resolved) =~ "text-green"
assert ActivityFeedLive.severity_icon_color(:info, :sync) =~ "text-blue"
assert ActivityFeedLive.severity_icon_color(:info, :device_added) =~ "text-cyan"
assert ActivityFeedLive.severity_icon_color(:info, :other) =~ "text-gray"
end
test "severity_text_color covers all branches" do
assert ActivityFeedLive.severity_text_color(:critical, :x) =~ "text-red"
assert ActivityFeedLive.severity_text_color(:warning, :x) =~ "text-yellow"
assert ActivityFeedLive.severity_text_color(:info, :alert_resolved) =~ "text-green"
assert ActivityFeedLive.severity_text_color(:info, :other) =~ "text-gray-900"
end
end
end

View file

@ -0,0 +1,36 @@
defmodule ToweropsWeb.Org.GaiiaReconciliationLiveTest do
use ToweropsWeb.ConnCase, async: true
import Phoenix.LiveViewTest
import Towerops.OrganizationsFixtures
setup :register_and_log_in_user
setup %{user: user} do
org = organization_fixture(user.id)
%{org: org}
end
test "renders the reconciliation page", %{conn: conn, org: org} do
{:ok, _view, html} = live(conn, ~p"/orgs/#{org.slug}/settings/integrations/gaiia/reconciliation")
assert html =~ "Gaiia"
end
test "select_tab patches URL with the new tab", %{conn: conn, org: org} do
{:ok, view, _html} =
live(conn, ~p"/orgs/#{org.slug}/settings/integrations/gaiia/reconciliation")
_ = render_hook(view, "select_tab", %{"tab" => "untracked"})
assert render(view) =~ "Gaiia"
end
test "deep-linking to a specific tab works", %{conn: conn, org: org} do
{:ok, _view, html} =
live(
conn,
~p"/orgs/#{org.slug}/settings/integrations/gaiia/reconciliation?tab=mismatches"
)
assert html =~ "Gaiia"
end
end