2023-09-13 15:55:29 +03:00
|
|
|
defmodule PlausibleWeb.Live.PropsSettingsTest do
|
2023-07-27 17:46:32 +03:00
|
|
|
use PlausibleWeb.ConnCase, async: true
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
import Plausible.Test.Support.HTML
|
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
describe "GET /:website/settings/properties" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "lists props for the site and renders links", %{conn: conn, site: site} do
|
|
|
|
{:ok, site} = Plausible.Props.allow(site, ["amount", "logged_in", "is_customer"])
|
|
|
|
conn = get(conn, "/#{site.domain}/settings/properties")
|
|
|
|
|
|
|
|
resp = html_response(conn, 200)
|
|
|
|
assert resp =~ "Attach Custom Properties"
|
|
|
|
|
|
|
|
assert element_exists?(
|
|
|
|
resp,
|
|
|
|
~s|a[href="https://plausible.io/docs/custom-props/introduction"]|
|
|
|
|
)
|
|
|
|
|
|
|
|
assert resp =~ "amount"
|
|
|
|
assert resp =~ "logged_in"
|
|
|
|
assert resp =~ "is_customer"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "lists props with disallow actions", %{conn: conn, site: site} do
|
|
|
|
{:ok, site} = Plausible.Props.allow(site, ["amount", "logged_in", "is_customer"])
|
|
|
|
conn = get(conn, "/#{site.domain}/settings/properties")
|
|
|
|
resp = html_response(conn, 200)
|
|
|
|
|
|
|
|
for p <- site.allowed_event_props do
|
|
|
|
assert element_exists?(
|
|
|
|
resp,
|
|
|
|
~s/button[phx-click="disallow-prop"][phx-value-prop=#{p}]#disallow-prop-#{p}/
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "if no props are allowed, a proper info is displayed", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/#{site.domain}/settings/properties")
|
|
|
|
resp = html_response(conn, 200)
|
|
|
|
assert resp =~ "No properties configured for this site"
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "if props are enabled, no info about missing props is displayed", %{
|
|
|
|
conn: conn,
|
|
|
|
site: site
|
|
|
|
} do
|
|
|
|
{:ok, site} = Plausible.Props.allow(site, ["amount", "logged_in", "is_customer"])
|
|
|
|
conn = get(conn, "/#{site.domain}/settings/properties")
|
|
|
|
resp = html_response(conn, 200)
|
|
|
|
refute resp =~ "No properties configured for this site"
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "add property button is rendered", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/#{site.domain}/settings/properties")
|
|
|
|
resp = html_response(conn, 200)
|
|
|
|
assert element_exists?(resp, ~s/button[phx-click="add-prop"]/)
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "search props input is rendered", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/#{site.domain}/settings/properties")
|
|
|
|
resp = html_response(conn, 200)
|
|
|
|
assert element_exists?(resp, ~s/input[type="text"]#filter-text/)
|
|
|
|
assert element_exists?(resp, ~s/form[phx-change="filter"]#filter-form/)
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
end
|
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
# validating input
|
|
|
|
# clicking suggestions fills out input
|
|
|
|
# adding props
|
|
|
|
# error when reached props limit
|
|
|
|
# clearserror when fixed input
|
|
|
|
# removal
|
|
|
|
# removal shows confirmation
|
|
|
|
# allow existing props: shows/hides
|
|
|
|
# after adding all suggestions no allow existing props
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
describe "PropsSettings live view" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "allows prop removal", %{conn: conn, site: site} do
|
|
|
|
{:ok, site} = Plausible.Props.allow(site, ["amount", "logged_in"])
|
|
|
|
{lv, html} = get_liveview(conn, site, with_html?: true)
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert html =~ "amount"
|
|
|
|
assert html =~ "logged_in"
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
html = lv |> element(~s/button#disallow-prop-amount/) |> render_click()
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
refute html =~ "amount"
|
|
|
|
assert html =~ "logged_in"
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
html = get(conn, "/#{site.domain}/settings/properties") |> html_response(200)
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
refute html =~ "amount"
|
|
|
|
assert html =~ "logged_in"
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "allows props filtering / search", %{conn: conn, site: site} do
|
|
|
|
{:ok, site} = Plausible.Props.allow(site, ["amount", "logged_in", "is_customer"])
|
|
|
|
{lv, html} = get_liveview(conn, site, with_html?: true)
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert html =~ to_string("amount")
|
|
|
|
assert html =~ to_string("logged_in")
|
|
|
|
assert html =~ to_string("is_customer")
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
html = type_into_search(lv, "is_customer")
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
refute html =~ to_string("amount")
|
|
|
|
refute html =~ to_string("logged_in")
|
|
|
|
assert html =~ to_string("is_customer")
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "allows resetting filter text via backspace icon", %{conn: conn, site: site} do
|
|
|
|
{:ok, site} = Plausible.Props.allow(site, ["amount", "logged_in", "is_customer"])
|
|
|
|
{lv, html} = get_liveview(conn, site, with_html?: true)
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
refute element_exists?(html, ~s/svg[phx-click="reset-filter-text"]#reset-filter/)
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
html = type_into_search(lv, to_string("is_customer"))
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert element_exists?(html, ~s/svg[phx-click="reset-filter-text"]#reset-filter/)
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
html = lv |> element(~s/svg#reset-filter/) |> render_click()
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert html =~ to_string("is_customer")
|
|
|
|
assert html =~ to_string("amount")
|
|
|
|
assert html =~ to_string("logged_in")
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "allows resetting filter text via no match link", %{conn: conn, site: site} do
|
|
|
|
lv = get_liveview(conn, site)
|
|
|
|
html = type_into_search(lv, "Definitely this is not going to render any matches")
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert html =~ "No properties found for this site. Please refine or"
|
|
|
|
assert html =~ "reset your search"
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert element_exists?(html, ~s/a[phx-click="reset-filter-text"]#reset-filter-hint/)
|
|
|
|
html = lv |> element(~s/a#reset-filter-hint/) |> render_click()
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
refute html =~ "No properties found for this site. Please refine or"
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
test "clicking Add Property button renders the form view", %{conn: conn, site: site} do
|
|
|
|
lv = get_liveview(conn, site)
|
|
|
|
html = lv |> element(~s/button[phx-click="add-prop"]/) |> render_click()
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert html =~ "Add Property for #{site.domain}"
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
assert element_exists?(
|
|
|
|
html,
|
|
|
|
~s/div#props-form form[phx-submit="allow-prop"][phx-click-away="cancel-allow-prop"]/
|
|
|
|
)
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
end
|
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
defp get_liveview(conn, site, opts \\ []) do
|
2023-07-27 17:46:32 +03:00
|
|
|
conn = assign(conn, :live_module, PlausibleWeb.Live.PropsSettings)
|
2023-09-13 15:55:29 +03:00
|
|
|
{:ok, lv, html} = live(conn, "/#{site.domain}/settings/properties")
|
2023-07-27 17:46:32 +03:00
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
if Keyword.get(opts, :with_html?) do
|
|
|
|
{lv, html}
|
|
|
|
else
|
|
|
|
lv
|
|
|
|
end
|
2023-07-27 17:46:32 +03:00
|
|
|
end
|
|
|
|
|
2023-09-13 15:55:29 +03:00
|
|
|
defp type_into_search(lv, text) do
|
2023-07-27 17:46:32 +03:00
|
|
|
lv
|
2023-09-13 15:55:29 +03:00
|
|
|
|> element("form#filter-form")
|
2023-07-27 17:46:32 +03:00
|
|
|
|> render_change(%{
|
2023-09-13 15:55:29 +03:00
|
|
|
"_target" => ["filter-text"],
|
|
|
|
"filter-text" => "#{text}"
|
2023-07-27 17:46:32 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|