Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Bugfix: ComboBox navigation with creatable on top (#3316)
hq1b2df714bdb9f
diff --git a/lib/plausible_web/live/components/combo_box.ex b/lib/plausible_web/live/components/combo_box.exindex 304175908b..7b98a7522a 100644--- a/lib/plausible_web/live/components/combo_box.ex+++ b/lib/plausible_web/live/components/combo_box.ex@@ -165,7 +165,7 @@ defmodule PlausibleWeb.Live.Components.ComboBox do><.option:if={display_creatable_option?(assigns)}- idx={length(@suggestions)}+ idx={0}submit_value={@display_value}display_value={@display_value}target={@target}@@ -178,7 +178,7 @@ defmodule PlausibleWeb.Live.Components.ComboBox do{{submit_value, display_value}, idx} <-Enum.with_index(@suggestions,- fn {option_value, option}, idx -> {{option_value, to_string(option)}, idx} end+ fn {option_value, option}, idx -> {{option_value, to_string(option)}, idx + 1} end)}:if={@suggestions != []}@@ -230,7 +230,7 @@ defmodule PlausibleWeb.Live.Components.ComboBox do<% end %></a></li>- <li :if={@idx == @suggestions_limit - 1} class="text-xs text-gray-500 relative py-2 px-3">+ <li :if={@idx == @suggestions_limit} class="text-xs text-gray-500 relative py-2 px-3">Max results reached. Refine your search by typing in goal name.</li>"""diff --git a/test/plausible_web/live/components/combo_box_test.exs b/test/plausible_web/live/components/combo_box_test.exsindex d2d2c43b7f..1220ee50fa 100644--- a/test/plausible_web/live/components/combo_box_test.exs+++ b/test/plausible_web/live/components/combo_box_test.exs@@ -50,11 +50,11 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest doli1 = doc |> find(suggestion_li(1)) |> List.first()li2 = doc |> find(suggestion_li(2)) |> List.first()- assert text_of_attr(li1, "@mouseenter") == "setFocus(0)"- assert text_of_attr(li2, "@mouseenter") == "setFocus(1)"+ assert text_of_attr(li1, "@mouseenter") == "setFocus(1)"+ assert text_of_attr(li2, "@mouseenter") == "setFocus(2)"- assert text_of_attr(li1, "x-bind:class") =~ "focus === 0"- assert text_of_attr(li2, "x-bind:class") =~ "focus === 1"+ assert text_of_attr(li1, "x-bind:class") =~ "focus === 1"+ assert text_of_attr(li2, "x-bind:class") =~ "focus === 2"endtest "Alpine.js: component refers to window.suggestionsDropdown" do@@ -113,12 +113,12 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest dodisplay_value: "Brazilian Real")- assert text_of_element(doc, "#dropdown-test-component-option-0") == "US Dollar"- assert text_of_element(doc, "#dropdown-test-component-option-1") == "Euro"-- assert text_of_element(doc, "#dropdown-test-component-option-2") ==+ assert text_of_element(doc, "#dropdown-test-component-option-0") ==~s(Create "Brazilian Real")+ assert text_of_element(doc, "#dropdown-test-component-option-1") == "US Dollar"+ assert text_of_element(doc, "#dropdown-test-component-option-2") == "Euro"+refute text_of_element(doc, "#dropdown-test-component") =="No matches found. Try searching for something different."end@@ -166,7 +166,7 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest dotest "uses the suggestions module", %{conn: conn} do{:ok, lv, _html} = live_isolated(conn, SampleView, session: %{})doc = type_into_combo(lv, "test-component", "Echo me")- assert text_of_element(doc, "#dropdown-test-component-option-0") == "Echo me"+ assert text_of_element(doc, "#dropdown-test-component-option-1") == "Echo me"endtest "stores selected value", %{conn: conn} do@@ -175,7 +175,7 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest dodoc =lv- |> element("li#dropdown-test-component-option-0 a")+ |> element("li#dropdown-test-component-option-1 a")|> render_click()assert element_exists?(doc, "input[type=hidden][name=some_submit_name][value=20]")@@ -225,7 +225,7 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest dodoc =lv- |> element("li#dropdown-test-creatable-component-option-0 a")+ |> element("li#dropdown-test-creatable-component-option-1 a")|> render_click()assert element_exists?(doc, "input[type=hidden][name=some_submit_name][value=20]")@@ -245,7 +245,7 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest doassert lv|> type_into_combo("test-creatable-component", "Option 1")- |> text_of_element("li#dropdown-test-creatable-component-option-0 a") == ~s(Option 1)+ |> text_of_element("li#dropdown-test-creatable-component-option-1 a") == ~s(Option 1)endtest "stores new value by clicking on the dropdown custom option", %{conn: conn} do@@ -314,27 +314,27 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest doasync: true)- refute element_exists?(doc, "#dropdown-test-component-option-0")+ refute element_exists?(doc, "#dropdown-test-component-option-1")endtest "pre-fills the suggestions asynchronously", %{conn: conn} do{:ok, lv, doc} = live_isolated(conn, SampleViewAsync, session: %{})- refute element_exists?(doc, "#dropdown-test-component-option-0")+ refute element_exists?(doc, "#dropdown-test-component-option-1"):timer.sleep(1000)doc = render(lv)- assert text_of_element(doc, "#dropdown-test-component-option-0") == "One"- assert text_of_element(doc, "#dropdown-test-component-option-1") == "Two"- assert text_of_element(doc, "#dropdown-test-component-option-2") == "Three"+ assert text_of_element(doc, "#dropdown-test-component-option-1") == "One"+ assert text_of_element(doc, "#dropdown-test-component-option-2") == "Two"+ assert text_of_element(doc, "#dropdown-test-component-option-3") == "Three"endtest "uses the suggestions function asynchronously", %{conn: conn} do{:ok, lv, _html} = live_isolated(conn, SampleViewAsync, session: %{})doc = type_into_combo(lv, "test-component", "Echo me")- refute element_exists?(doc, "#dropdown-test-component-option-0")+ refute element_exists?(doc, "#dropdown-test-component-option-1"):timer.sleep(1000)doc = render(lv)- assert element_exists?(doc, "#dropdown-test-component-option-0")- assert text_of_element(doc, "#dropdown-test-component-option-0") == "Echo me"+ assert element_exists?(doc, "#dropdown-test-component-option-1")+ assert text_of_element(doc, "#dropdown-test-component-option-1") == "Echo me"endend@@ -358,7 +358,7 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest doenddefp suggestion_li(idx) do- ~s/#{@ul} li#dropdown-test-component-option-#{idx - 1}/+ ~s/#{@ul} li#dropdown-test-component-option-#{idx}/enddefp type_into_combo(lv, id, text) dodiff --git a/test/plausible_web/live/funnel_settings/form_test.exs b/test/plausible_web/live/funnel_settings/form_test.exsindex 49b399fa44..34854a2168 100644--- a/test/plausible_web/live/funnel_settings/form_test.exs+++ b/test/plausible_web/live/funnel_settings/form_test.exs@@ -12,11 +12,11 @@ defmodule PlausibleWeb.Live.FunnelSettings.FormTest dodoc = type_into_combo(lv, 1, "hello")- assert text_of_element(doc, "#dropdown-step-1-option-0") == "Hello World"+ assert text_of_element(doc, "#dropdown-step-1-option-1") == "Hello World"doc = type_into_combo(lv, 1, "plausible")- assert text_of_element(doc, "#dropdown-step-1-option-0") == "Plausible"+ assert text_of_element(doc, "#dropdown-step-1-option-1") == "Plausible"endtest "selecting an option prefills input values", %{conn: conn, site: site} do@@ -29,7 +29,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.FormTest dorefute element_exists?(doc, ~s/input[type="text"][value="Another World"]/)lv- |> element("li#dropdown-step-1-option-0 a")+ |> element("li#dropdown-step-1-option-1 a")|> render_click()assert lv@@ -50,7 +50,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.FormTest dotype_into_combo(lv, 1, "another")lv- |> element("li#dropdown-step-1-option-0 a")+ |> element("li#dropdown-step-1-option-1 a")|> render_click()doc = type_into_combo(lv, 2, "another")@@ -65,11 +65,11 @@ defmodule PlausibleWeb.Live.FunnelSettings.FormTest dodoc =lv- |> element("li#dropdown-step-1-option-0 a")+ |> element("li#dropdown-step-1-option-1 a")|> render_click()- assert element_exists?(doc, ~s/#li#dropdown-step-1-option-14/)- refute element_exists?(doc, ~s/#li#dropdown-step-1-option-15/)+ assert element_exists?(doc, ~s/#li#dropdown-step-1-option-15/)+ refute element_exists?(doc, ~s/#li#dropdown-step-1-option-16/)endtest "removing one option alters suggestions for other", %{conn: conn, site: site} do@@ -82,12 +82,12 @@ defmodule PlausibleWeb.Live.FunnelSettings.FormTest dotype_into_combo(lv, 2, "hello")lv- |> element("li#dropdown-step-2-option-0 a")+ |> element("li#dropdown-step-2-option-1 a")|> render_click()doc = type_into_combo(lv, 1, "hello")- refute text_of_element(doc, "ul#dropdown-step-1 li") =~ "Hello World"+ refute text_of_element(doc, "ul#dropdown-step-0 li") =~ "Hello World"lv |> element(~s/#remove-step-2/) |> render_click()diff --git a/test/plausible_web/live/funnel_settings_test.exs b/test/plausible_web/live/funnel_settings_test.exsindex 618261daf6..5b224c1ac6 100644--- a/test/plausible_web/live/funnel_settings_test.exs+++ b/test/plausible_web/live/funnel_settings_test.exs@@ -165,12 +165,12 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest doassert lv = find_live_child(lv, "funnels-form")lv- |> element("li#dropdown-step-1-option-0 a")+ |> element("li#dropdown-step-1-option-1 a")|> render_click()doc =lv- |> element("li#dropdown-step-2-option-0 a")+ |> element("li#dropdown-step-2-option-1 a")|> render_click()save_inactive = ~s/form button#save.cursor-not-allowed/@@ -207,11 +207,11 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest doassert lv = find_live_child(lv, "funnels-form")- lv |> element("li#dropdown-step-1-option-0 a") |> render_click()+ lv |> element("li#dropdown-step-1-option-1 a") |> render_click():timer.sleep(1001)- lv |> element("li#dropdown-step-2-option-0 a") |> render_click()+ lv |> element("li#dropdown-step-2-option-1 a") |> render_click()doc = lv |> element("#step-eval-0") |> render()assert text_of_element(doc, ~s/#step-eval-0/) =~ "Entering Visitors: 0"diff --git a/test/plausible_web/live/props_settings_test.exs b/test/plausible_web/live/props_settings_test.exsindex 4dd048734c..5324a73e5c 100644--- a/test/plausible_web/live/props_settings_test.exs+++ b/test/plausible_web/live/props_settings_test.exs@@ -35,13 +35,13 @@ defmodule PlausibleWeb.Live.PropsSettings.FormTest dotest "renders dropdown with suggestions", %{conn: conn, site: site} do{:ok, _lv, doc} = get_liveview(conn, site)- assert text_of_element(doc, ~s/ul#dropdown-prop_input li#dropdown-prop_input-option-0/) ==+ assert text_of_element(doc, ~s/ul#dropdown-prop_input li#dropdown-prop_input-option-1/) =="amount"- assert text_of_element(doc, ~s/ul#dropdown-prop_input li#dropdown-prop_input-option-1/) ==+ assert text_of_element(doc, ~s/ul#dropdown-prop_input li#dropdown-prop_input-option-2/) =="logged_in"- assert text_of_element(doc, ~s/ul#dropdown-prop_input li#dropdown-prop_input-option-2/) ==+ assert text_of_element(doc, ~s/ul#dropdown-prop_input li#dropdown-prop_input-option-3/) =="is_customer"end@@ -55,7 +55,7 @@ defmodule PlausibleWeb.Live.PropsSettings.FormTest dodoc =lv- |> element(~s/ul#dropdown-prop_input li#dropdown-prop_input-option-0 a/)+ |> element(~s/ul#dropdown-prop_input li#dropdown-prop_input-option-1 a/)|> render_click()assert element_exists?(doc, ~s/input[type="hidden"][value="amount"]/)@@ -64,7 +64,7 @@ defmodule PlausibleWeb.Live.PropsSettings.FormTest dotest "saving from suggestion adds to the list", %{conn: conn, site: site} do{:ok, lv, _doc} = get_liveview(conn, site)- doc = select_and_submit(lv, 0)+ doc = select_and_submit(lv, 1)assert text_of_element(doc, ~s/ul#allowed-props li#prop-0 span/) == "amount"refute doc =~ "No properties configured for this site yet"@@ -169,9 +169,9 @@ defmodule PlausibleWeb.Live.PropsSettings.FormTest do} do{:ok, lv, _doc} = get_liveview(conn, site)- _doc = select_and_submit(lv, 0)- _doc = select_and_submit(lv, 0)- doc = select_and_submit(lv, 0)+ _doc = select_and_submit(lv, 1)+ _doc = select_and_submit(lv, 1)+ doc = select_and_submit(lv, 1)refute element_exists?(doc, ~s/button[phx-click="allow-existing-props"]/)end