From 1b8d359f418cc1ac7475215cda64cc9e69dd8c99 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 24 Apr 2026 08:44:46 -0500 Subject: [PATCH] test: StatusLive.Index health_score 3/4 render paths --- .../live/status_live/index_test.exs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/aprsme_web/live/status_live/index_test.exs b/test/aprsme_web/live/status_live/index_test.exs index 1a7dc1b..1f32827 100644 --- a/test/aprsme_web/live/status_live/index_test.exs +++ b/test/aprsme_web/live/status_live/index_test.exs @@ -13,6 +13,65 @@ defmodule AprsmeWeb.StatusLive.IndexTest do assert html =~ "APRS-IS Connection" end + test "renders health score 3 (stable under 1 hour)", %{conn: conn} do + _ = + case :ets.info(:query_cache) do + :undefined -> :ets.new(:query_cache, [:named_table, :public, :set]) + _ -> :ok + end + + status = %{ + connected: true, + server: "test.aprs.test", + port: 14_580, + connected_at: DateTime.add(DateTime.utc_now(), -1000, :second), + uptime_seconds: 1000, + login_id: "N0CALL", + filter: "r/33/-96/100", + packet_stats: %{total_packets: 10, last_packet_at: DateTime.utc_now(), packets_per_second: 1}, + stored_packet_count: 50, + oldest_packet_timestamp: DateTime.add(DateTime.utc_now(), -3600, :second) + } + + Aprsme.Cache.put(:query_cache, "aprs_status", status) + + {:ok, _lv, html} = live(conn, ~p"/status", on_error: :warn) + # Uptime 1000s < 3600 → score 3. 50 stored packets. + assert html =~ "System Status" + assert html =~ "Connected" + + Aprsme.Cache.del(:query_cache, "aprs_status") + end + + test "renders health score 4 (stable under 1 day)", %{conn: conn} do + _ = + case :ets.info(:query_cache) do + :undefined -> :ets.new(:query_cache, [:named_table, :public, :set]) + _ -> :ok + end + + status = %{ + connected: true, + server: "test", + port: 14_580, + connected_at: DateTime.add(DateTime.utc_now(), -10_000, :second), + # Uptime 10,000s is between 3600 and 86_400 → score 4. + uptime_seconds: 10_000, + login_id: "N0CALL", + filter: "r/0/0/100", + packet_stats: %{total_packets: 1, last_packet_at: nil, packets_per_second: 0}, + stored_packet_count: 0, + oldest_packet_timestamp: nil + } + + Aprsme.Cache.put(:query_cache, "aprs_status", status) + + {:ok, _lv, html} = live(conn, ~p"/status", on_error: :warn) + assert html =~ "Connected" + + Aprsme.Cache.del(:query_cache, "aprs_status") + end + test "renders the connected-path template when cache has a live status", %{conn: conn} do # Ensure the cache ETS table exists for test. _ =