From 3eead112b0ddb00a01dd511fae94afb72815d277 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 12 Feb 2026 18:44:46 +0100 Subject: [PATCH] Statistics tests: strict first_join_year nil, fee_type_id in URL --- test/mv/statistics_test.exs | 4 +-- test/mv_web/live/statistics_live_test.exs | 33 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/mv/statistics_test.exs b/test/mv/statistics_test.exs index 463dcb3..f8db9bc 100644 --- a/test/mv/statistics_test.exs +++ b/test/mv/statistics_test.exs @@ -46,9 +46,9 @@ defmodule Mv.StatisticsTest do end test "returns nil when no members exist", %{actor: actor} do - # Relies on empty member table for this test; may be nil if other tests created members + # Expects empty member table (sandbox isolation). If flaky, ensure no other test creates members. result = Statistics.first_join_year(actor: actor) - assert result == nil or is_integer(result) + assert result == nil end end diff --git a/test/mv_web/live/statistics_live_test.exs b/test/mv_web/live/statistics_live_test.exs index 8681bb8..3075c24 100644 --- a/test/mv_web/live/statistics_live_test.exs +++ b/test/mv_web/live/statistics_live_test.exs @@ -6,6 +6,8 @@ defmodule MvWeb.StatisticsLiveTest do import Phoenix.LiveViewTest + alias Mv.MembershipFees.MembershipFeeType + describe "statistics page" do test "renders statistics page with title and key labels for authenticated user with access", %{ @@ -28,5 +30,36 @@ defmodule MvWeb.StatisticsLiveTest do # table header or legend assert html =~ "Year" end + + test "fee_type_id in URL updates selected filter and contributions", %{conn: conn} do + actor = Mv.Helpers.SystemActor.get_system_actor() + + fee_types = + MembershipFeeType + |> Ash.Query.sort(name: :asc) + |> Ash.read!(domain: Mv.MembershipFees, actor: actor) + + fee_type = + case List.first(fee_types) do + nil -> + MembershipFeeType + |> Ash.Changeset.for_create(:create, %{ + name: "Test Fee #{System.unique_integer([:positive])}", + amount: Decimal.new("50.00"), + interval: :yearly + }) + |> Ash.create!(actor: actor) + + ft -> + ft + end + + path = ~p"/statistics" <> "?" <> URI.encode_query(%{"fee_type_id" => fee_type.id}) + {:ok, view, html} = live(conn, path) + + assert view |> element("select#fee-type-filter") |> has_element?() + assert html =~ fee_type.name + assert html =~ "Contributions by year" + end end end