LiveView testing delete link with confirmation

Hi, I have a classic delete link with confirmation in my liveview

<%= link "Delete", to: "#", phx_click: "delete", phx_value_classid:, data: [confirm: "Are you sure?"] %>

and this is the test

assert index_live |> element("#class-#{} a", "Delete") |> render_click()
refute has_element?(index_live, "#class-#{}")

the refute test fails. I assume it’s because there’s the additional confirmation dialog where user needs to click OK? If so, how do I add that action into my test, please? This si a browser dialog, so it doesn’t seem to be possible to target it as html element.

1 Like

I’ve found that if the confirmation is for a form, then render_submit() will handle the confirmation OK in testing, for example:

<.form let={_f} for={:delete_class} id="delete-class-form" ... >
  <%= submit "Delete Class", data_confirm: "Are you sure?", ... %>
view |> form("#delete-class-form") |> render_submit()
# refute should pass

having the same problem as the author’s