Merge branch 'main' into feature/209_hide_field_dropdown
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
5ae4450444
14 changed files with 727 additions and 554 deletions
|
|
@ -1,6 +1,7 @@
|
|||
defmodule MvWeb.CustomFieldLive.DeletionTest do
|
||||
@moduledoc """
|
||||
Tests for CustomFieldLive.Index deletion modal and slug confirmation.
|
||||
Tests for CustomFieldLive.IndexComponent deletion modal and slug confirmation.
|
||||
Tests the custom field management component embedded in the settings page.
|
||||
|
||||
Tests cover:
|
||||
- Opening deletion confirmation modal
|
||||
|
|
@ -39,11 +40,11 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
# Create custom field value
|
||||
create_custom_field_value(member, custom_field, "test")
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
# Click delete button
|
||||
# Click delete button - find the delete link within the component
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Modal should be visible
|
||||
|
|
@ -65,10 +66,10 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
create_custom_field_value(member1, custom_field, "test1")
|
||||
create_custom_field_value(member2, custom_field, "test2")
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Should show plural form
|
||||
|
|
@ -78,10 +79,10 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
test "shows 0 members for custom field without values", %{conn: conn} do
|
||||
{:ok, _custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Should show 0 members
|
||||
|
|
@ -93,15 +94,16 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
test "updates confirmation state when typing", %{conn: conn} do
|
||||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Type in slug input
|
||||
# Type in slug input - use element to find the form with phx-target
|
||||
view
|
||||
|> render_change("update_slug_confirmation", %{"slug" => custom_field.slug})
|
||||
|> element("#delete-custom-field-modal form")
|
||||
|> render_change(%{"slug" => custom_field.slug})
|
||||
|
||||
# Confirm button should be enabled now (no disabled attribute)
|
||||
html = render(view)
|
||||
|
|
@ -111,15 +113,16 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
test "delete button is disabled when slug doesn't match", %{conn: conn} do
|
||||
{:ok, _custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Type wrong slug
|
||||
# Type wrong slug - use element to find the form with phx-target
|
||||
view
|
||||
|> render_change("update_slug_confirmation", %{"slug" => "wrong-slug"})
|
||||
|> element("#delete-custom-field-modal form")
|
||||
|> render_change(%{"slug" => "wrong-slug"})
|
||||
|
||||
# Button should be disabled
|
||||
html = render(view)
|
||||
|
|
@ -133,20 +136,21 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
{:ok, custom_field_value} = create_custom_field_value(member, custom_field, "test")
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
# Open modal
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Enter correct slug
|
||||
# Enter correct slug - use element to find the form with phx-target
|
||||
view
|
||||
|> render_change("update_slug_confirmation", %{"slug" => custom_field.slug})
|
||||
|> element("#delete-custom-field-modal form")
|
||||
|> render_change(%{"slug" => custom_field.slug})
|
||||
|
||||
# Click confirm
|
||||
view
|
||||
|> element("button", "Delete Custom Field and All Values")
|
||||
|> element("#delete-custom-field-modal button", "Delete Custom Field and All Values")
|
||||
|> render_click()
|
||||
|
||||
# Should show success message
|
||||
|
|
@ -162,27 +166,28 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
assert {:ok, _} = Ash.get(Member, member.id)
|
||||
end
|
||||
|
||||
test "shows error when slug doesn't match", %{conn: conn} do
|
||||
test "button remains disabled and custom field not deleted when slug doesn't match", %{
|
||||
conn: conn
|
||||
} do
|
||||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Enter wrong slug
|
||||
# Enter wrong slug - use element to find the form with phx-target
|
||||
view
|
||||
|> render_change("update_slug_confirmation", %{"slug" => "wrong-slug"})
|
||||
|> element("#delete-custom-field-modal form")
|
||||
|> render_change(%{"slug" => "wrong-slug"})
|
||||
|
||||
# Try to confirm (button should be disabled, but test the handler anyway)
|
||||
view
|
||||
|> render_click("confirm_delete", %{})
|
||||
# Button should be disabled and we cannot click it
|
||||
# The test verifies that the button is properly disabled in the UI
|
||||
html = render(view)
|
||||
assert html =~ ~r/disabled(?:=""|(?!\w))/
|
||||
|
||||
# Should show error message
|
||||
assert render(view) =~ "Slug does not match"
|
||||
|
||||
# Custom field should still exist
|
||||
# Custom field should still exist since deletion couldn't proceed
|
||||
assert {:ok, _} = Ash.get(CustomField, custom_field.id)
|
||||
end
|
||||
end
|
||||
|
|
@ -191,10 +196,10 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
test "closes modal without deleting", %{conn: conn} do
|
||||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/custom_fields")
|
||||
{:ok, view, _html} = live(conn, ~p"/settings")
|
||||
|
||||
view
|
||||
|> element("a", "Delete")
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
|
||||
# Modal should be visible
|
||||
|
|
@ -202,7 +207,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
|
||||
# Click cancel
|
||||
view
|
||||
|> element("button", "Cancel")
|
||||
|> element("#delete-custom-field-modal button", "Cancel")
|
||||
|> render_click()
|
||||
|
||||
# Modal should be gone
|
||||
|
|
|
|||
|
|
@ -148,8 +148,6 @@ defmodule MvWeb.ProfileNavigationTest do
|
|||
"/members/new",
|
||||
"/custom_field_values",
|
||||
"/custom_field_values/new",
|
||||
"/custom_fields",
|
||||
"/custom_fields/new",
|
||||
"/users",
|
||||
"/users/new"
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue