mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Bugfix: funnel deletion (#3090)
Somewhere along the way of rebasing the feature,
the integration tests for deletion were lost.
j/k they were never written 🤡
This commit is contained in:
parent
eb397a6c25
commit
ff11b3f26d
@ -80,11 +80,14 @@ defmodule PlausibleWeb.Live.FunnelSettings do
|
||||
end
|
||||
|
||||
def handle_event("delete-funnel", %{"funnel-id" => id}, socket) do
|
||||
site =
|
||||
Sites.get_for_user!(socket.assigns.current_user_id, socket.assigns.domain, [:owner, :admin])
|
||||
|
||||
id = String.to_integer(id)
|
||||
:ok = Funnels.delete(socket.assigns.site, id)
|
||||
:ok = Funnels.delete(site, id)
|
||||
socket = put_flash(socket, :success, "Funnel deleted successfully")
|
||||
Process.send_after(self(), :clear_flash, 5000)
|
||||
{:noreply, assign(socket, funnels: Funnels.list(socket.assigns.site))}
|
||||
{:noreply, assign(socket, funnels: Enum.reject(socket.assigns.funnels, &(&1.id == id)))}
|
||||
end
|
||||
|
||||
def handle_info({:funnel_saved, funnel}, socket) do
|
||||
|
@ -25,6 +25,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.List do
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
id={"delete-funnel-#{funnel.id}"}
|
||||
phx-click="delete-funnel"
|
||||
phx-value-funnel-id={funnel.id}
|
||||
class="text-sm text-red-600"
|
||||
|
@ -7,7 +7,7 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest do
|
||||
setup [:create_user, :log_in, :create_site]
|
||||
|
||||
test "lists funnels for the site and renders help link", %{conn: conn, site: site} do
|
||||
:ok = setup_funnels(site)
|
||||
{:ok, _} = setup_funnels(site)
|
||||
conn = get(conn, "/#{site.domain}/settings/funnels")
|
||||
|
||||
resp = html_response(conn, 200)
|
||||
@ -17,8 +17,25 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest do
|
||||
assert element_exists?(resp, "a[href=\"https://plausible.io/docs/funnel-analysis\"]")
|
||||
end
|
||||
|
||||
test "lists funnels with delete actions", %{conn: conn, site: site} do
|
||||
{:ok, [f1_id, f2_id]} = setup_funnels(site)
|
||||
conn = get(conn, "/#{site.domain}/settings/funnels")
|
||||
|
||||
resp = html_response(conn, 200)
|
||||
|
||||
assert element_exists?(
|
||||
resp,
|
||||
~s/button[phx-click="delete-funnel"][phx-value-funnel-id=#{f1_id}]#delete-funnel-#{f1_id}/
|
||||
)
|
||||
|
||||
assert element_exists?(
|
||||
resp,
|
||||
~s/button[phx-click="delete-funnel"][phx-value-funnel-id=#{f2_id}]#delete-funnel-#{f2_id}/
|
||||
)
|
||||
end
|
||||
|
||||
test "if goals are present, Add Funnel button is rendered", %{conn: conn, site: site} do
|
||||
:ok = setup_funnels(site)
|
||||
{:ok, _} = setup_funnels(site)
|
||||
conn = get(conn, "/#{site.domain}/settings/funnels")
|
||||
resp = conn |> html_response(200)
|
||||
assert element_exists?(resp, ~S/button[phx-click="add-funnel"]/)
|
||||
@ -42,6 +59,25 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest do
|
||||
describe "FunnelSettings component" do
|
||||
setup [:create_user, :log_in, :create_site]
|
||||
|
||||
test "allows to delete funnels", %{conn: conn, site: site} do
|
||||
{:ok, [f1_id, _f2_id]} = setup_funnels(site)
|
||||
|
||||
{lv, html} = get_liveview(conn, site, with_html?: true)
|
||||
|
||||
assert html =~ "From blog to signup"
|
||||
assert html =~ "From signup to blog"
|
||||
|
||||
html = lv |> element(~s/button#delete-funnel-#{f1_id}/) |> render_click()
|
||||
|
||||
refute html =~ "From blog to signup"
|
||||
assert html =~ "From signup to blog"
|
||||
|
||||
html = get(conn, "/#{site.domain}/settings/funnels") |> html_response(200)
|
||||
|
||||
refute html =~ "From blog to signup"
|
||||
assert html =~ "From signup to blog"
|
||||
end
|
||||
|
||||
test "renders the funnel form on clicking 'Add Funnel' button", %{conn: conn, site: site} do
|
||||
setup_goals(site)
|
||||
lv = get_liveview(conn, site)
|
||||
@ -181,21 +217,21 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest do
|
||||
defp setup_funnels(site) do
|
||||
{:ok, [g1, g2]} = setup_goals(site)
|
||||
|
||||
{:ok, _} =
|
||||
{:ok, f1} =
|
||||
Plausible.Funnels.create(
|
||||
site,
|
||||
"From blog to signup",
|
||||
[%{"goal_id" => g1.id}, %{"goal_id" => g2.id}]
|
||||
)
|
||||
|
||||
{:ok, _} =
|
||||
{:ok, f2} =
|
||||
Plausible.Funnels.create(
|
||||
site,
|
||||
"From signup to blog",
|
||||
[%{"goal_id" => g2.id}, %{"goal_id" => g1.id}]
|
||||
)
|
||||
|
||||
:ok
|
||||
{:ok, [f1.id, f2.id]}
|
||||
end
|
||||
|
||||
defp setup_goals(site) do
|
||||
@ -204,9 +240,14 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest do
|
||||
{:ok, [g1, g2]}
|
||||
end
|
||||
|
||||
defp get_liveview(conn, site) do
|
||||
defp get_liveview(conn, site, opts \\ []) do
|
||||
conn = assign(conn, :live_module, PlausibleWeb.Live.FunnelSettings)
|
||||
{:ok, lv, _html} = live(conn, "/#{site.domain}/settings/funnels")
|
||||
lv
|
||||
{:ok, lv, html} = live(conn, "/#{site.domain}/settings/funnels")
|
||||
|
||||
if Keyword.get(opts, :with_html?) do
|
||||
{lv, html}
|
||||
else
|
||||
lv
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user