towerops/test/towerops_web/components/consent_prompt_test.exs

53 lines
1.6 KiB
Elixir

defmodule ToweropsWeb.Components.ConsentPromptTest do
use ExUnit.Case, async: true
import Phoenix.Component
import Phoenix.LiveViewTest
alias ToweropsWeb.Components.ConsentPrompt
describe "consent_modal/1" do
test "renders nothing when there are no policies" do
assigns = %{user_id: "user-1", policies: []}
html =
rendered_to_string(~H"""
<ConsentPrompt.consent_modal user_id={@user_id} policies={@policies} />
""")
assert html == ""
end
test "renders translated consent checkboxes and links for known policies" do
assigns = %{user_id: "user-1", policies: ["privacy_policy", "terms_of_service"]}
html =
rendered_to_string(~H"""
<ConsentPrompt.consent_modal user_id={@user_id} policies={@policies} />
""")
assert html =~ ~s(id="consent-modal")
assert html =~ ~s(phx-value-user-id="user-1")
assert html =~ ~s(id="consent-privacy_policy")
assert html =~ ~s(href="/privacy")
assert html =~ "Privacy Policy"
assert html =~ ~s(id="consent-terms_of_service")
assert html =~ ~s(href="/terms")
assert html =~ "Terms of Service"
assert html =~ "Accept and Continue"
end
test "falls back to the generic policy label and root link for unknown policies" do
assigns = %{user_id: "user-1", policies: ["custom_policy"]}
html =
rendered_to_string(~H"""
<ConsentPrompt.consent_modal user_id={@user_id} policies={@policies} />
""")
assert html =~ ~s(id="consent-custom_policy")
assert html =~ ~s(href="/")
assert html =~ "Policy"
end
end
end