analytics/test/plausible_web/controllers/api/stats_controller/suggestions_test.exs

134 lines
4.2 KiB
Elixir
Raw Normal View History

Adds manual, editable, auto-suggested filters, and negated&globbed path-based filters (#1121) * Adds manual-filters + friends commit 308192044d726e9a6f7406e333048ab3407aa260 Merge: 39287ab a299fab Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 03:40:55 2021 -0500 Merge branch 'manual-filters' into manual-filters-2 commit a299fab1fbe98ec04ea3dfbfbd175a2af5e73804 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 02:20:26 2021 -0500 Changes to split and pattern matched function for time_on_page commit 10f10c933af56a3482747f818bd580a8a1903ae2 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 01:53:18 2021 -0500 Fixes a couple of minor UX issues commit f2e5ce8eb33460cb2d1dc9ac0bd0d4ad0a20aa31 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 01:49:10 2021 -0500 Fixes time on page for globbed and negated page paths commit bb18af6526068860e4090dc91d02455e515f1238 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu Jun 10 05:24:05 2021 -0500 Close to finalized version of updated version Just needs some additional testing + potentially code cleanup commit d0b7bfe3dacb4c611e6857bed308b5954aa2cc1e Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 28 04:21:21 2021 -0500 Real Dialyzer Fix commit 296a76af34ff7e16c83e5b5bf62f0547dc30ece9 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 28 03:44:29 2021 -0500 Dialyzer fix commit 91f3b44017afb3838bbb4de8ec9f3ba4d39709bc Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:11:24 2021 -0500 Changelog commit e041f75745ab57b0d3c00d4a9ff7f8a490b27c17 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:09:52 2021 -0500 Formatting commit f689642204b02f6544dc072b95c9c22e180b9e87 Merge: e00929b 4ff25f6 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:08:47 2021 -0500 Merge branch 'master' into manual-filters commit e00929b1c51411fe4bf939266d3aeb6f67dcb2ab Merge: 83887c4 806975e Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:01:48 2021 -0500 Merge branch 'manual-filters' of github.com:Vigasaurus/plausible-analytics into manual-filters commit 83887c49ccc7fbc50ba1766bfa74c77994ef1900 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:59:32 2021 -0500 Adds tests for suggestions, formats goals suggestion query commit 1cb7732a08a50eddb81166fb796bf5731a0c5aba Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:36:31 2021 -0500 Adds goals as auto-complete capable filter commit 4ca39cc406777794bab7586116115031c6d8a82a Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:08:22 2021 -0500 95% completed auto-complete setup Still needs: - tests - goals added as filter commit 22d38c4cd83dd1d72ec435e1b8cf6fc3eb70d957 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 03:47:19 2021 -0500 80% of auto-complete filters progress Still needs - countries and screen into new format - re-style dropdown and background - drop debounce time - tests commit 806975ede9ebcbaa03ce888c41f20da866413697 Merge: 81c5e05 1a93542 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 15:28:21 2021 -0500 Merge branch 'master' into manual-filters commit 81c5e05760bf7f5d6fc05290e662ab61f9a4b73b Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 15:21:03 2021 -0500 Makes colorings on top bar elements consistent commit fa7f6c22680f5f00b89c7ea99032b409a5f8bbd2 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 14:58:25 2021 -0500 Makes requested changes, adds different version of filter button commit 7dc65b9b7a5a9678499a7c404109e710ae7da36d Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 04:29:01 2021 -0500 Changelog commit c684f1c76a2599324c19ca32de10b2f2849fd5e9 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 04:26:14 2021 -0500 Various UI Improvements - Makes edit buttons full-length & properly sized - Adds remove filter button in edit menu commit a632e7a8eea4a9897052cb08d3f7605403c227f7 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 03:11:50 2021 -0500 Adds tests for exclusions and wildcards commit eb91a7942b662d412511a4c47501a9b6d7f2d625 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 03:02:23 2021 -0500 Fixes editing UX on list view commit 6209d72aeede6aa8ce4f8e009d2ea168bb8f77a7 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 04:01:17 2021 -0500 Bugfix in realtime view, formatting commit 007d44df38dba254154b3450aacec9dd253ccd95 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 03:23:16 2021 -0500 Second pass - mostly everything user-facing is done Still needs: - Tests - Potentially negating other filters - Potentially some code cleanup commit cb7b5b9fbd83f618cf4ebbe6582a9202b4989033 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 01:49:52 2021 -0500 First pass on manual filter & path regex/negated filters Still needs: - Form structure on filter modal - Edit filter button - Filter dropdown UI improvement - Filter modal mount data collection - Tests - Potentially negating other filters * Fixes an issue between the updated React version and Flatpickr not showing up Reverting to v16 was the simplest fix without diving into the issue upstream with Flatpickr * Resolves comments on UI and code style Co-authored-by: Uku Taht <Uku.taht@gmail.com>
2021-06-21 14:42:16 +03:00
defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
use PlausibleWeb.ConnCase
import Plausible.TestUtils
describe "GET /api/stats/:domain/suggestions/:filter_name" do
setup [:create_user, :log_in, :create_site]
test "returns suggestions for pages without a query", %{conn: conn, site: site} do
conn = get(conn, "/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01")
assert json_response(conn, 200) == ["/", "/register", "/contact", "/irrelevant"]
end
test "returns suggestions for pages with a query", %{conn: conn, site: site} do
conn =
get(conn, "/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01&q=re")
assert json_response(conn, 200) == ["/register", "/irrelevant"]
end
test "returns suggestions for pages without any suggestions", %{conn: conn, site: site} do
conn =
get(
conn,
"/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01&q=/123"
)
assert json_response(conn, 200) == []
end
test "returns suggestions for goals", %{conn: conn, site: site} do
conn = get(conn, "/api/stats/#{site.domain}/suggestions/goal?period=month&date=2019-01-01")
assert json_response(conn, 200) == []
end
test "returns suggestions for sources", %{conn: conn, site: site} do
conn =
get(conn, "/api/stats/#{site.domain}/suggestions/source?period=month&date=2019-01-01")
assert json_response(conn, 200) == ["10words", "Bing"]
end
test "returns suggestions for countries", %{conn: conn, site: site} do
conn =
get(
conn,
"/api/stats/#{site.domain}/suggestions/country?period=month&date=2019-01-01&q=GBR,UKR,URY,USA"
)
assert json_response(conn, 200) == ["USA"]
end
test "returns suggestions for countries without country in search", %{conn: conn, site: site} do
conn =
get(
conn,
"/api/stats/#{site.domain}/suggestions/country?period=month&date=2019-01-01&q=GBR,UKR,URY"
)
assert json_response(conn, 200) == []
end
test "returns suggestions for screen sizes", %{conn: conn, site: site} do
conn =
get(conn, "/api/stats/#{site.domain}/suggestions/screen?period=month&date=2019-01-01")
assert json_response(conn, 200) == ["Desktop"]
end
test "returns suggestions for browsers", %{conn: conn, site: site} do
conn =
get(conn, "/api/stats/#{site.domain}/suggestions/browser?period=month&date=2019-01-01")
assert json_response(conn, 200) == ["Chrome"]
end
test "returns suggestions for browser versions", %{conn: conn, site: site} do
filters = Jason.encode!(%{browser: "Chrome"})
conn =
get(
conn,
"/api/stats/#{site.domain}/suggestions/browser_version?period=month&date=2019-01-01&filters=#{
filters
}"
)
assert json_response(conn, 200) == ["78.0"]
end
test "returns suggestions for OS", %{conn: conn, site: site} do
conn = get(conn, "/api/stats/#{site.domain}/suggestions/os?period=month&date=2019-01-01")
assert json_response(conn, 200) == ["Mac"]
end
test "returns suggestions for OS versions", %{conn: conn, site: site} do
filters = Jason.encode!(%{os: "Mac"})
conn =
get(
conn,
"/api/stats/#{site.domain}/suggestions/os_version?period=month&date=2019-01-01&filters=#{
filters
}"
)
assert json_response(conn, 200) == ["10.15"]
end
test "returns suggestions for OS versions with search", %{conn: conn, site: site} do
filters = Jason.encode!(%{os: "Mac"})
conn =
get(
conn,
"/api/stats/#{site.domain}/suggestions/os_version?period=month&date=2019-01-01&filters=#{
filters
}&q=11"
)
assert json_response(conn, 200) == []
end
test "returns suggestions for referrers", %{conn: conn, site: site} do
conn =
get(conn, "/api/stats/#{site.domain}/suggestions/referrer?period=month&date=2019-01-01")
assert json_response(conn, 200) == ["10words.com/page1"]
end
end
end