From 1b35177c1b38a62922315919ac85b91fd0ffb8c1 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 8 May 2026 13:39:01 -0500 Subject: [PATCH] test: GaiiaReconciliationLive + ActivityFeedLive helpers and events --- test/towerops/profiles/mib_cache_test.exs | 11 --- .../live/activity_feed_live_test.exs | 82 +++++++++++++++++++ .../org/gaiia_reconciliation_live_test.exs | 36 ++++++++ 3 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 test/towerops_web/live/activity_feed_live_test.exs create mode 100644 test/towerops_web/live/org/gaiia_reconciliation_live_test.exs diff --git a/test/towerops/profiles/mib_cache_test.exs b/test/towerops/profiles/mib_cache_test.exs index 6606883c..9bc776b6 100644 --- a/test/towerops/profiles/mib_cache_test.exs +++ b/test/towerops/profiles/mib_cache_test.exs @@ -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 diff --git a/test/towerops_web/live/activity_feed_live_test.exs b/test/towerops_web/live/activity_feed_live_test.exs new file mode 100644 index 00000000..08313bda --- /dev/null +++ b/test/towerops_web/live/activity_feed_live_test.exs @@ -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 diff --git a/test/towerops_web/live/org/gaiia_reconciliation_live_test.exs b/test/towerops_web/live/org/gaiia_reconciliation_live_test.exs new file mode 100644 index 00000000..d7839646 --- /dev/null +++ b/test/towerops_web/live/org/gaiia_reconciliation_live_test.exs @@ -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