defmodule MicrowavepropWeb.StatusLiveTest do use MicrowavepropWeb.ConnCase, async: false import Microwaveprop.AccountsFixtures import Phoenix.LiveViewTest alias Microwaveprop.Cache alias Microwaveprop.Radio.Contact alias Microwaveprop.Repo alias Microwaveprop.Weather.NarrProfile setup %{conn: conn} do Cache.invalidate({MicrowavepropWeb.StatusLive, :count_unprocessed}) Cache.invalidate({MicrowavepropWeb.StatusLive, :stats}) Cache.invalidate({MicrowavepropWeb.StatusLive, :db_stats}) user = user_fixture() {:ok, admin} = user |> Ecto.Changeset.change(%{is_admin: true}) |> Repo.update() conn = log_in_user(conn, admin) {:ok, conn: conn} end defp create_narr_candidate do {:ok, contact} = %Contact{} |> Contact.changeset(%{ station1: "W5TEST", station2: "K5TEST", qso_timestamp: ~U[2010-06-15 18:00:00Z], mode: "CW", band: Decimal.new("1296"), grid1: "EM12", grid2: "EM00", pos1: %{"lat" => 33.0, "lon" => -97.0}, pos2: %{"lat" => 30.3, "lon" => -97.7}, distance_km: Decimal.new("300") }) |> Ecto.Changeset.change(%{hrrr_status: :unavailable}) |> Repo.insert() contact end # NARR fetches land in era5_profiles (table rename is a follow-up migration). # The status UI labels this "NARR" now. test "NARR progress bar numerator is actual profile matches not total-minus-candidates", %{conn: conn} do create_narr_candidate() # No NARR profile yet — candidates = 1, done = 0 {:ok, lv, _html} = live(conn, ~p"/status") narr_row = lv |> element(~s|[data-progress-key="narr"]|) |> render() assert narr_row =~ "NARR" assert narr_row =~ "0 / 1" # Insert a matching profile row — done should become 1 {:ok, _} = Repo.insert(%NarrProfile{ valid_time: ~U[2010-06-15 18:00:00Z], lat: 33.0, lon: -97.0, ducting_detected: false }) Cache.invalidate({MicrowavepropWeb.StatusLive, :count_unprocessed}) {:ok, lv, _html} = live(conn, ~p"/status") narr_row = lv |> element(~s|[data-progress-key="narr"]|) |> render() assert narr_row =~ "1 / 1" end end