defmodule AprsmeWeb.StatusLive.IndexTest do use AprsmeWeb.ConnCase import Phoenix.LiveViewTest alias AprsmeWeb.StatusLive.Index alias Phoenix.LiveView.Socket describe "mount via HTTP" do test "renders the status page", %{conn: conn} do {:ok, _lv, html} = live(conn, ~p"/status", on_error: :warn) assert html =~ "System Status" assert html =~ "APRS-IS Connection" end end describe "handle_info({:status_updated, status}, socket)" do test "updates assigns with the new status" do status = %{ connected: true, server: "test-server", port: 14_580, connected_at: DateTime.utc_now(), uptime_seconds: 60, login_id: "TEST-ID", filter: "r/0/0/100", packet_stats: %{total_packets: 0, packets_per_second: 0, last_packet_at: nil}, stored_packet_count: 0, oldest_packet_timestamp: nil } socket = %Socket{assigns: %{__changed__: %{}}} assert {:noreply, new_socket} = Index.handle_info({:status_updated, status}, socket) assert new_socket.assigns.aprs_status == status assert new_socket.assigns.loading == false assert %DateTime{} = new_socket.assigns.current_time # Connected+uptime 60s → health score 2. assert new_socket.assigns.health_score == 2 end end describe "handle_info({:aprs_status_update, status}, socket)" do test "updates status without flipping loading flag" do status = %{ connected: true, server: "test-server", port: 14_580, connected_at: DateTime.utc_now(), uptime_seconds: 100_000, login_id: "TEST-ID", filter: "r/0/0/100", packet_stats: %{total_packets: 5, packets_per_second: 1, last_packet_at: DateTime.utc_now()}, stored_packet_count: 123, oldest_packet_timestamp: DateTime.utc_now() } socket = %Socket{assigns: %{__changed__: %{}, loading: false}} assert {:noreply, new_socket} = Index.handle_info({:aprs_status_update, status}, socket) assert new_socket.assigns.aprs_status == status # Uptime > 86_400? 100_000 > 86_400 → yes → score 5. assert new_socket.assigns.health_score == 5 # Loading flag is untouched (this code path doesn't toggle it). assert new_socket.assigns.loading == false end end end