defmodule MvWeb.Components.BulkActionsDropdownTest do use MvWeb.ConnCase, async: true import Phoenix.LiveViewTest alias MvWeb.Components.BulkActionsDropdown defp render_open(assigns) do base = %{ id: "bulk-actions-dropdown", open: true, export_payload_json: ~s({"selected_ids":[]}), selected_count: 0, scope: :all, mailto_bcc: "a%40example.com", recipient_count: 1, mailto_disabled?: false } render_component(BulkActionsDropdown, Map.merge(base, assigns)) end defp scope_badge(html) do html |> LazyHTML.from_fragment() |> LazyHTML.query(~s([data-testid="bulk-actions-scope-badge"])) end describe "trigger scope badge" do test "shows an emphasized primary count badge when members are selected" do html = render_component(BulkActionsDropdown, %{id: "d", scope: :selection, selected_count: 3}) badge = scope_badge(html) assert badge |> LazyHTML.text() |> String.trim() == "3" classes = badge |> LazyHTML.attribute("class") |> List.first() assert classes =~ "badge-primary" assert classes =~ "badge-sm" # The trigger label itself is just the bare action verb, no parenthetical. assert html =~ "Actions" refute html =~ "(3)" end test "shows a muted neutral 'all' badge when nothing selected and no filter" do html = render_component(BulkActionsDropdown, %{id: "d", scope: :all, selected_count: 0}) badge = scope_badge(html) assert badge |> LazyHTML.text() |> String.trim() == "all" classes = badge |> LazyHTML.attribute("class") |> List.first() assert classes =~ "badge-neutral" assert classes =~ "badge-sm" refute html =~ "(all)" end test "shows a muted neutral 'filtered' badge when a filter is active" do html = render_component(BulkActionsDropdown, %{id: "d", scope: :filtered, selected_count: 0}) badge = scope_badge(html) assert badge |> LazyHTML.text() |> String.trim() == "filtered" classes = badge |> LazyHTML.attribute("class") |> List.first() assert classes =~ "badge-neutral" assert classes =~ "badge-sm" refute html =~ "(filtered)" end end describe "trigger affordance" do test "carries a trailing chevron" do html = render_component(BulkActionsDropdown, %{id: "d", scope: :all, selected_count: 0}) assert html =~ "hero-chevron-down" end end describe "menu item layout" do test "all menu items carry whitespace-nowrap to prevent label text wrapping" do html = render_open(%{}) doc = LazyHTML.from_fragment(html) # Collect all elements with role="menuitem" (both and