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: class.id, data: [confirm: "Are you sure?"] %>

and this is the test

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

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.

2 Likes

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?", ... %>
</.form>
...
view |> form("#delete-class-form") |> render_submit()
# refute should pass

having the same problem as the author’s