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"""
""")
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"""
""")
assert html == ""
end
test "has proper accessibility attributes" do
assigns = %{requires_consent: true}
html =
rendered_to_string(~H"""
""")
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"""
""")
assert html =~ ~s(data-cookie-consent="accept")
assert html =~ ~s(type="button")
end
end
end