towerops/test/towerops_web/components/cookie_consent_test.exs
Graham McIntire b96b1fabcb chore: add jump_credo_checks ~> 0.4 with all 19 checks enabled
All checks set to exit_status: 0 initially to avoid blocking on
pre-existing violations. Remove exit_status overrides as each
check category is cleaned up incrementally.
2026-06-12 13:44:31 -05:00

61 lines
1.6 KiB
Elixir

defmodule ToweropsWeb.Components.CookieConsentTest do
use ExUnit.Case, async: true
import Phoenix.Component
import Phoenix.LiveViewTest
alias ToweropsWeb.Components.CookieConsent
describe "banner/1" do
test "renders consent banner when requires_consent is true" do
assigns = %{requires_consent: true}
html =
rendered_to_string(~H"""
<CookieConsent.banner requires_consent={@requires_consent} />
""")
assert html =~ ~s(id="cookie-consent-banner")
assert html =~ "We respect your privacy"
assert html =~ "essential cookies"
assert html =~ ~s(href="/privacy")
assert html =~ "Accept"
end
test "renders nothing when requires_consent is false" do
assigns = %{requires_consent: false}
html =
rendered_to_string(~H"""
<CookieConsent.banner requires_consent={@requires_consent} />
""")
assert html == ""
end
test "has proper accessibility attributes" do
assigns = %{requires_consent: true}
html =
rendered_to_string(~H"""
<CookieConsent.banner requires_consent={@requires_consent} />
""")
assert html =~ ~s(role="dialog")
assert html =~ ~s(aria-label="Cookie consent")
assert html =~ ~s(aria-live="polite")
end
test "has functioning accept button with data attribute" do
assigns = %{requires_consent: true}
html =
rendered_to_string(~H"""
<CookieConsent.banner requires_consent={@requires_consent} />
""")
assert html =~ ~s(data-cookie-consent="accept")
assert html =~ ~s(type="button")
end
end
end