feat(custom-field): let admins set join_description with a link-syntax hint
This commit is contained in:
parent
df271055a8
commit
404d524ee1
5 changed files with 171 additions and 0 deletions
|
|
@ -91,6 +91,45 @@ defmodule MvWeb.CustomFieldLive.FormComponent do
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<.input field={@form[:description]} type="text" label={gettext("Description")} />
|
<.input field={@form[:description]} type="text" label={gettext("Description")} />
|
||||||
|
|
||||||
|
<fieldset class="mb-2 fieldset">
|
||||||
|
<label>
|
||||||
|
<span class="mb-1 label flex items-center gap-2">
|
||||||
|
{gettext("Description for join form")}
|
||||||
|
<.tooltip
|
||||||
|
content={
|
||||||
|
gettext(
|
||||||
|
"You can add links: full addresses (https://…) or as [link text](https://…)."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
position="right"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
data-testid="join-description-link-hint"
|
||||||
|
aria-label={
|
||||||
|
gettext(
|
||||||
|
"You can add links: full addresses (https://…) or as [link text](https://…)."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<.icon
|
||||||
|
name="hero-information-circle"
|
||||||
|
class="w-4 h-4 text-base-content/60 cursor-help"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</.tooltip>
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name={@form[:join_description].name}
|
||||||
|
id={@form[:join_description].id}
|
||||||
|
value={Phoenix.HTML.Form.normalize_value("text", @form[:join_description].value)}
|
||||||
|
class="w-full input"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<.input field={@form[:required]} type="checkbox" label={gettext("Required")} />
|
<.input field={@form[:required]} type="checkbox" label={gettext("Required")} />
|
||||||
<.input
|
<.input
|
||||||
field={@form[:show_in_overview]}
|
field={@form[:show_in_overview]}
|
||||||
|
|
|
||||||
|
|
@ -3972,3 +3972,13 @@ msgstr "Bis"
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Join form:"
|
msgid "Join form:"
|
||||||
msgstr "Beitrittsformular:"
|
msgstr "Beitrittsformular:"
|
||||||
|
|
||||||
|
#: lib/mv_web/live/custom_field_live/form_component.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Description for join form"
|
||||||
|
msgstr "Beschreibung für das Beitrittsformular"
|
||||||
|
|
||||||
|
#: lib/mv_web/live/custom_field_live/form_component.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "You can add links: full addresses (https://…) or as [link text](https://…)."
|
||||||
|
msgstr "Du kannst Links einfügen: ganze Adressen (https://…) oder als [Linktext](https://…)."
|
||||||
|
|
|
||||||
|
|
@ -3972,3 +3972,13 @@ msgstr ""
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Join form:"
|
msgid "Join form:"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/mv_web/live/custom_field_live/form_component.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Description for join form"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/mv_web/live/custom_field_live/form_component.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "You can add links: full addresses (https://…) or as [link text](https://…)."
|
||||||
|
msgstr ""
|
||||||
|
|
|
||||||
|
|
@ -3972,3 +3972,13 @@ msgstr ""
|
||||||
#, elixir-autogen, elixir-format, fuzzy
|
#, elixir-autogen, elixir-format, fuzzy
|
||||||
msgid "Join form:"
|
msgid "Join form:"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/mv_web/live/custom_field_live/form_component.ex
|
||||||
|
#, elixir-autogen, elixir-format, fuzzy
|
||||||
|
msgid "Description for join form"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/mv_web/live/custom_field_live/form_component.ex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "You can add links: full addresses (https://…) or as [link text](https://…)."
|
||||||
|
msgstr ""
|
||||||
|
|
|
||||||
102
test/mv_web/live/custom_field_live/form_test.exs
Normal file
102
test/mv_web/live/custom_field_live/form_test.exs
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue