From ddc8b32970b6598259bab3af9fdb54e1220699f3 Mon Sep 17 00:00:00 2001 From: Jamil Date: Mon, 23 Jan 2023 07:31:37 -0800 Subject: [PATCH] Add tests to ensure path changes when modal is dismissed (#1356) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- apps/fz_http/test/fz_http_web/acceptance/admin_test.exs | 2 ++ .../test/fz_http_web/acceptance/unprivileged_user_test.exs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/apps/fz_http/test/fz_http_web/acceptance/admin_test.exs b/apps/fz_http/test/fz_http_web/acceptance/admin_test.exs index dbef633bd..5532fc0ca 100644 --- a/apps/fz_http/test/fz_http_web/acceptance/admin_test.exs +++ b/apps/fz_http/test/fz_http_web/acceptance/admin_test.exs @@ -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")) diff --git a/apps/fz_http/test/fz_http_web/acceptance/unprivileged_user_test.exs b/apps/fz_http/test/fz_http_web/acceptance/unprivileged_user_test.exs index 42278ce40..9d827b40d 100644 --- a/apps/fz_http/test/fz_http_web/acceptance/unprivileged_user_test.exs +++ b/apps/fz_http/test/fz_http_web/acceptance/unprivileged_user_test.exs @@ -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"