diff --git a/lib/mv_web/live/custom_field_live/form_component.ex b/lib/mv_web/live/custom_field_live/form_component.ex index 2e98aeb..1663b4e 100644 --- a/lib/mv_web/live/custom_field_live/form_component.ex +++ b/lib/mv_web/live/custom_field_live/form_component.ex @@ -91,6 +91,45 @@ defmodule MvWeb.CustomFieldLive.FormComponent do <% end %> <.input field={@form[:description]} type="text" label={gettext("Description")} /> + +
+ <.input field={@form[:required]} type="checkbox" label={gettext("Required")} /> <.input field={@form[:show_in_overview]} diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index 4f895bb..94e26ac 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -3972,3 +3972,13 @@ msgstr "Bis" #, elixir-autogen, elixir-format msgid "Join form:" 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://…)." diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 6bdbc40..7707714 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -3972,3 +3972,13 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Join form:" 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 "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 82a52a6..bed9227 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -3972,3 +3972,13 @@ msgstr "" #, elixir-autogen, elixir-format, fuzzy msgid "Join form:" 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 "" diff --git a/test/mv_web/live/custom_field_live/form_test.exs b/test/mv_web/live/custom_field_live/form_test.exs new file mode 100644 index 0000000..4f7c8ec --- /dev/null +++ b/test/mv_web/live/custom_field_live/form_test.exs @@ -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