Delete test/plausible_web/live/shields/countries_test.exs with huggingface_hub
Browse files
test/plausible_web/live/shields/countries_test.exs
DELETED
|
@@ -1,159 +0,0 @@
|
|
| 1 |
-
defmodule PlausibleWeb.Live.Shields.CountriesTest do
|
| 2 |
-
use PlausibleWeb.ConnCase, async: true
|
| 3 |
-
|
| 4 |
-
import Phoenix.LiveViewTest
|
| 5 |
-
|
| 6 |
-
alias Plausible.Shields
|
| 7 |
-
|
| 8 |
-
setup [:create_user, :create_site, :log_in]
|
| 9 |
-
|
| 10 |
-
describe "Country Rules - static" do
|
| 11 |
-
test "renders country rules page with empty list", %{conn: conn, site: site} do
|
| 12 |
-
conn = get(conn, "/#{site.domain}/settings/shields/countries")
|
| 13 |
-
resp = html_response(conn, 200)
|
| 14 |
-
|
| 15 |
-
assert resp =~ "Block a country"
|
| 16 |
-
assert resp =~ "Country block list"
|
| 17 |
-
end
|
| 18 |
-
|
| 19 |
-
test "lists country rules with remove actions", %{conn: conn, site: site} do
|
| 20 |
-
{:ok, r1} =
|
| 21 |
-
Shields.add_country_rule(site, %{"country_code" => "PL"})
|
| 22 |
-
|
| 23 |
-
{:ok, r2} =
|
| 24 |
-
Shields.add_country_rule(site, %{"country_code" => "EE"})
|
| 25 |
-
|
| 26 |
-
conn = get(conn, "/#{site.domain}/settings/shields/countries")
|
| 27 |
-
resp = html_response(conn, 200)
|
| 28 |
-
|
| 29 |
-
assert resp =~ "Poland"
|
| 30 |
-
assert resp =~ "Estonia"
|
| 31 |
-
|
| 32 |
-
assert remove_button_1 = find(resp, "#remove-country-rule-#{r1.id}")
|
| 33 |
-
assert remove_button_2 = find(resp, "#remove-country-rule-#{r2.id}")
|
| 34 |
-
|
| 35 |
-
assert text_of_attr(remove_button_1, "phx-click") == "remove-country-rule"
|
| 36 |
-
assert text_of_attr(remove_button_1, "phx-value-rule-id") == r1.id
|
| 37 |
-
assert text_of_attr(remove_button_2, "phx-click") == "remove-country-rule"
|
| 38 |
-
assert text_of_attr(remove_button_2, "phx-value-rule-id") == r2.id
|
| 39 |
-
end
|
| 40 |
-
|
| 41 |
-
test "lists Unknown country rule", %{conn: conn, site: site} do
|
| 42 |
-
{:ok, rule} =
|
| 43 |
-
Shields.add_country_rule(site, %{"country_code" => "ZZ"})
|
| 44 |
-
|
| 45 |
-
conn = get(conn, "/#{site.domain}/settings/shields/countries")
|
| 46 |
-
resp = html_response(conn, 200)
|
| 47 |
-
|
| 48 |
-
assert resp =~ "Unknown"
|
| 49 |
-
assert find(resp, "#remove-country-rule-#{rule.id}")
|
| 50 |
-
end
|
| 51 |
-
|
| 52 |
-
test "add rule button is rendered", %{conn: conn, site: site} do
|
| 53 |
-
conn = get(conn, "/#{site.domain}/settings/shields/countries")
|
| 54 |
-
resp = html_response(conn, 200)
|
| 55 |
-
|
| 56 |
-
assert element_exists?(resp, ~s/button#add-country-rule[x-data]/)
|
| 57 |
-
attr = text_of_attr(resp, ~s/button#add-country-rule/, "x-on:click")
|
| 58 |
-
|
| 59 |
-
assert attr =~ "open-modal"
|
| 60 |
-
assert attr =~ "country-rule-form-modal"
|
| 61 |
-
end
|
| 62 |
-
|
| 63 |
-
test "add rule button is not rendered when maximum reached", %{conn: conn, site: site} do
|
| 64 |
-
country_codes =
|
| 65 |
-
Location.Country.all()
|
| 66 |
-
|> Enum.take(Shields.maximum_country_rules())
|
| 67 |
-
|> Enum.map(& &1.alpha_2)
|
| 68 |
-
|
| 69 |
-
for cc <- country_codes do
|
| 70 |
-
assert {:ok, _} =
|
| 71 |
-
Shields.add_country_rule(site, %{"country_code" => "#{cc}"})
|
| 72 |
-
end
|
| 73 |
-
|
| 74 |
-
conn = get(conn, "/#{site.domain}/settings/shields/countries")
|
| 75 |
-
resp = html_response(conn, 200)
|
| 76 |
-
|
| 77 |
-
refute element_exists?(resp, ~s/button#add-country-rule[x-data]/)
|
| 78 |
-
assert resp =~ "Maximum number of countries reached"
|
| 79 |
-
assert resp =~ "You've reached the maximum number of countries you can block (30)"
|
| 80 |
-
end
|
| 81 |
-
end
|
| 82 |
-
|
| 83 |
-
describe "Country Rules - LiveView" do
|
| 84 |
-
test "modal contains form", %{site: site, conn: conn} do
|
| 85 |
-
lv = get_liveview(conn, site)
|
| 86 |
-
html = render(lv)
|
| 87 |
-
|
| 88 |
-
assert element_exists?(
|
| 89 |
-
html,
|
| 90 |
-
~s/form[phx-submit="save-country-rule"] input[name="country_rule\[country_code\]"]/
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
assert submit_button(html, ~s/form[phx-submit="save-country-rule"]/)
|
| 94 |
-
end
|
| 95 |
-
|
| 96 |
-
test "submitting a valid country saves it", %{conn: conn, site: site, user: user} do
|
| 97 |
-
lv = get_liveview(conn, site)
|
| 98 |
-
|
| 99 |
-
lv
|
| 100 |
-
|> element("form")
|
| 101 |
-
|> render_submit(%{
|
| 102 |
-
"country_rule[country_code]" => "EE"
|
| 103 |
-
})
|
| 104 |
-
|
| 105 |
-
html = render(lv)
|
| 106 |
-
|
| 107 |
-
assert html =~ "Estonia"
|
| 108 |
-
|
| 109 |
-
added_by = "#{user.name} <#{user.email}>"
|
| 110 |
-
|
| 111 |
-
assert [%{id: id, country_code: "EE", added_by: ^added_by}] =
|
| 112 |
-
Shields.list_country_rules(site)
|
| 113 |
-
|
| 114 |
-
tooltip = text_of_attr(html, "#country-#{id}", "title")
|
| 115 |
-
assert tooltip =~ "Added at #{Date.utc_today()}"
|
| 116 |
-
assert tooltip =~ "by #{added_by}"
|
| 117 |
-
end
|
| 118 |
-
|
| 119 |
-
test "submitting Unknown (ZZ) country saves it", %{conn: conn, site: site} do
|
| 120 |
-
lv = get_liveview(conn, site)
|
| 121 |
-
|
| 122 |
-
lv
|
| 123 |
-
|> element("form")
|
| 124 |
-
|> render_submit(%{
|
| 125 |
-
"country_rule[country_code]" => "ZZ"
|
| 126 |
-
})
|
| 127 |
-
|
| 128 |
-
html = render(lv)
|
| 129 |
-
|
| 130 |
-
assert html =~ "Unknown"
|
| 131 |
-
|
| 132 |
-
assert [%{country_code: "ZZ"}] = Shields.list_country_rules(site)
|
| 133 |
-
end
|
| 134 |
-
|
| 135 |
-
test "clicking Remove deletes the rule", %{conn: conn, site: site} do
|
| 136 |
-
{:ok, _} =
|
| 137 |
-
Shields.add_country_rule(site, %{"country_code" => "EE"})
|
| 138 |
-
|
| 139 |
-
lv = get_liveview(conn, site)
|
| 140 |
-
|
| 141 |
-
html = render(lv)
|
| 142 |
-
assert text_of_element(html, "table tbody td") =~ "Estonia"
|
| 143 |
-
|
| 144 |
-
lv |> element(~s/button[phx-click="remove-country-rule"]/) |> render_click()
|
| 145 |
-
|
| 146 |
-
html = render(lv)
|
| 147 |
-
refute text_of_element(html, "table tbody td") =~ "Estonia"
|
| 148 |
-
|
| 149 |
-
assert Shields.count_country_rules(site) == 0
|
| 150 |
-
end
|
| 151 |
-
|
| 152 |
-
defp get_liveview(conn, site) do
|
| 153 |
-
conn = assign(conn, :live_module, PlausibleWeb.Live.Shields)
|
| 154 |
-
{:ok, lv, _html} = live(conn, "/#{site.domain}/settings/shields/countries")
|
| 155 |
-
|
| 156 |
-
lv
|
| 157 |
-
end
|
| 158 |
-
end
|
| 159 |
-
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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