From 7f15909cc6aa474f4371076363971a2569e68086 Mon Sep 17 00:00:00 2001 From: carla Date: Thu, 26 Feb 2026 17:14:47 +0100 Subject: [PATCH] fix tests --- .../live/custom_field_live/index_component.ex | 1 + lib/mv_web/live/role_live/show.ex | 1 + .../live/custom_field_live/deletion_test.exs | 18 +++++++++++------- test/mv_web/live/role_live_test.exs | 7 ++++++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/mv_web/live/custom_field_live/index_component.ex b/lib/mv_web/live/custom_field_live/index_component.ex index f9dca11..6d1fc2f 100644 --- a/lib/mv_web/live/custom_field_live/index_component.ex +++ b/lib/mv_web/live/custom_field_live/index_component.ex @@ -54,6 +54,7 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do <.table id="custom_fields_table" rows={@streams.custom_fields} + row_id={fn {_stream_key, cf} -> "custom_fields-#{cf.id}" end} row_click={ fn {_id, custom_field} -> JS.push("edit_custom_field", value: %{id: custom_field.id}, target: @myself) diff --git a/lib/mv_web/live/role_live/show.ex b/lib/mv_web/live/role_live/show.ex index 7455a1a..ae390c3 100644 --- a/lib/mv_web/live/role_live/show.ex +++ b/lib/mv_web/live/role_live/show.ex @@ -307,6 +307,7 @@ defmodule MvWeb.RoleLive.Show do type="button" variant="danger" phx-click={JS.push("delete", value: %{id: @role.id})} + data-testid="role-delete-confirm" aria-label={gettext("Delete role")} > {gettext("Delete")} diff --git a/test/mv_web/live/custom_field_live/deletion_test.exs b/test/mv_web/live/custom_field_live/deletion_test.exs index e841120..962ada1 100644 --- a/test/mv_web/live/custom_field_live/deletion_test.exs +++ b/test/mv_web/live/custom_field_live/deletion_test.exs @@ -46,15 +46,19 @@ 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) + # Delete is in the edit form (FormComponent). First row click opens form (overview) or switches + # to edit-mode (new component shows table). If delete button is visible, click it; else click row + # again to open the form, then click delete. defp open_delete_modal(view, custom_field) do - view - |> element("tr#custom_fields-#{custom_field.id} td", custom_field.name) - |> render_click() + row_selector = "tr#custom_fields-#{custom_field.id} td" + view |> element(row_selector, custom_field.name) |> render_click() - view - |> element("[data-testid=custom-field-delete]") - |> render_click() + if has_element?(view, "[data-testid=custom-field-delete]") do + view |> element("[data-testid=custom-field-delete]") |> render_click() + else + view |> element(row_selector, custom_field.name) |> render_click() + view |> element("[data-testid=custom-field-delete]") |> render_click() + end end describe "delete button and modal" do diff --git a/test/mv_web/live/role_live_test.exs b/test/mv_web/live/role_live_test.exs index 57ce814..2bbb443 100644 --- a/test/mv_web/live/role_live_test.exs +++ b/test/mv_web/live/role_live_test.exs @@ -386,11 +386,16 @@ defmodule MvWeb.RoleLiveTest do {:ok, view, _html} = live(conn, "/admin/roles/#{role.id}") - # Delete from Danger zone on show page + # Open delete modal from Danger zone view |> element("[data-testid=role-delete]") |> render_click() + # Confirm deletion in modal + view + |> element("[data-testid=role-delete-confirm]") + |> render_click() + assert_redirect(view, "/admin/roles") # Verify deletion by checking database