feat(custom-field): let admins set join_description with a link-syntax hint

This commit is contained in:
Simon 2026-06-03 12:28:23 +02:00
parent df271055a8
commit 404d524ee1
5 changed files with 171 additions and 0 deletions

View file

@ -0,0 +1,102 @@
defmodule MvWeb.CustomFieldLive.FormTest do
@moduledoc """
Tests for the CustomFieldLive.FormComponent join_description input.
Covers that an admin can set and persist a custom field's join_description via
the settings edit form.
"""
use MvWeb.ConnCase, async: true
import Phoenix.LiveViewTest
require Ash.Query
alias Mv.Membership.CustomField
setup do
system_actor = Mv.Helpers.SystemActor.get_system_actor()
admin_role = Mv.Fixtures.role_fixture("admin")
{:ok, user} =
Mv.Accounts.User
|> Ash.Changeset.for_create(:register_with_password, %{
email: "admin#{System.unique_integer([:positive])}@mv.local",
password: "testpassword123"
})
|> Ash.create(actor: system_actor)
{:ok, user} =
user
|> Ash.Changeset.for_update(:update, %{})
|> Ash.Changeset.manage_relationship(:role, admin_role, type: :append_and_remove)
|> Ash.update(actor: system_actor)
user_with_role = Ash.load!(user, :role, domain: Mv.Accounts, actor: system_actor)
conn = log_in_user(build_conn(), user_with_role)
session = conn.private[:plug_session] || %{}
conn = Plug.Test.init_test_session(conn, Map.put(session, "locale", "en"))
%{conn: conn, actor: system_actor}
end
defp log_in_user(conn, user) do
conn
|> Phoenix.ConnTest.init_test_session(%{})
|> AshAuthentication.Plug.Helpers.store_in_session(user)
end
defp open_edit_form(view, custom_field) do
view
|> element("tr#custom_fields-#{custom_field.id} td", custom_field.name)
|> render_click()
end
describe "join_description input" do
test "form shows a join_description input", %{conn: conn, actor: actor} do
{:ok, custom_field} =
CustomField
|> Ash.Changeset.for_create(:create, %{name: "dsgvo_field", value_type: :boolean})
|> Ash.create(actor: actor)
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
open_edit_form(view, custom_field)
assert has_element?(view, "input[name='custom_field[join_description]']")
end
test "form shows an info tooltip explaining allowed link syntax", %{conn: conn, actor: actor} do
{:ok, custom_field} =
CustomField
|> Ash.Changeset.for_create(:create, %{name: "dsgvo_field", value_type: :boolean})
|> Ash.create(actor: actor)
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
open_edit_form(view, custom_field)
assert has_element?(
view,
"[data-testid='join-description-link-hint'] .hero-information-circle"
)
end
test "form accepts and persists join_description", %{conn: conn, actor: actor} do
{:ok, custom_field} =
CustomField
|> Ash.Changeset.for_create(:create, %{name: "dsgvo_field", value_type: :boolean})
|> Ash.create(actor: actor)
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
open_edit_form(view, custom_field)
view
|> form("#custom-field-form-#{custom_field.id}-form", %{
"custom_field" => %{
"name" => custom_field.name,
"join_description" => "Accept the GDPR at https://example.com/dsgvo"
}
})
|> render_submit()
updated = Ash.get!(CustomField, custom_field.id, actor: actor)
assert updated.join_description == "Accept the GDPR at https://example.com/dsgvo"
end
end
end