style: consistent back button and some translations
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:
parent
91cf7cca6a
commit
0f12befd11
26 changed files with 747 additions and 710 deletions
|
|
@ -46,6 +46,17 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
%{conn: conn, user: user_with_role}
|
||||
end
|
||||
|
||||
# Delete is in the edit form (FormComponent); open form by clicking the name cell (unique td with phx-click)
|
||||
defp open_delete_modal(view, custom_field) do
|
||||
view
|
||||
|> element("tr#custom_fields-#{custom_field.id} td", custom_field.name)
|
||||
|> render_click()
|
||||
|
||||
view
|
||||
|> element("[data-testid=custom-field-delete]")
|
||||
|> render_click()
|
||||
end
|
||||
|
||||
describe "delete button and modal" do
|
||||
test "opens modal with correct member count when delete is clicked", %{conn: conn} do
|
||||
{:ok, member} = create_member()
|
||||
|
|
@ -55,11 +66,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
create_custom_field_value(member, custom_field, "test")
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
# Click delete button - find the delete link within the component
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Modal should be visible
|
||||
assert has_element?(view, "#delete-custom-field-modal")
|
||||
|
|
@ -81,23 +88,17 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
create_custom_field_value(member2, custom_field, "test2")
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Should show plural form
|
||||
assert render(view) =~ "2 members have values assigned for this custom field"
|
||||
end
|
||||
|
||||
test "shows 0 members for custom field without values", %{conn: conn} do
|
||||
{:ok, _custom_field} = create_custom_field("test_field", :string)
|
||||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Should show 0 members
|
||||
assert render(view) =~ "0 members have values assigned for this custom field"
|
||||
|
|
@ -109,10 +110,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Type in slug input - use element to find the form with phx-target
|
||||
view
|
||||
|
|
@ -124,13 +122,10 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
end
|
||||
|
||||
test "delete button is disabled when slug doesn't match", %{conn: conn} do
|
||||
{:ok, _custom_field} = create_custom_field("test_field", :string)
|
||||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Type wrong slug - use element to find the form with phx-target
|
||||
view
|
||||
|
|
@ -149,11 +144,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
{:ok, custom_field_value} = create_custom_field_value(member, custom_field, "test")
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
# Open modal
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Enter correct slug - use element to find the form with phx-target
|
||||
view
|
||||
|
|
@ -162,7 +153,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
|
||||
# Click confirm
|
||||
view
|
||||
|> element("#delete-custom-field-modal button", "Delete Custom Field and All Values")
|
||||
|> element("#delete-custom-field-modal button", "Delete Datafields and All Values")
|
||||
|> render_click()
|
||||
|
||||
# Should show success message
|
||||
|
|
@ -186,10 +177,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Enter wrong slug - use element to find the form with phx-target
|
||||
view
|
||||
|
|
@ -210,10 +198,7 @@ defmodule MvWeb.CustomFieldLive.DeletionTest do
|
|||
{:ok, custom_field} = create_custom_field("test_field", :string)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/admin/datafields")
|
||||
|
||||
view
|
||||
|> element("#custom-fields-component a", "Delete")
|
||||
|> render_click()
|
||||
open_delete_modal(view, custom_field)
|
||||
|
||||
# Modal should be visible
|
||||
assert has_element?(view, "#delete-custom-field-modal")
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ defmodule MvWeb.RoleLiveTest do
|
|||
assert html =~ "System Role" || html =~ "system"
|
||||
end
|
||||
|
||||
test "delete button disabled for system roles", %{conn: conn, actor: actor} do
|
||||
test "delete button not shown for system roles", %{conn: conn, actor: actor} do
|
||||
system_role =
|
||||
Role
|
||||
|> Ash.Changeset.for_create(:create_role, %{
|
||||
|
|
@ -148,28 +148,19 @@ defmodule MvWeb.RoleLiveTest do
|
|||
|> Ash.Changeset.force_change_attribute(:is_system_role, true)
|
||||
|> Ash.create!(actor: actor)
|
||||
|
||||
{:ok, view, _html} = live(conn, "/admin/roles")
|
||||
{:ok, view, _html} = live(conn, "/admin/roles/#{system_role.id}")
|
||||
|
||||
assert has_element?(
|
||||
view,
|
||||
"button[phx-click='delete'][phx-value-id='#{system_role.id}'][disabled]"
|
||||
) ||
|
||||
not has_element?(
|
||||
view,
|
||||
"button[phx-click='delete'][phx-value-id='#{system_role.id}']"
|
||||
)
|
||||
# Danger zone (and delete button) is not rendered for system roles
|
||||
refute has_element?(view, "[data-testid=role-delete]")
|
||||
end
|
||||
|
||||
test "delete button enabled for non-system roles", %{conn: conn} do
|
||||
role = create_role()
|
||||
|
||||
{:ok, view, html} = live(conn, "/admin/roles")
|
||||
{:ok, view, _html} = live(conn, "/admin/roles/#{role.id}")
|
||||
|
||||
# Delete is a link with phx-click containing delete event
|
||||
# Check if delete link exists in HTML (phx-click contains delete and role id)
|
||||
assert (html =~ "phx-click" && html =~ "delete" && html =~ role.id) ||
|
||||
has_element?(view, "a[phx-click*='delete'][phx-value-id='#{role.id}']") ||
|
||||
has_element?(view, "a[aria-label='Delete role']")
|
||||
# Delete is on show page (Danger zone)
|
||||
assert has_element?(view, "[data-testid=role-delete]")
|
||||
end
|
||||
|
||||
test "new role button navigates to form", %{conn: conn} do
|
||||
|
|
@ -393,21 +384,21 @@ defmodule MvWeb.RoleLiveTest do
|
|||
test "deletes non-system role", %{conn: conn, actor: actor} do
|
||||
role = create_role()
|
||||
|
||||
{:ok, view, html} = live(conn, "/admin/roles")
|
||||
{:ok, view, _html} = live(conn, "/admin/roles/#{role.id}")
|
||||
|
||||
# Delete is a link - JS.push creates phx-click with value containing id
|
||||
# Verify the role id is in the HTML (in phx-click value)
|
||||
assert html =~ role.id
|
||||
# Delete from Danger zone on show page
|
||||
view
|
||||
|> element("[data-testid=role-delete]")
|
||||
|> render_click()
|
||||
|
||||
# Send delete event directly to avoid selector issues with multiple delete buttons
|
||||
render_click(view, "delete", %{"id" => role.id})
|
||||
assert_redirect(view, "/admin/roles")
|
||||
|
||||
# Verify deletion by checking database
|
||||
assert {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.NotFound{}]}} =
|
||||
Authorization.get_role(role.id, actor: actor)
|
||||
end
|
||||
|
||||
test "fails to delete system role with error message", %{conn: conn, actor: actor} do
|
||||
test "system role has no delete button and cannot be deleted", %{conn: conn, actor: actor} do
|
||||
system_role =
|
||||
Role
|
||||
|> Ash.Changeset.for_create(:create_role, %{
|
||||
|
|
@ -417,19 +408,12 @@ defmodule MvWeb.RoleLiveTest do
|
|||
|> Ash.Changeset.force_change_attribute(:is_system_role, true)
|
||||
|> Ash.create!(actor: actor)
|
||||
|
||||
{:ok, view, html} = live(conn, "/admin/roles")
|
||||
{:ok, view, _html} = live(conn, "/admin/roles/#{system_role.id}")
|
||||
|
||||
# System role delete button should be disabled
|
||||
assert html =~ "disabled" || html =~ "cursor-not-allowed" ||
|
||||
html =~ "System roles cannot be deleted"
|
||||
# Danger zone is not rendered for system roles (no delete button)
|
||||
refute has_element?(view, "[data-testid=role-delete]")
|
||||
|
||||
# Try to delete via event (backend check)
|
||||
render_click(view, "delete", %{"id" => system_role.id})
|
||||
|
||||
# Should show error message
|
||||
assert render(view) =~ "System roles cannot be deleted"
|
||||
|
||||
# Role should still exist
|
||||
# Role still exists
|
||||
{:ok, _role} = Authorization.get_role(system_role.id, actor: actor)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,14 +10,16 @@ defmodule MvWeb.UserLiveAuthorizationTest do
|
|||
|
||||
describe "User Index - Admin" do
|
||||
@tag role: :admin
|
||||
test "sees New User, Edit and Delete buttons", %{conn: conn} do
|
||||
test "sees New User button; Edit and Delete are on show page", %{conn: conn} do
|
||||
user = Fixtures.user_with_role_fixture("admin")
|
||||
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
{:ok, index_view, _html} = live(conn, "/users")
|
||||
assert has_element?(index_view, "[data-testid=user-new]")
|
||||
|
||||
assert has_element?(view, "[data-testid=user-new]")
|
||||
assert has_element?(view, "#row-#{user.id} [data-testid=user-edit]")
|
||||
assert has_element?(view, "#row-#{user.id} [data-testid=user-delete]")
|
||||
# Edit and Delete are on user show page (Danger zone), not on index
|
||||
{:ok, show_view, _html} = live(conn, "/users/#{user.id}")
|
||||
assert has_element?(show_view, "[data-testid=user-edit]")
|
||||
assert has_element?(show_view, "[data-testid=user-delete]")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,10 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
assert html =~ "alice@example.com"
|
||||
assert html =~ "bob@example.com"
|
||||
|
||||
# UI elements: New User button, action links
|
||||
# UI elements: New User button; row click navigates to show (no Edit/Delete on index)
|
||||
assert html =~ "New User"
|
||||
assert html =~ "Edit"
|
||||
assert html =~ "Delete"
|
||||
assert html =~ ~r/href="[^"]*\/users\/#{user1.id}\/edit"/
|
||||
# Row or navigation contains user id (e.g. row id or phx-click navigate)
|
||||
assert html =~ "row-#{user1.id}" or html =~ to_string(user1.id)
|
||||
end
|
||||
|
||||
@tag :ui
|
||||
|
|
@ -116,177 +115,29 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "checkbox selection functionality" do
|
||||
setup do
|
||||
user1 = create_test_user(%{email: "user1@example.com", oidc_id: "user1"})
|
||||
user2 = create_test_user(%{email: "user2@example.com", oidc_id: "user2"})
|
||||
%{users: [user1, user2]}
|
||||
end
|
||||
|
||||
@tag :ui
|
||||
test "shows checkbox UI elements", %{conn: conn, users: [user1, user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
# Check select all checkbox exists
|
||||
assert html =~ ~s(name="select_all")
|
||||
assert html =~ ~s(phx-click="select_all")
|
||||
|
||||
# Check individual user checkboxes exist
|
||||
assert html =~ ~s(name="#{user1.id}")
|
||||
assert html =~ ~s(name="#{user2.id}")
|
||||
assert html =~ ~s(phx-click="select_user")
|
||||
end
|
||||
|
||||
@tag :ui
|
||||
test "can select and deselect individual users", %{conn: conn, users: [user1, user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Initially, individual checkboxes should exist but not be checked
|
||||
assert view |> element("input[type='checkbox'][name='#{user1.id}']") |> has_element?()
|
||||
assert view |> element("input[type='checkbox'][name='#{user2.id}']") |> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Select first user checkbox
|
||||
html = view |> element("input[type='checkbox'][name='#{user1.id}']") |> render_click()
|
||||
assert html =~ "Email"
|
||||
assert html =~ to_string(user1.email)
|
||||
|
||||
# The select_all checkbox should still not be checked (not all users selected)
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Deselect user
|
||||
html = view |> element("input[type='checkbox'][name='#{user1.id}']") |> render_click()
|
||||
assert html =~ "Email"
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
end
|
||||
|
||||
@tag :ui
|
||||
test "select all and deselect all functionality", %{conn: conn, users: [user1, user2]} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
|
||||
# Initially no checkboxes should be checked
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user1.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user2.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Click select all
|
||||
html = view |> element("input[type='checkbox'][name='select_all']") |> render_click()
|
||||
|
||||
# After selecting all, the select_all checkbox should be checked
|
||||
assert view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
assert html =~ "Email"
|
||||
assert html =~ to_string(user1.email)
|
||||
assert html =~ to_string(user2.email)
|
||||
|
||||
# Then deselect all
|
||||
html = view |> element("input[type='checkbox'][name='select_all']") |> render_click()
|
||||
|
||||
# After deselecting all, no checkboxes should be checked
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user1.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='#{user2.id}'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
assert html =~ "Email"
|
||||
end
|
||||
|
||||
@tag :slow
|
||||
test "select all automatically checks when all individual users are selected", %{
|
||||
conn: conn,
|
||||
users: [_user1, _user2]
|
||||
} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, html} = live(conn, "/users")
|
||||
|
||||
# Get all user IDs from the rendered HTML by finding all checkboxes with phx-click="select_user"
|
||||
# Extract user IDs from the HTML (they appear as name attributes on checkboxes)
|
||||
user_ids =
|
||||
html
|
||||
|> String.split("phx-click=\"select_user\"")
|
||||
|> Enum.flat_map(fn part ->
|
||||
case Regex.run(~r/name="([^"]+)"[^>]*phx-value-id/, part) do
|
||||
[_, user_id] -> [user_id]
|
||||
_ -> []
|
||||
end
|
||||
end)
|
||||
|> Enum.uniq()
|
||||
|
||||
# Skip if no users found (shouldn't happen, but be safe)
|
||||
if user_ids != [] do
|
||||
# Initially nothing should be checked
|
||||
refute view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
|
||||
# Select all users one by one
|
||||
Enum.each(user_ids, fn user_id ->
|
||||
view |> element("input[type='checkbox'][name='#{user_id}']") |> render_click()
|
||||
end)
|
||||
|
||||
# Now select all should be automatically checked (all individual users are selected)
|
||||
assert view
|
||||
|> element("input[type='checkbox'][name='select_all'][checked]")
|
||||
|> has_element?()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete functionality" do
|
||||
test "can delete a user", %{conn: conn} do
|
||||
_user = create_test_user(%{email: "delete-me@example.com"})
|
||||
# Delete is only on user show page (Danger zone), not on index (per CODE_GUIDELINES: at most one UI smoke test for delete)
|
||||
test "can delete a user from show page", %{conn: conn} do
|
||||
user = create_test_user(%{email: "delete-me@example.com"})
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/users")
|
||||
{:ok, index_view, _html} = live(conn, "/users")
|
||||
assert render(index_view) =~ "delete-me@example.com"
|
||||
|
||||
# Confirm user is displayed
|
||||
assert render(view) =~ "delete-me@example.com"
|
||||
# Navigate to user show and trigger delete from Danger zone
|
||||
{:ok, show_view, _html} = live(conn, "/users/#{user.id}")
|
||||
|
||||
# Click the delete button (phx-click="delete" event)
|
||||
view |> element("tbody tr:first-child a[data-confirm]") |> render_click()
|
||||
show_view
|
||||
|> element("[data-testid=user-delete]")
|
||||
|> render_click()
|
||||
|
||||
# Verify user was actually deleted (should not appear in HTML anymore)
|
||||
html = render(view)
|
||||
# Should redirect to index
|
||||
assert_redirect(show_view, "/users")
|
||||
|
||||
# Reload index with same session; user should be gone
|
||||
{:ok, _view_after, html} = live(conn, "/users")
|
||||
refute html =~ "delete-me@example.com"
|
||||
# Table header should still be there
|
||||
assert html =~ "Email"
|
||||
end
|
||||
|
||||
test "shows delete confirmation", %{conn: conn} do
|
||||
_user = create_test_user(%{email: "confirm-delete@example.com"})
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
# Check that delete link has confirmation attribute
|
||||
assert html =~ ~s(data-confirm="Are you sure?")
|
||||
end
|
||||
end
|
||||
|
||||
describe "navigation" do
|
||||
|
|
@ -296,36 +147,14 @@ defmodule MvWeb.UserLive.IndexTest do
|
|||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, _view, html} = live(conn, "/users")
|
||||
|
||||
# Check that user row contains link to show page
|
||||
# Row click navigates to show page (edit is on show page)
|
||||
assert html =~ ~s(/users/#{user.id})
|
||||
|
||||
# Check edit link points to correct edit page
|
||||
assert html =~ ~s(/users/#{user.id}/edit)
|
||||
|
||||
# Check new user button points to correct new page
|
||||
assert html =~ ~s(/users/new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "translations" do
|
||||
@tag :ui
|
||||
test "shows translations for selection in different locales", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
|
||||
# Test German translations
|
||||
conn = Plug.Test.init_test_session(conn, locale: "de")
|
||||
{:ok, _view, html_de} = live(conn, "/users")
|
||||
assert html_de =~ "Alle Benutzer*innen auswählen"
|
||||
assert html_de =~ "Benutzer*in auswählen"
|
||||
|
||||
# Test English translations
|
||||
Gettext.put_locale(MvWeb.Gettext, "en")
|
||||
{:ok, _view, html_en} = live(conn, "/users")
|
||||
# Check that aria-label attributes exist (structure is there)
|
||||
assert html_en =~ ~s(aria-label=)
|
||||
end
|
||||
end
|
||||
|
||||
describe "edge cases" do
|
||||
test "handles empty user list gracefully", %{conn: conn} do
|
||||
# Don't create any users besides the authenticated one
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue