defmodule MvWeb.MemberLive.IndexColumnManagerTest do @moduledoc """ §1.6 — The column manager sits in the filter toolbar, offers a per-column visibility toggle plus All and None controls styled as buttons (not links), and applies changes while preserving the existing persistence chain. """ use MvWeb.ConnCase, async: false import Phoenix.LiveViewTest alias Mv.Helpers.SystemActor setup %{conn: conn} do {:ok, _} = Mv.Membership.create_member( %{first_name: "Manager", last_name: "Columns", email: "manager@example.com"}, actor: SystemActor.get_system_actor() ) %{conn: conn_with_oidc_user(conn)} end test "column manager trigger sits alongside the filter controls", %{conn: conn} do {:ok, view, _html} = live(conn, ~p"/members") # Both the add-filter builder trigger and the column-manager trigger render # in the same toolbar. assert has_element?(view, "[data-testid='add-filter-trigger']") assert has_element?(view, "button[aria-controls='field-visibility-menu']") end test "All and None are buttons, not links, and per-column toggles are checkboxes", %{conn: conn} do {:ok, view, _html} = live(conn, ~p"/members") view |> element("button[aria-controls='field-visibility-menu']") |> render_click() # All / None render as buttons with button styling. assert has_element?(view, "button.btn[phx-click='select_all']", "All") assert has_element?(view, "button.btn[phx-click='select_none']", "None") refute has_element?(view, "a[phx-click='select_all']") refute has_element?(view, "a[phx-click='select_none']") # Per-column visibility toggles are accessible checkbox menu items. assert has_element?(view, "button[role='menuitemcheckbox'][phx-value-item='name']") end test "toggling a column applies and is reflected in the URL (persistence)", %{conn: conn} do {:ok, view, _html} = live(conn, ~p"/members") view |> element("button[aria-controls='field-visibility-menu']") |> render_click() view |> element("button[phx-value-item='join_date']") |> render_click() # The selection is pushed to the URL fields param so it survives reloads. path = assert_patch(view) assert path =~ "fields=" refute has_element?(view, "[data-testid='join_date']") end test "a reset button restores the curated default column set", %{conn: conn} do {:ok, view, _html} = live(conn, ~p"/members") view |> element("button[aria-controls='field-visibility-menu']") |> render_click() # Reset is a button styled like All/None, sitting next to them, with a tooltip. assert has_element?(view, "button.btn[phx-click='reset_fields']") # Hide a curated-default column, then reset restores it. view |> element("button[phx-value-item='join_date']") |> render_click() assert_patch(view) refute has_element?(view, "[data-testid='join_date']") view |> element("button[phx-click='reset_fields']") |> render_click() assert_patch(view) assert has_element?(view, "[data-testid='join_date']") end end