Add tests to ensure path changes when modal is dismissed (#1356)

Refs #1353 

I was looking for a `refute_el` helper to check for `.modal.is-active`
*not* being on the page, but that would take time to write 😅

This checks to ensure the URL is updated, which should cause the
`@live_action` to change, the view to be patched, and the modal to be
dismissed, but isn't the most straightforward way to make sure the modal
isn't visible.

We've hit this problem twice before (am not successful this morning
finding the relevant issues):

* If the WebSocket is flapping, the event may not register. But usually
the browser will refresh if this is the case (we have a red indicator in
the upper-right to indicate if the websocket is not connected, i.e. the
views aren't "live")
* A CSS bug caused the click event to target the wrong LiveView PID (the
modal's parent I believe), which ended up crashing it because it didn't
have the "close" event handler defined. I believe the escape keydown
still closed the view though in that case.

This feels more like the first issue, given the acceptance test is
passing.

Co-authored-by: Andrew Dryga <andrew@dryga.com>
This commit is contained in:
Jamil
2023-01-23 07:31:37 -08:00
committed by GitHub
parent b5ff85c276
commit ddc8b32970
2 changed files with 4 additions and 0 deletions

View File

@@ -226,6 +226,7 @@ defmodule FzHttpWeb.Acceptance.AdminTest do
|> click(Query.css("button[phx-click=\"close\"]"))
|> assert_el(Query.link("Add Device"))
|> assert_el(Query.link("big-leg-007"))
|> assert_path(~p"/users/#{user.id}")
assert device = Repo.one(FzHttp.Devices.Device)
assert device.name == "big-leg-007"
@@ -637,6 +638,7 @@ defmodule FzHttpWeb.Acceptance.AdminTest do
|> assert_el(Query.text("API token secret:"))
|> click(Query.css("button[aria-label=\"close\"]"))
|> assert_el(Query.link("Delete"))
|> assert_path(~p"/settings/account")
accept_confirm(session, fn session ->
click(session, Query.link("Delete"))

View File

@@ -50,6 +50,7 @@ defmodule FzHttpWeb.Acceptance.UnprivilegedUserTest do
|> assert_el(Query.text("Device added!"))
|> click(Query.css("button[phx-click=\"close\"]"))
|> assert_el(Query.text("big-head-007"))
|> assert_path(~p"/user_devices")
assert device = Repo.one(FzHttp.Devices.Device)
assert device.name == "big-head-007"
@@ -82,6 +83,7 @@ defmodule FzHttpWeb.Acceptance.UnprivilegedUserTest do
|> assert_el(Query.text("Device added!"))
|> click(Query.css("button[phx-click=\"close\"]"))
|> assert_el(Query.text("big-hand-007"))
|> assert_path(~p"/user_devices")
assert device = Repo.one(FzHttp.Devices.Device)
assert device.name == "big-hand-007"