defmodule ToweropsWeb.LiveViewTestHelpers do @moduledoc """ Helpers for LiveView tests using data-testid attributes. Provides `assert_has/2,3` and `refute_has/2` for structural assertions that are resilient to text/wording changes in templates. """ import ExUnit.Assertions import Phoenix.LiveViewTest @doc "Assert an element with the given data-testid exists" def assert_has(view, testid) do assert has_element?(view, "[data-testid='#{testid}']") end @doc "Assert an element with the given data-testid exists and contains text" def assert_has(view, testid, text) do assert has_element?(view, "[data-testid='#{testid}']", text) end @doc "Refute an element with the given data-testid exists" def refute_has(view, testid) do refute has_element?(view, "[data-testid='#{testid}']") end end