analytics/test/plausible_web/live/goal_settings_test.exs

179 lines
6.0 KiB
Elixir
Raw Normal View History

Improve goal settings UX (#3293) * Add Heroicons dependency * Add name_of/1 html helper Currently with Floki there's no way to query for `[name=foo[some]]` selector * Update changelog * Make goal deletion possible with only goal id * Remove stale goal controllers * Improve ComboBox component - make sure the list options are always of the parent input width - allow passing a suggestion function instead of a module * Stale fixup * Update routes * Use the new goals route in funnel settings * Use a function in the funnel combo * Use function in the props combo * Remove old goals form * Implement new goal settings * Update moduledoc * Fix revenue switch in dark mode * Connect live socket on goal settings page * Fixup * Use Heroicons.trash icon * Tweak goals search input * Remove unused alias * Fix search/button alignment * Fix backspace icon alignment * Delegate :superadmin check to get_for_user/3 I'll do props settings separately, it's work in progress in a branch on top of this one already. cc @ukutaht * Rename socket assigns * Fixup to 5c9f58e * Fixup * Render ComboBox suggestions asynchronously This commit: - prevents redundant work by checking the socket connection - allows passing no options to the ComboBox component, so that when combined with the `async` option, the options are asynchronously initialized post-render - allows updating the suggestions asynchronously with the `async` option set to `true` - helpful in case of DB queries used for suggestions * Update tests * Throttle comboboxes * Update tests * Dim the search input * Use debounce=200 in ComboBox component * Move creatable option to the top * Ensure there's always a leading slash for goals * Test pageview goals with leading / missing * Make the modal scrollable on small viewports
2023-09-04 14:44:22 +03:00
defmodule PlausibleWeb.Live.GoalSettingsTest do
use PlausibleWeb.ConnCase, async: true
import Phoenix.LiveViewTest
import Plausible.Test.Support.HTML
describe "GET /:website/settings/goals" do
setup [:create_user, :log_in, :create_site]
@tag :full_build_only
Improve goal settings UX (#3293) * Add Heroicons dependency * Add name_of/1 html helper Currently with Floki there's no way to query for `[name=foo[some]]` selector * Update changelog * Make goal deletion possible with only goal id * Remove stale goal controllers * Improve ComboBox component - make sure the list options are always of the parent input width - allow passing a suggestion function instead of a module * Stale fixup * Update routes * Use the new goals route in funnel settings * Use a function in the funnel combo * Use function in the props combo * Remove old goals form * Implement new goal settings * Update moduledoc * Fix revenue switch in dark mode * Connect live socket on goal settings page * Fixup * Use Heroicons.trash icon * Tweak goals search input * Remove unused alias * Fix search/button alignment * Fix backspace icon alignment * Delegate :superadmin check to get_for_user/3 I'll do props settings separately, it's work in progress in a branch on top of this one already. cc @ukutaht * Rename socket assigns * Fixup to 5c9f58e * Fixup * Render ComboBox suggestions asynchronously This commit: - prevents redundant work by checking the socket connection - allows passing no options to the ComboBox component, so that when combined with the `async` option, the options are asynchronously initialized post-render - allows updating the suggestions asynchronously with the `async` option set to `true` - helpful in case of DB queries used for suggestions * Update tests * Throttle comboboxes * Update tests * Dim the search input * Use debounce=200 in ComboBox component * Move creatable option to the top * Ensure there's always a leading slash for goals * Test pageview goals with leading / missing * Make the modal scrollable on small viewports
2023-09-04 14:44:22 +03:00
test "lists goals for the site and renders links", %{conn: conn, site: site} do
{:ok, [g1, g2, g3]} = setup_goals(site)
conn = get(conn, "/#{site.domain}/settings/goals")
resp = html_response(conn, 200)
assert resp =~ "Define actions that you want your users to take"
assert resp =~ "compose Goals into Funnels"
assert resp =~ "/#{URI.encode_www_form(site.domain)}/settings/funnels"
Improve goal settings UX (#3293) * Add Heroicons dependency * Add name_of/1 html helper Currently with Floki there's no way to query for `[name=foo[some]]` selector * Update changelog * Make goal deletion possible with only goal id * Remove stale goal controllers * Improve ComboBox component - make sure the list options are always of the parent input width - allow passing a suggestion function instead of a module * Stale fixup * Update routes * Use the new goals route in funnel settings * Use a function in the funnel combo * Use function in the props combo * Remove old goals form * Implement new goal settings * Update moduledoc * Fix revenue switch in dark mode * Connect live socket on goal settings page * Fixup * Use Heroicons.trash icon * Tweak goals search input * Remove unused alias * Fix search/button alignment * Fix backspace icon alignment * Delegate :superadmin check to get_for_user/3 I'll do props settings separately, it's work in progress in a branch on top of this one already. cc @ukutaht * Rename socket assigns * Fixup to 5c9f58e * Fixup * Render ComboBox suggestions asynchronously This commit: - prevents redundant work by checking the socket connection - allows passing no options to the ComboBox component, so that when combined with the `async` option, the options are asynchronously initialized post-render - allows updating the suggestions asynchronously with the `async` option set to `true` - helpful in case of DB queries used for suggestions * Update tests * Throttle comboboxes * Update tests * Dim the search input * Use debounce=200 in ComboBox component * Move creatable option to the top * Ensure there's always a leading slash for goals * Test pageview goals with leading / missing * Make the modal scrollable on small viewports
2023-09-04 14:44:22 +03:00
assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)
assert resp =~ to_string(g1)
assert resp =~ "Pageview"
assert resp =~ to_string(g2)
assert resp =~ "Custom Event"
assert resp =~ to_string(g3)
Plugins API: 2nd pass with Goals resource + SharedLinks schema changes (#3396) * Remove "Context" namespace level * Change Goal string representation * Alias Schemas in Plugin API Test Case template * Update schema & tests for SharedLink resource * Update Goals interface - make it possible to create revenue goals - extract "for site" query to a standalone function * Fixup typespecs * Alias Errors module in OpenAPI controllers * Add missing goals test * Implement Goals Plugins API resource * Add extra test to confirm changeset error propagation * Mute credo * Fix typos * Handle changeset traversal in `Errors` * Use upserts in `Goals.find_or_create` * Extract touch_site! to Site.Cache, address credo, improve code docs * Apply formatting * Remove unused inner join * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update test/plausible_web/plugins/api/controllers/goals_test.exs Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com> * Update error message on revenue goal currency clash * Remove unused code --------- Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2023-10-05 12:54:18 +03:00
assert resp =~ "Revenue Goal"
Improve goal settings UX (#3293) * Add Heroicons dependency * Add name_of/1 html helper Currently with Floki there's no way to query for `[name=foo[some]]` selector * Update changelog * Make goal deletion possible with only goal id * Remove stale goal controllers * Improve ComboBox component - make sure the list options are always of the parent input width - allow passing a suggestion function instead of a module * Stale fixup * Update routes * Use the new goals route in funnel settings * Use a function in the funnel combo * Use function in the props combo * Remove old goals form * Implement new goal settings * Update moduledoc * Fix revenue switch in dark mode * Connect live socket on goal settings page * Fixup * Use Heroicons.trash icon * Tweak goals search input * Remove unused alias * Fix search/button alignment * Fix backspace icon alignment * Delegate :superadmin check to get_for_user/3 I'll do props settings separately, it's work in progress in a branch on top of this one already. cc @ukutaht * Rename socket assigns * Fixup to 5c9f58e * Fixup * Render ComboBox suggestions asynchronously This commit: - prevents redundant work by checking the socket connection - allows passing no options to the ComboBox component, so that when combined with the `async` option, the options are asynchronously initialized post-render - allows updating the suggestions asynchronously with the `async` option set to `true` - helpful in case of DB queries used for suggestions * Update tests * Throttle comboboxes * Update tests * Dim the search input * Use debounce=200 in ComboBox component * Move creatable option to the top * Ensure there's always a leading slash for goals * Test pageview goals with leading / missing * Make the modal scrollable on small viewports
2023-09-04 14:44:22 +03:00
end
test "lists goals with delete actions", %{conn: conn, site: site} do
{:ok, goals} = setup_goals(site)
conn = get(conn, "/#{site.domain}/settings/goals")
resp = html_response(conn, 200)
for g <- goals do
assert element_exists?(
resp,
~s/button[phx-click="delete-goal"][phx-value-goal-id=#{g.id}]#delete-goal-#{g.id}/
)
end
end
test "if no goals are present, a proper info is displayed", %{conn: conn, site: site} do
conn = get(conn, "/#{site.domain}/settings/goals")
resp = html_response(conn, 200)
assert resp =~ "No goals configured for this site"
end
test "if goals are present, no info about missing goals is displayed", %{
conn: conn,
site: site
} do
{:ok, _goals} = setup_goals(site)
conn = get(conn, "/#{site.domain}/settings/goals")
resp = html_response(conn, 200)
refute resp =~ "No goals configured for this site"
end
test "add goal button is rendered", %{conn: conn, site: site} do
conn = get(conn, "/#{site.domain}/settings/goals")
resp = html_response(conn, 200)
assert element_exists?(resp, ~s/button[phx-click="add-goal"]/)
end
test "search goals input is rendered", %{conn: conn, site: site} do
conn = get(conn, "/#{site.domain}/settings/goals")
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
end
describe "GoalSettings live view" do
setup [:create_user, :log_in, :create_site]
test "allows goal deletion", %{conn: conn, site: site} do
{:ok, [g1, g2 | _]} = setup_goals(site)
{lv, html} = get_liveview(conn, site, with_html?: true)
assert html =~ to_string(g1)
assert html =~ to_string(g2)
html = lv |> element(~s/button#delete-goal-#{g1.id}/) |> render_click()
refute html =~ to_string(g1)
assert html =~ to_string(g2)
html = get(conn, "/#{site.domain}/settings/goals") |> html_response(200)
refute html =~ to_string(g1)
assert html =~ to_string(g2)
end
test "allows list filtering / search", %{conn: conn, site: site} do
{:ok, [g1, g2, g3]} = setup_goals(site)
{lv, html} = get_liveview(conn, site, with_html?: true)
assert html =~ to_string(g1)
assert html =~ to_string(g2)
assert html =~ to_string(g3)
html = type_into_search(lv, to_string(g3))
refute html =~ to_string(g1)
refute html =~ to_string(g2)
assert html =~ to_string(g3)
end
test "allows resetting filter text via backspace icon", %{conn: conn, site: site} do
{:ok, [g1, g2, g3]} = setup_goals(site)
{lv, html} = get_liveview(conn, site, with_html?: true)
refute element_exists?(html, ~s/svg[phx-click="reset-filter-text"]#reset-filter/)
html = type_into_search(lv, to_string(g3))
assert element_exists?(html, ~s/svg[phx-click="reset-filter-text"]#reset-filter/)
html = lv |> element(~s/svg#reset-filter/) |> render_click()
assert html =~ to_string(g1)
assert html =~ to_string(g2)
assert html =~ to_string(g3)
end
test "allows resetting filter text via no match link", %{conn: conn, site: site} do
{:ok, _goals} = setup_goals(site)
lv = get_liveview(conn, site)
html = type_into_search(lv, "Definitely this is not going to render any matches")
assert html =~ "No goals found for this site. Please refine or"
assert html =~ "reset your search"
assert element_exists?(html, ~s/a[phx-click="reset-filter-text"]#reset-filter-hint/)
html = lv |> element(~s/a#reset-filter-hint/) |> render_click()
refute html =~ "No goals found for this site. Please refine or"
end
test "clicking Add Goal button renders the form view", %{conn: conn, site: site} do
{:ok, _goals} = setup_goals(site)
lv = get_liveview(conn, site)
html = lv |> element(~s/button[phx-click="add-goal"]/) |> render_click()
assert html =~ "Add Goal for #{site.domain}"
Improve goal settings UX (#3293) * Add Heroicons dependency * Add name_of/1 html helper Currently with Floki there's no way to query for `[name=foo[some]]` selector * Update changelog * Make goal deletion possible with only goal id * Remove stale goal controllers * Improve ComboBox component - make sure the list options are always of the parent input width - allow passing a suggestion function instead of a module * Stale fixup * Update routes * Use the new goals route in funnel settings * Use a function in the funnel combo * Use function in the props combo * Remove old goals form * Implement new goal settings * Update moduledoc * Fix revenue switch in dark mode * Connect live socket on goal settings page * Fixup * Use Heroicons.trash icon * Tweak goals search input * Remove unused alias * Fix search/button alignment * Fix backspace icon alignment * Delegate :superadmin check to get_for_user/3 I'll do props settings separately, it's work in progress in a branch on top of this one already. cc @ukutaht * Rename socket assigns * Fixup to 5c9f58e * Fixup * Render ComboBox suggestions asynchronously This commit: - prevents redundant work by checking the socket connection - allows passing no options to the ComboBox component, so that when combined with the `async` option, the options are asynchronously initialized post-render - allows updating the suggestions asynchronously with the `async` option set to `true` - helpful in case of DB queries used for suggestions * Update tests * Throttle comboboxes * Update tests * Dim the search input * Use debounce=200 in ComboBox component * Move creatable option to the top * Ensure there's always a leading slash for goals * Test pageview goals with leading / missing * Make the modal scrollable on small viewports
2023-09-04 14:44:22 +03:00
assert element_exists?(
html,
~s/div#goals-form form[phx-submit="save-goal"][phx-click-away="cancel-add-goal"]/
)
end
end
defp setup_goals(site) do
{:ok, g1} = Plausible.Goals.create(site, %{"page_path" => "/go/to/blog/**"})
{:ok, g2} = Plausible.Goals.create(site, %{"event_name" => "Signup"})
{:ok, g3} = Plausible.Goals.create(site, %{"event_name" => "Purchase", "currency" => "EUR"})
{:ok, [g1, g2, g3]}
end
defp get_liveview(conn, site, opts \\ []) do
conn = assign(conn, :live_module, PlausibleWeb.Live.GoalSettings)
{:ok, lv, html} = live(conn, "/#{site.domain}/settings/goals")
if Keyword.get(opts, :with_html?) do
{lv, html}
else
lv
end
end
defp type_into_search(lv, text) do
lv
|> element("form#filter-form")
|> render_change(%{
"_target" => ["filter-text"],
"filter-text" => "#{text}"
})
end
end