fix: pass actor to CustomFieldLive.FormComponent for save
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
IndexComponent now passes actor to FormComponent; FormComponent uses assigns[:actor] instead of current_actor(socket). Add test that submits new custom field form on settings page.
This commit is contained in:
parent
21dbdbe366
commit
2931632aa8
3 changed files with 44 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
use MvWeb.ConnCase, async: true
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
require Ash.Query
|
||||
|
||||
alias Mv.Membership.{CustomField, CustomFieldValue, Member}
|
||||
|
||||
|
|
@ -230,6 +231,46 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "create custom field" do
|
||||
test "submitting new data field form creates custom field and shows success", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
# Open "New Data Field" form
|
||||
view
|
||||
|> element("#custom-fields-component button", "New Data Field")
|
||||
|> render_click()
|
||||
|
||||
# Form is visible; submit with valid data
|
||||
form_params = %{
|
||||
"custom_field" => %{
|
||||
"name" => "Created via Form",
|
||||
"value_type" => "string",
|
||||
"description" => "",
|
||||
"required" => "false",
|
||||
"show_in_overview" => "true"
|
||||
}
|
||||
}
|
||||
|
||||
view
|
||||
|> form("#custom-field-form-new-form", form_params)
|
||||
|> render_submit()
|
||||
|
||||
# Success flash (FormComponent needs actor from parent; without it KeyError would occur)
|
||||
assert render(view) =~ "successfully"
|
||||
|
||||
# Custom field was created in DB
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
search_name = "Created via Form"
|
||||
|
||||
[custom_field] =
|
||||
Mv.Membership.CustomField
|
||||
|> Ash.Query.filter(name == ^search_name)
|
||||
|> Ash.read!(actor: system_actor)
|
||||
|
||||
assert custom_field.value_type == :string
|
||||
end
|
||||
end
|
||||
|
||||
# Helper functions
|
||||
defp create_member do
|
||||
system_actor = Mv.Helpers.SystemActor.get_system_actor()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue