defmodule MvWeb.MemberLive.IndexDatePresetsTest do @moduledoc """ §1.25 (supersedes §1.8) — a date field's value control offers relative presets; picking "This year" applies the period-to-date range (Jan 1 – today) of the current year and writes the equivalent range params to the URL. """ use MvWeb.ConnCase, async: false import Phoenix.LiveViewTest setup %{conn: conn} do actor = Mv.Helpers.SystemActor.get_system_actor() {:ok, _member} = Mv.Membership.create_member( %{first_name: "Preset", last_name: "Member", email: "preset@example.com"}, actor: actor ) %{conn: conn_with_oidc_user(conn)} end test "the 'This year' preset applies the year-to-date range and writes URL params", %{ conn: conn } do {:ok, view, _html} = live(conn, ~p"/members") # Open the Join date value control and apply the "This year" preset. pick_field(view, "join_date") assert has_element?(view, "[data-testid='date-presets']") view |> element("[data-testid='date-preset-this_year']") |> render_click() path = assert_patch(view) today = Date.utc_today() assert path =~ "jd_from=#{today.year}-01-01" assert path =~ "jd_to=#{Date.to_iso8601(today)}" end test "the 'Last 30 days' preset applies a today-anchored 30-day window", %{conn: conn} do {:ok, view, _html} = live(conn, ~p"/members") pick_field(view, "join_date") view |> element("[data-testid='date-preset-last_30_days']") |> render_click() path = assert_patch(view) today = Date.utc_today() assert path =~ "jd_from=#{Date.to_iso8601(Date.add(today, -29))}" assert path =~ "jd_to=#{Date.to_iso8601(today)}" end end