defmodule MvWeb.MemberLive.IndexSearchClearTest do @moduledoc """ §1.3 — Activating the search clear (×) control clears the query, removes the URL search param, and resets the result set to the unfiltered list. """ use MvWeb.ConnCase, async: false import Phoenix.LiveViewTest alias Mv.Helpers.SystemActor setup %{conn: conn} do actor = SystemActor.get_system_actor() {:ok, _} = Mv.Membership.create_member( %{first_name: "Findable", last_name: "One", email: "findable@example.com"}, actor: actor ) {:ok, other} = Mv.Membership.create_member( %{first_name: "Other", last_name: "Two", email: "other@example.com"}, actor: actor ) %{conn: conn_with_oidc_user(conn), other: other} end test "clear control only appears when a query is present", %{conn: conn} do {:ok, no_query, _} = live(conn, ~p"/members") refute has_element?(no_query, "[data-testid='search-clear']") {:ok, with_query, _} = live(conn, ~p"/members?query=Findable") assert has_element?(with_query, "[data-testid='search-clear']") end test "clear resets query, URL param and the result set", %{conn: conn, other: other} do {:ok, view, _html} = live(conn, ~p"/members?query=Findable") # The filtered list excludes the non-matching member. refute has_element?(view, "#row-#{other.id}") view |> element("[data-testid='search-clear']") |> render_click() # Query cleared in the URL (search param reset to empty). path = assert_patch(view) assert path =~ "query=" refute path =~ "query=Findable" # Result set resets to the unfiltered list (the previously excluded member returns). assert has_element?(view, "#row-#{other.id}") # The input no longer carries the query. refute has_element?(view, "[data-testid='search-input'][value='Findable']") end end