Delete test/plausible_web/live/goal_settings/property_pair_input_test.exs with huggingface_hub
Browse files
test/plausible_web/live/goal_settings/property_pair_input_test.exs
DELETED
|
@@ -1,192 +0,0 @@
|
|
| 1 |
-
defmodule PlausibleWeb.Live.GoalSettings.PropertyPairInputTest do
|
| 2 |
-
use PlausibleWeb.ConnCase, async: true
|
| 3 |
-
import Phoenix.LiveViewTest
|
| 4 |
-
|
| 5 |
-
alias PlausibleWeb.Live.GoalSettings.PropertyPairInput
|
| 6 |
-
|
| 7 |
-
describe "static rendering" do
|
| 8 |
-
setup [:create_user, :create_site]
|
| 9 |
-
|
| 10 |
-
test "renders both property name and value comboboxes", %{site: site} do
|
| 11 |
-
doc = render_pair_component(site, "test-pair")
|
| 12 |
-
|
| 13 |
-
assert element_exists?(
|
| 14 |
-
doc,
|
| 15 |
-
~s/input#test-pair_key[name="display-test-pair_key"][phx-change="search"]/
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
assert element_exists?(
|
| 19 |
-
doc,
|
| 20 |
-
~s/input#test-pair_value[name="display-test-pair_value"][phx-change="search"]/
|
| 21 |
-
)
|
| 22 |
-
end
|
| 23 |
-
|
| 24 |
-
test "property value combobox shows 'Select property first' when no property selected", %{
|
| 25 |
-
site: site
|
| 26 |
-
} do
|
| 27 |
-
doc = render_pair_component(site, "test-pair")
|
| 28 |
-
|
| 29 |
-
assert element_exists?(
|
| 30 |
-
doc,
|
| 31 |
-
~s/input#test-pair_value[placeholder="Select property first"]/
|
| 32 |
-
)
|
| 33 |
-
end
|
| 34 |
-
|
| 35 |
-
test "property value combobox shows 'Select value' when property is selected", %{site: site} do
|
| 36 |
-
doc = render_pair_component(site, "test-pair", selected_property: "product")
|
| 37 |
-
|
| 38 |
-
assert element_exists?(
|
| 39 |
-
doc,
|
| 40 |
-
~s/input#test-pair_value[placeholder="Select value"]/
|
| 41 |
-
)
|
| 42 |
-
end
|
| 43 |
-
|
| 44 |
-
test "both comboboxes have correct submit names", %{site: site} do
|
| 45 |
-
doc = render_pair_component(site, "test-pair")
|
| 46 |
-
|
| 47 |
-
assert element_exists?(
|
| 48 |
-
doc,
|
| 49 |
-
~s/input[type="hidden"][name="goal[custom_props][keys][]"]/
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
assert element_exists?(
|
| 53 |
-
doc,
|
| 54 |
-
~s/input[type="hidden"][name="goal[custom_props][values][]"]/
|
| 55 |
-
)
|
| 56 |
-
end
|
| 57 |
-
|
| 58 |
-
test "renders wrapper div with correct ID", %{site: site} do
|
| 59 |
-
doc = render_pair_component(site, "my-custom-id")
|
| 60 |
-
|
| 61 |
-
assert element_exists?(doc, ~s/div#my-custom-id/)
|
| 62 |
-
end
|
| 63 |
-
|
| 64 |
-
test "both comboboxes are marked as creatable", %{site: site} do
|
| 65 |
-
doc = render_pair_component(site, "test-pair")
|
| 66 |
-
|
| 67 |
-
assert text_of_element(doc, "#dropdown-test-pair_key") =~ "Create an item by typing."
|
| 68 |
-
assert text_of_element(doc, "#dropdown-test-pair_value") =~ "Create an item by typing."
|
| 69 |
-
end
|
| 70 |
-
|
| 71 |
-
test "pre-populates property key when initial_prop_key is provided", %{site: site} do
|
| 72 |
-
doc = render_pair_component(site, "test-pair", initial_prop_key: "product")
|
| 73 |
-
|
| 74 |
-
assert element_exists?(
|
| 75 |
-
doc,
|
| 76 |
-
~s/input#test-pair_key[name="display-test-pair_key"][value="product"]/
|
| 77 |
-
)
|
| 78 |
-
end
|
| 79 |
-
|
| 80 |
-
test "pre-populates property value when initial_prop_value is provided", %{site: site} do
|
| 81 |
-
doc = render_pair_component(site, "test-pair", initial_prop_value: "Shirt")
|
| 82 |
-
|
| 83 |
-
assert element_exists?(
|
| 84 |
-
doc,
|
| 85 |
-
~s/input#test-pair_value[name="display-test-pair_value"][value="Shirt"]/
|
| 86 |
-
)
|
| 87 |
-
end
|
| 88 |
-
|
| 89 |
-
test "pre-populates both property key and value when both are provided", %{site: site} do
|
| 90 |
-
doc =
|
| 91 |
-
render_pair_component(site, "test-pair",
|
| 92 |
-
initial_prop_key: "product",
|
| 93 |
-
initial_prop_value: "Shirt"
|
| 94 |
-
)
|
| 95 |
-
|
| 96 |
-
assert element_exists?(
|
| 97 |
-
doc,
|
| 98 |
-
~s/input#test-pair_key[name="display-test-pair_key"][value="product"]/
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
assert element_exists?(
|
| 102 |
-
doc,
|
| 103 |
-
~s/input#test-pair_value[name="display-test-pair_value"][value="Shirt"]/
|
| 104 |
-
)
|
| 105 |
-
end
|
| 106 |
-
|
| 107 |
-
test "value combobox shows 'Select value' when property is pre-populated", %{site: site} do
|
| 108 |
-
doc = render_pair_component(site, "test-pair", initial_prop_key: "product")
|
| 109 |
-
|
| 110 |
-
assert element_exists?(
|
| 111 |
-
doc,
|
| 112 |
-
~s/input#test-pair_value[placeholder="Select value"]/
|
| 113 |
-
)
|
| 114 |
-
end
|
| 115 |
-
end
|
| 116 |
-
|
| 117 |
-
describe "integration with live view" do
|
| 118 |
-
setup [:create_user, :create_site]
|
| 119 |
-
|
| 120 |
-
defmodule TestLiveView do
|
| 121 |
-
use Phoenix.LiveView
|
| 122 |
-
|
| 123 |
-
def render(assigns) do
|
| 124 |
-
~H"""
|
| 125 |
-
<div>
|
| 126 |
-
<.live_component
|
| 127 |
-
id="test-property-pair"
|
| 128 |
-
module={PlausibleWeb.Live.GoalSettings.PropertyPairInput}
|
| 129 |
-
site={@site}
|
| 130 |
-
/>
|
| 131 |
-
</div>
|
| 132 |
-
"""
|
| 133 |
-
end
|
| 134 |
-
|
| 135 |
-
def mount(_params, %{"site" => site}, socket) do
|
| 136 |
-
{:ok, assign(socket, site: site)}
|
| 137 |
-
end
|
| 138 |
-
end
|
| 139 |
-
|
| 140 |
-
test "selecting property value based on name selection", %{conn: conn, site: site} do
|
| 141 |
-
populate_stats(site, [
|
| 142 |
-
build(:event,
|
| 143 |
-
name: "Purchase",
|
| 144 |
-
"meta.key": ["product"],
|
| 145 |
-
"meta.value": ["Shirt"]
|
| 146 |
-
)
|
| 147 |
-
])
|
| 148 |
-
|
| 149 |
-
{:ok, lv, html} = live_isolated(conn, TestLiveView, session: %{"site" => site})
|
| 150 |
-
|
| 151 |
-
assert html =~ "Select property first"
|
| 152 |
-
|
| 153 |
-
html = type_into_combo(lv, "test-property-pair_key", "zzz")
|
| 154 |
-
refute element_exists?(html, "li#dropdown-test-property-pair_key-option-1 a")
|
| 155 |
-
|
| 156 |
-
type_into_combo(lv, "test-property-pair_key", "duct")
|
| 157 |
-
|
| 158 |
-
lv
|
| 159 |
-
|> element("li#dropdown-test-property-pair_key-option-1 a")
|
| 160 |
-
|> render_click()
|
| 161 |
-
|
| 162 |
-
html = render(lv)
|
| 163 |
-
|
| 164 |
-
refute html =~ "Select property first"
|
| 165 |
-
assert html =~ "Select value"
|
| 166 |
-
|
| 167 |
-
html = type_into_combo(lv, "test-property-pair_value", "zzz")
|
| 168 |
-
refute html =~ "Shirt"
|
| 169 |
-
|
| 170 |
-
html = type_into_combo(lv, "test-property-pair_value", "irt")
|
| 171 |
-
assert html =~ "Shirt"
|
| 172 |
-
|
| 173 |
-
lv
|
| 174 |
-
|> element("li#dropdown-test-property-pair_value-option-1 a")
|
| 175 |
-
|> render_click()
|
| 176 |
-
end
|
| 177 |
-
end
|
| 178 |
-
|
| 179 |
-
defp render_pair_component(site, id, extra_opts \\ []) do
|
| 180 |
-
opts = Keyword.merge([id: id, site: site], extra_opts)
|
| 181 |
-
render_component(PropertyPairInput, opts)
|
| 182 |
-
end
|
| 183 |
-
|
| 184 |
-
defp type_into_combo(lv, id, text) do
|
| 185 |
-
lv
|
| 186 |
-
|> element("input##{id}")
|
| 187 |
-
|> render_change(%{
|
| 188 |
-
"_target" => ["display-#{id}"],
|
| 189 |
-
"display-#{id}" => "#{text}"
|
| 190 |
-
})
|
| 191 |
-
end
|
| 192 |
-
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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