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
Starter Tier: Getting ready for release (#5489)
RobertJoonasd00dde183e94
diff --git a/lib/plausible/billing/plan_benefits.ex b/lib/plausible/billing/plan_benefits.exnew file mode 100644index 0000000000..df13c09463--- /dev/null+++ b/lib/plausible/billing/plan_benefits.ex@@ -0,0 +1,135 @@+defmodule Plausible.Billing.PlanBenefits do+ @moduledoc false++ alias Plausible.Billing.Plan++ @doc """+ This function takes a starter plan and returns a list representing+ the different benefits a user gets when subscribing to this plan.+ """+ def for_starter(starter_plan) do+ [+ site_limit_benefit(starter_plan),+ data_retention_benefit(starter_plan),+ "Intuitive, fast and privacy-friendly dashboard",+ "Email/Slack reports",+ "Google Analytics import"+ ]+ |> Kernel.++(feature_benefits(starter_plan))+ |> Kernel.++(["Saved Segments"])+ end++ @doc """+ Returns Growth benefits for the given Growth plan.++ A second argument is also required - list of Starter benefits. This+ is because we don't want to list the same benefits in both Starter+ and Growth. Everything in Starter is also included in Growth.+ """+ def for_growth(growth_plan, starter_benefits) do+ [+ if(Enum.empty?(starter_benefits), do: nil, else: "Everything in Starter"),+ site_limit_benefit(growth_plan),+ team_member_limit_benefit(growth_plan),+ "Team Management",+ if(Enum.empty?(starter_benefits), do: "Saved Segments", else: nil)+ ]+ |> Kernel.++(feature_benefits(growth_plan))+ |> Kernel.--(starter_benefits)+ |> Enum.filter(& &1)+ end++ @doc """+ Returns Business benefits for the given Business plan.++ A second argument is also required - list of Growth benefits. This+ is because we don't want to list the same benefits in both Growth+ and Business. Everything in Growth is also included in Business.+ """+ def for_business(plan, growth_benefits, starter_benefits) do+ [+ "Everything in Growth",+ site_limit_benefit(plan),+ team_member_limit_benefit(plan),+ data_retention_benefit(plan)+ ]+ |> Kernel.++(feature_benefits(plan))+ |> Kernel.--(growth_benefits)+ |> Kernel.--(starter_benefits)+ |> Enum.filter(& &1)+ end++ @doc """+ This function only takes a list of business benefits. Since all+ limits and features of enterprise plans are configurable, we can+ say on the upgrade page that enterprise plans include everything+ in Business.+ """+ def for_enterprise(business_benefits) do+ team_members =+ cond do+ "Unlimited team members" in business_benefits -> nil+ "Up to 10 team members" in business_benefits -> "10+ team members"+ "Up to 50 team members" in business_benefits -> "50+ team members"+ # if there's nothing about team members in Business benefits, then+ # Growth has unlimited team members already. In that case, we don't+ # mention team members at all.+ true -> nil+ end++ sites =+ cond do+ "Up to 10 sites" in business_benefits -> "10+ sites"+ "Up to 50 sites" in business_benefits -> "50+ sites"+ # Before v4, every plan (both Growth and Business) had 50 sites.+ # Therefore, if Business benefits do not mention site limit, then+ # it's 50. Newer Business plans always define a higher site limit.+ true -> "50+ sites"+ end++ data_retention =+ if "5 years of data retention" in business_benefits, do: "5+ years of data retention"++ [+ "Everything in Business",+ sites,+ team_members,+ "600+ Stats API requests per hour",+ "Sites API",+ data_retention,+ "Technical onboarding",+ "Priority support"+ ]+ |> Enum.filter(& &1)+ end++ defp data_retention_benefit(%Plan{} = plan) do+ if plan.data_retention_in_years, do: "#{plan.data_retention_in_years} years of data retention"+ end++ defp team_member_limit_benefit(%Plan{} = plan) do+ case plan.team_member_limit do+ :unlimited -> "Unlimited team members"+ number -> "Up to #{number} team members"+ end+ end++ defp site_limit_benefit(%Plan{} = plan) do+ case plan.site_limit do+ 1 -> "One site"+ site_limit -> "Up to #{site_limit} sites"+ end+ end++ defp feature_benefits(%Plan{} = plan) do+ Enum.flat_map(plan.features, fn feature_mod ->+ case feature_mod.name() do+ :goals -> ["Goals and custom events"]+ :stats_api -> ["Stats API (600 requests per hour)", "Looker Studio Connector"]+ :shared_links -> ["Shared Links", "Embedded Dashboards"]+ :revenue_goals -> ["Ecommerce revenue attribution"]+ _ -> [feature_mod.display_name()]+ end+ end)+ end+enddiff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.exindex a6affd5cd4..a83ef1f385 100644--- a/lib/plausible/billing/plans.ex+++ b/lib/plausible/billing/plans.ex@@ -32,11 +32,13 @@ defmodule Plausible.Billing.Plans doendend- defp starter_plans_for(legacy?) do- if legacy? do- []- else- Enum.filter(plans_v5(), &(&1.kind == :starter))+ defp starter_plans_for(subscription, legacy?) do+ active_plan = get_regular_plan(subscription, only_non_expired: true)++ case {legacy?, active_plan} do+ {true, _} -> []+ {_, %Plan{kind: :growth, generation: g}} when g <= 4 -> []+ {_, _} -> Enum.filter(plans_v5(), &(&1.kind == :starter))endend@@ -72,8 +74,8 @@ defmodule Plausible.Billing.Plans docond dosubscription && Subscriptions.expired?(subscription) -> default_plans- owned_plan && owned_plan.generation < 4 -> plans_v3()- owned_plan && owned_plan.generation < 5 -> plans_v4()+ owned_plan && owned_plan.generation <= 3 -> plans_v3()+ owned_plan && owned_plan.generation <= 4 -> plans_v4()true -> default_plansend|> Enum.filter(&(&1.kind == :business))@@ -82,22 +84,22 @@ defmodule Plausible.Billing.Plans dodef available_plans_for(subscription, opts \\ []) dolegacy? = Keyword.get(opts, :legacy?, false)- plans =- Enum.concat([- starter_plans_for(legacy?),- growth_plans_for(subscription, legacy?),- business_plans_for(subscription, legacy?)- ])-- plans =- if Keyword.get(opts, :with_prices) do- customer_ip = Keyword.fetch!(opts, :customer_ip)- with_prices(plans, customer_ip)- else- plans- end+ %{+ starter: starter_plans_for(subscription, legacy?) |> maybe_add_prices(opts),+ growth: growth_plans_for(subscription, legacy?) |> maybe_add_prices(opts),+ business: business_plans_for(subscription, legacy?) |> maybe_add_prices(opts)+ }+ end++ defp maybe_add_prices([] = _plans, _opts), do: []- Enum.group_by(plans, & &1.kind)+ defp maybe_add_prices(plans, opts) do+ if Keyword.get(opts, :with_prices) do+ customer_ip = Keyword.fetch!(opts, :customer_ip)+ with_prices(plans, customer_ip)+ else+ plans+ endend@high_legacy_volumes [20_000_000, 50_000_000]diff --git a/lib/plausible/billing/qouta/quota.ex b/lib/plausible/billing/qouta/quota.exindex 59e8ad42c6..95d40400a5 100644--- a/lib/plausible/billing/qouta/quota.ex+++ b/lib/plausible/billing/qouta/quota.ex@@ -51,7 +51,7 @@ defmodule Plausible.Billing.Quota doend@doc """- Suggests a suitable tier (Growth or Business) for the given usage map.+ Suggests a suitable tier (Starter, Growth or Business) for the given usage map.If even the highest Business plan does not accommodate the usage, then`:custom` is returned. This means that this kind of usage should get on@@ -67,7 +67,8 @@ defmodule Plausible.Billing.Quota donot eligible_for_upgrade?(usage) ->nil- usage_fits_plan?(usage, highest_starter) and owned_tier not in [:business, :growth] ->+ not is_nil(highest_starter) and usage_fits_plan?(usage, highest_starter) and+ owned_tier not in [:business, :growth] ->:starterusage_fits_plan?(usage, highest_growth) and owned_tier != :business ->diff --git a/lib/plausible/teams/billing.ex b/lib/plausible/teams/billing.exindex 80ec8d3459..63f24e9dd1 100644--- a/lib/plausible/teams/billing.ex+++ b/lib/plausible/teams/billing.ex@@ -6,7 +6,6 @@ defmodule Plausible.Teams.Billing doimport Ecto.Queryalias Plausible.Billing.EnterprisePlan- alias Plausible.Billing.Plansalias Plausible.Billing.Subscriptionalias Plausible.Billing.Subscriptionsalias Plausible.Repo@@ -22,6 +21,42 @@ defmodule Plausible.Teams.Billing do@typep last_30_days_usage() :: %{:last_30_days => Quota.usage_cycle()}@typep monthly_pageview_usage() :: Quota.cycles_usage() | last_30_days_usage()+ @starter_tier_launch ~D[2025-06-11]+ def starter_tier_launch(), do: @starter_tier_launch++ def show_new_upgrade_page?(nil = _team) do+ FunWithFlags.enabled?(:starter_tier)+ end++ def show_new_upgrade_page?(%Teams.Team{} = team) do+ team = Teams.with_subscription(team)+ feature_flag_enabled? = FunWithFlags.enabled?(:starter_tier, for: team)++ subscription_plan = Plans.get_subscription_plan(team.subscription)++ case {subscription_plan, team.trial_expiry_date} do+ {%Plan{generation: 5}, _} ->+ true++ {nil, nil} ->+ feature_flag_enabled?++ {nil, trial_expiry_date} ->+ diff = Date.diff(@starter_tier_launch, trial_expiry_date)+ # Active or recently (less than 10 days ago) ended trials+ # should be able to subscribe to the plans they saw when+ # they signed up.+ if diff <= 10 and diff >= -30 do+ false+ else+ feature_flag_enabled?+ end++ {_, _} ->+ feature_flag_enabled?+ end+ end+def grandfathered_team?(nil), do: falsedef grandfathered_team?(team) dodiff --git a/lib/plausible_web/components/billing/legacy_plan_box.ex b/lib/plausible_web/components/billing/legacy_plan_box.exindex bf4507a064..663fc962cf 100644--- a/lib/plausible_web/components/billing/legacy_plan_box.ex+++ b/lib/plausible_web/components/billing/legacy_plan_box.ex@@ -9,7 +9,7 @@ defmodule PlausibleWeb.Components.Billing.LegacyPlanBox douse PlausibleWeb, :componentrequire Plausible.Billing.Subscription.Status- alias PlausibleWeb.Components.Billing.{PlanBenefits, Notice}+ alias PlausibleWeb.Components.Billing.{LegacyPlanBenefits, Notice}alias Plausible.Billing.{Plan, Quota, Subscription}def standard(assigns) do@@ -52,7 +52,7 @@ defmodule PlausibleWeb.Components.Billing.LegacyPlanBox do<%= if @owned && @kind == :growth && @plan_to_render.generation < 4 do %><Notice.growth_grandfathered /><% else %>- <PlanBenefits.render benefits={@benefits} class="text-gray-600 dark:text-gray-100" />+ <LegacyPlanBenefits.render benefits={@benefits} class="text-gray-600 dark:text-gray-100" /><% end %></div>"""@@ -91,7 +91,7 @@ defmodule PlausibleWeb.Components.Billing.LegacyPlanBox do</p><p class="h-4 mt-1"></p><.contact_button class="" />- <PlanBenefits.render benefits={@benefits} class="text-gray-300 dark:text-gray-100" />+ <LegacyPlanBenefits.render benefits={@benefits} class="text-gray-300 dark:text-gray-100" /></div>"""enddiff --git a/lib/plausible_web/components/billing/notice.ex b/lib/plausible_web/components/billing/notice.exindex 28ff6d42cb..65759d5482 100644--- a/lib/plausible_web/components/billing/notice.ex+++ b/lib/plausible_web/components/billing/notice.ex@@ -283,12 +283,13 @@ defmodule PlausibleWeb.Components.Billing.Notice dodefp lose_grandfathering_warning(%{subscription: subscription} = assigns) doplan = Plans.get_regular_plan(subscription, only_non_expired: true)- loses_grandfathering = plan && plan.generation < 4+ latest_generation = if FunWithFlags.enabled?(:starter_tier), do: 5, else: 4+ loses_grandfathering? = plan && plan.generation < latest_generation- assigns = assign(assigns, :loses_grandfathering, loses_grandfathering)+ assigns = assign(assigns, :loses_grandfathering?, loses_grandfathering?)~H"""- <p :if={@loses_grandfathering} class="mt-2">+ <p :if={@loses_grandfathering?} class="mt-2">Please also note that by letting your subscription expire, you lose access to our grandfathered terms. If you want to subscribe again after that, your account will be offered the <.linkhref="https://plausible.io/#pricing"target="_blank"diff --git a/lib/plausible_web/components/billing/plan_benefits.ex b/lib/plausible_web/components/billing/plan_benefits.exindex ac79e558fe..a1a18b389c 100644--- a/lib/plausible_web/components/billing/plan_benefits.ex+++ b/lib/plausible_web/components/billing/plan_benefits.ex@@ -5,7 +5,6 @@ defmodule PlausibleWeb.Components.Billing.PlanBenefits do"""use Phoenix.Component- alias Plausible.Billing.Planattr :benefits, :list, required: trueattr :class, :string, default: nil@@ -13,10 +12,10 @@ defmodule PlausibleWeb.Components.Billing.PlanBenefits do@doc """This function takes a list of benefits returned by either one of:- * `for_starter/1`- * `for_growth/2`- * `for_business/2`- * `for_enterprise/1`.+ * `Plausible.Billing.PlanBenefits.for_starter/1`+ * `Plausible.Billing.PlanBenefits.for_growth/2`+ * `Plausible.Billing.PlanBenefits.for_business/3`+ * `Plausible.Billing.PlanBenefits.for_enterprise/1`.and renders them as HTML.@@ -29,123 +28,16 @@ defmodule PlausibleWeb.Components.Billing.PlanBenefits do<ul role="list" class={["mt-8 space-y-1 text-sm leading-6", @class]}><li :for={benefit <- @benefits} class="flex gap-x-1"><Heroicons.check class="shrink-0 h-5 w-5 text-indigo-600 dark:text-green-600" />- {if is_binary(benefit), do: benefit, else: benefit.(assigns)}+ <%= if benefit == "Sites API" do %>+ <.sites_api_benefit />+ <% else %>+ {benefit}+ <% end %></li></ul>"""end- @doc """- This function takes a starter plan and returns a list representing- the different benefits a user gets when subscribing to this plan.- """- def for_starter(starter_plan) do- [- site_limit_benefit(starter_plan),- data_retention_benefit(starter_plan),- "Intuitive, fast and privacy-friendly dashboard",- "Email/Slack reports",- "Google Analytics import"- ]- |> Kernel.++(feature_benefits(starter_plan))- |> Kernel.++(["Saved Segments"])- end-- @doc """- Returns Growth benefits for the given Growth plan.-- A second argument is also required - list of Starter benefits. This- is because we don't want to list the same benefits in both Starter- and Growth. Everything in Starter is also included in Growth.- """- def for_growth(growth_plan, starter_benefits) do- [- "Everything in Starter",- site_limit_benefit(growth_plan),- team_member_limit_benefit(growth_plan),- "Team Management"- ]- |> Kernel.++(feature_benefits(growth_plan))- |> Kernel.--(starter_benefits)- |> Enum.filter(& &1)- end-- @doc """- Returns Business benefits for the given Business plan.-- A second argument is also required - list of Growth benefits. This- is because we don't want to list the same benefits in both Growth- and Business. Everything in Growth is also included in Business.- """- def for_business(plan, growth_benefits, starter_benefits) do- [- "Everything in Growth",- site_limit_benefit(plan),- team_member_limit_benefit(plan),- data_retention_benefit(plan)- ]- |> Kernel.++(feature_benefits(plan))- |> Kernel.--(growth_benefits)- |> Kernel.--(starter_benefits)- |> Kernel.++(["Priority support"])- |> Enum.filter(& &1)- end-- @doc """- This function only takes a list of business benefits. Since all- limits and features of enterprise plans are configurable, we can- say on the upgrade page that enterprise plans include everything- in Business.- """- def for_enterprise(business_benefits) do- team_members =- if "Up to 10 team members" in business_benefits, do: "10+ team members"-- data_retention =- if "5 years of data retention" in business_benefits, do: "5+ years of data retention"-- [- "Everything in Business",- team_members,- "50+ sites",- "600+ Stats API requests per hour",- &sites_api_benefit/1,- data_retention,- "Technical onboarding"- ]- |> Enum.filter(& &1)- end-- defp data_retention_benefit(%Plan{} = plan) do- if plan.data_retention_in_years, do: "#{plan.data_retention_in_years} years of data retention"- end-- defp team_member_limit_benefit(%Plan{} = plan) do- case plan.team_member_limit do- :unlimited -> "Unlimited team members"- number -> "Up to #{number} team members"- end- end-- defp site_limit_benefit(%Plan{} = plan) do- case plan.site_limit do- 1 -> "One site"- site_limit -> "Up to #{site_limit} sites"- end- end-- defp feature_benefits(%Plan{} = plan) do- Enum.flat_map(plan.features, fn feature_mod ->- case feature_mod.name() do- :goals -> ["Goals and custom events"]- :stats_api -> ["Stats API (600 requests per hour)", "Looker Studio Connector"]- :shared_links -> ["Shared Links", "Embedded Dashboards"]- :revenue_goals -> ["Ecommerce revenue attribution"]- _ -> [feature_mod.display_name()]- end- end)- end-defp sites_api_benefit(assigns) do~H"""<p>diff --git a/lib/plausible_web/components/billing/plan_box.ex b/lib/plausible_web/components/billing/plan_box.exindex 039d7c2b09..e7a721f769 100644--- a/lib/plausible_web/components/billing/plan_box.ex+++ b/lib/plausible_web/components/billing/plan_box.ex@@ -4,7 +4,7 @@ defmodule PlausibleWeb.Components.Billing.PlanBox douse PlausibleWeb, :componentrequire Plausible.Billing.Subscription.Status- alias PlausibleWeb.Components.Billing.{PlanBenefits, Notice}+ alias PlausibleWeb.Components.Billing.{PlanBenefits}alias Plausible.Billing.{Plan, Quota, Subscription}@plan_box_price_container_class "relative h-20 pt-4 max-h-20 whitespace-nowrap overflow-hidden"@@ -51,11 +51,7 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do<.contact_button class="bg-indigo-600 hover:bg-indigo-500 text-white" /><% end %></div>- <%= if @owned && @kind == :growth && @plan_to_render.generation < 5 do %>- <Notice.growth_grandfathered />- <% else %>- <PlanBenefits.render benefits={@benefits} class="text-gray-600 dark:text-gray-100" />- <% end %>+ <PlanBenefits.render benefits={@benefits} class="text-gray-600 dark:text-gray-100" /></div>"""enddiff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.exindex 52517f0b6a..1c15c18e01 100644--- a/lib/plausible_web/controllers/billing_controller.ex+++ b/lib/plausible_web/controllers/billing_controller.ex@@ -20,7 +20,7 @@ defmodule PlausibleWeb.BillingController doteam = conn.assigns.current_team{live_module, hide_header?} =- if FunWithFlags.enabled?(:starter_tier, for: conn.assigns.current_user) do+ if Plausible.Teams.Billing.show_new_upgrade_page?(team) do{PlausibleWeb.Live.ChoosePlan, true}else{PlausibleWeb.Live.LegacyChoosePlan, false}diff --git a/lib/plausible_web/live/choose_plan.ex b/lib/plausible_web/live/choose_plan.exindex 485fb4e283..bd7a9e4782 100644--- a/lib/plausible_web/live/choose_plan.ex+++ b/lib/plausible_web/live/choose_plan.ex@@ -6,8 +6,8 @@ defmodule PlausibleWeb.Live.ChoosePlan dorequire Plausible.Billing.Subscription.Status- alias PlausibleWeb.Components.Billing.{PlanBox, PlanBenefits, Notice, PageviewSlider}- alias Plausible.Billing.{Plans, Quota}+ alias PlausibleWeb.Components.Billing.{PlanBox, Notice, PageviewSlider}+ alias Plausible.Billing.{Plans, Quota, PlanBenefits}alias PlausibleWeb.Router.Helpers, as: Routes@contact_link "https://plausible.io/contact"@@ -95,17 +95,21 @@ defmodule PlausibleWeb.Live.ChoosePlan doenddef render(assigns) do- starter_plan_to_render =- assigns.selected_starter_plan || List.last(assigns.available_plans.starter)-growth_plan_to_render =assigns.selected_growth_plan || List.last(assigns.available_plans.growth)business_plan_to_render =assigns.selected_business_plan || List.last(assigns.available_plans.business)+ starter_plan_to_render =+ assigns.selected_starter_plan || List.last(assigns.available_plans.starter)+starter_benefits =- PlanBenefits.for_starter(starter_plan_to_render)+ if starter_plan_to_render do+ PlanBenefits.for_starter(starter_plan_to_render)+ else+ []+ endgrowth_benefits =PlanBenefits.for_growth(growth_plan_to_render, starter_benefits)@@ -127,7 +131,10 @@ defmodule PlausibleWeb.Live.ChoosePlan do~H"""<div class="pt-1 pb-12 sm:pb-16 text-gray-900 dark:text-gray-100">- <div class="mx-auto max-w-7xl px-6 lg:px-8">+ <div class={[+ "mx-auto px-6 lg:px-8",+ if(is_nil(@starter_plan_to_render), do: "max-w-5xl", else: "max-w-7xl")+ ]}><Notice.pending_site_ownerships_noticeclass="pb-6"pending_ownership_count={length(@pending_ownership_site_ids)}@@ -170,8 +177,12 @@ defmodule PlausibleWeb.Live.ChoosePlan doavailable_volumes={@available_volumes}/></div>- <div class="mt-6 isolate mx-auto grid max-w-md grid-cols-1 gap-4 lg:mx-0 lg:max-w-none lg:grid-cols-4">+ <div class={[+ "mt-6 isolate mx-auto grid max-w-md grid-cols-1 gap-4 lg:max-w-none lg:mx-0",+ if(is_nil(@starter_plan_to_render), do: "lg:grid-cols-3", else: "lg:grid-cols-4")+ ]}><PlanBox.standard+ :if={@growth_plan_to_render.generation == 5}kind={:starter}owned={@owned_tier == :starter}recommended={@recommended_tier == :starter}diff --git a/test/plausible/billing/billing_test.exs b/test/plausible/billing/billing_test.exsindex fd8377d343..97f053c5fa 100644--- a/test/plausible/billing/billing_test.exs+++ b/test/plausible/billing/billing_test.exs@@ -622,4 +622,77 @@ defmodule Plausible.BillingTest dorefute Plausible.Teams.Billing.has_active_subscription?(paused_team)refute Plausible.Teams.Billing.has_active_subscription?(nil)end++ @v4_plan_id "857088"+ @v5_plan_id "910429"++ describe "show_new_upgrade_page?/1" do+ @describetag :ee_only++ test "returns true for non-existing team" do+ assert Plausible.Teams.Billing.show_new_upgrade_page?(nil) == true+ end++ test "returns true for team with no trial_expiry_date" do+ {:ok, team} = new_user() |> Plausible.Teams.get_or_create()+ team = %{team | trial_expiry_date: nil}+ assert Plausible.Teams.Billing.show_new_upgrade_page?(team) == true+ end++ test "returns true for a user already on a v5 plan regardless of starter_tier feature flag" do+ team =+ new_user()+ |> subscribe_to_plan(@v5_plan_id)+ |> team_of()++ FunWithFlags.disable(:starter_tier, for_actor: team)++ assert Plausible.Teams.Billing.show_new_upgrade_page?(team) == true+ end++ test "returns false for a trial that expired 10 days before starter tier release" do+ trial_expiry_date =+ Plausible.Teams.Billing.starter_tier_launch()+ |> Date.shift(day: -10)++ team = new_user(trial_expiry_date: trial_expiry_date) |> team_of()+ assert Plausible.Teams.Billing.show_new_upgrade_page?(team) == false+ end++ test "returns true for a trial that expired 11 days before starter tier release" do+ trial_expiry_date =+ Plausible.Teams.Billing.starter_tier_launch()+ |> Date.shift(day: -11)++ team = new_user(trial_expiry_date: trial_expiry_date) |> team_of()+ assert Plausible.Teams.Billing.show_new_upgrade_page?(team) == true+ end++ test "returns false for a trial that started on the day of starter tier release" do+ trial_expiry_date =+ Plausible.Teams.Billing.starter_tier_launch()+ |> Date.shift(day: 30)++ team = new_user(trial_expiry_date: trial_expiry_date) |> team_of()+ assert Plausible.Teams.Billing.show_new_upgrade_page?(team) == false+ end++ test "returns true for a trial that started after starter tier release" do+ trial_expiry_date =+ Plausible.Teams.Billing.starter_tier_launch()+ |> Date.shift(day: 31)++ team = new_user(trial_expiry_date: trial_expiry_date) |> team_of()+ assert Plausible.Teams.Billing.show_new_upgrade_page?(team) == true+ end++ test "returns true for a v4 subscription" do+ team =+ new_user(trial_expiry_date: ~D[2025-01-01])+ |> subscribe_to_plan(@v4_plan_id)+ |> team_of()++ assert Plausible.Teams.Billing.show_new_upgrade_page?(team) == true+ end+ endenddiff --git a/test/plausible/billing/plan_benefits_test.exs b/test/plausible/billing/plan_benefits_test.exsnew file mode 100644index 0000000000..190f5e99cb--- /dev/null+++ b/test/plausible/billing/plan_benefits_test.exs@@ -0,0 +1,192 @@+defmodule Plausible.Billing.PlanBenefitsTest do+ use ExUnit.Case, async: true++ alias Plausible.Billing.{Plans, PlanBenefits}++ describe "for_starter/1" do+ test "returns v5 Starter plan benefits" do+ assert PlanBenefits.for_starter(get_10k_plan(5, :starter)) == [+ "One site",+ "3 years of data retention",+ "Intuitive, fast and privacy-friendly dashboard",+ "Email/Slack reports",+ "Google Analytics import",+ "Goals and custom events",+ "Saved Segments"+ ]+ end+ end++ describe "for_growth/2" do+ test "returns v5 Growth plan benefits" do+ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))++ assert PlanBenefits.for_growth(get_10k_plan(5, :growth), starter_benefits) == [+ "Everything in Starter",+ "Up to 3 sites",+ "Up to 3 team members",+ "Team Management",+ "Shared Links",+ "Embedded Dashboards",+ "Shared Segments"+ ]+ end++ test "returns v4 Growth plan benefits" do+ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))++ assert PlanBenefits.for_growth(get_10k_plan(4, :growth), starter_benefits) == [+ "Everything in Starter",+ "Up to 10 sites",+ "Up to 3 team members",+ "Team Management",+ "Shared Links",+ "Embedded Dashboards"+ ]+ end++ for generation <- [1, 2, 3] do+ test "returns v#{generation} Growth plan benefits (with empty Starter benefits)" do+ growth_plan = get_10k_plan(unquote(generation), :growth)++ assert PlanBenefits.for_growth(growth_plan, []) == [+ "Up to 50 sites",+ "Unlimited team members",+ "Team Management",+ "Saved Segments",+ "Goals and custom events",+ "Custom Properties",+ "Stats API (600 requests per hour)",+ "Looker Studio Connector",+ "Shared Links",+ "Embedded Dashboards"+ ]+ end+ end+ end++ describe "for_business/3" do+ test "returns v5 Business plan benefits (with Growth v5 plans available)" do+ business_plan = get_10k_plan(5, :business)+ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))+ growth_benefits = PlanBenefits.for_growth(get_10k_plan(5, :growth), starter_benefits)++ assert PlanBenefits.for_business(business_plan, growth_benefits, starter_benefits) == [+ "Everything in Growth",+ "Up to 10 sites",+ "Up to 10 team members",+ "5 years of data retention",+ "Custom Properties",+ "Stats API (600 requests per hour)",+ "Looker Studio Connector",+ "Ecommerce revenue attribution",+ "Funnels"+ ]+ end++ test "returns v4 Business plan benefits (with Growth v4 plans available)" do+ business_plan = get_10k_plan(4, :business)+ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))+ growth_benefits = PlanBenefits.for_growth(get_10k_plan(4, :growth), starter_benefits)++ assert PlanBenefits.for_business(business_plan, growth_benefits, starter_benefits) == [+ "Everything in Growth",+ "Up to 50 sites",+ "Up to 10 team members",+ "5 years of data retention",+ "Custom Properties",+ "Ecommerce revenue attribution",+ "Funnels",+ "Stats API (600 requests per hour)",+ "Looker Studio Connector",+ "Shared Segments"+ ]+ end++ for generation <- [1, 2, 3] do+ test "returns v3 Business plan benefits (with Growth v#{generation} plans available)" do+ business_plan = get_10k_plan(3, :business)++ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))++ growth_benefits =+ PlanBenefits.for_growth(get_10k_plan(unquote(generation), :growth), starter_benefits)++ assert PlanBenefits.for_business(+ business_plan,+ growth_benefits,+ starter_benefits+ ) == [+ "Everything in Growth",+ "Ecommerce revenue attribution",+ "Funnels",+ "Shared Segments"+ ]+ end+ end+ end++ describe "for_enterprise/1" do+ test "with v5 business benefits" do+ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))+ growth_benefits = PlanBenefits.for_growth(get_10k_plan(5, :growth), starter_benefits)++ v5_business_benefits =+ PlanBenefits.for_business(get_10k_plan(5, :business), growth_benefits, starter_benefits)++ assert PlanBenefits.for_enterprise(v5_business_benefits) == [+ "Everything in Business",+ "10+ sites",+ "10+ team members",+ "600+ Stats API requests per hour",+ "Sites API",+ "5+ years of data retention",+ "Technical onboarding",+ "Priority support"+ ]+ end++ test "with v4 business benefits" do+ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))+ growth_benefits = PlanBenefits.for_growth(get_10k_plan(4, :growth), starter_benefits)++ v4_business_benefits =+ PlanBenefits.for_business(get_10k_plan(4, :business), growth_benefits, starter_benefits)++ assert PlanBenefits.for_enterprise(v4_business_benefits) == [+ "Everything in Business",+ "50+ sites",+ "10+ team members",+ "600+ Stats API requests per hour",+ "Sites API",+ "5+ years of data retention",+ "Technical onboarding",+ "Priority support"+ ]+ end++ test "with v3 business benefits" do+ starter_benefits = PlanBenefits.for_starter(get_10k_plan(5, :starter))+ growth_benefits = PlanBenefits.for_growth(get_10k_plan(3, :growth), starter_benefits)++ v3_business_benefits =+ PlanBenefits.for_business(get_10k_plan(3, :business), growth_benefits, starter_benefits)++ assert PlanBenefits.for_enterprise(v3_business_benefits) == [+ "Everything in Business",+ "50+ sites",+ "600+ Stats API requests per hour",+ "Sites API",+ "Technical onboarding",+ "Priority support"+ ]+ end+ end++ defp get_10k_plan(generation, kind) do+ Enum.find(Plans.all(), fn plan ->+ plan.generation == generation and plan.kind == kind and+ plan.monthly_pageview_limit == 10_000+ end)+ end+enddiff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exsindex ab1d950ed2..b41810522a 100644--- a/test/plausible/billing/quota_test.exs+++ b/test/plausible/billing/quota_test.exs@@ -1007,6 +1007,17 @@ defmodule Plausible.Billing.QuotaTest doassert suggested_tier == :starterend+ test "returns :growth if usage within starter limits but starter plan not available",+ %{team: team} do+ suggested_tier =+ team+ |> Plausible.Teams.Billing.quota_usage(with_features: true)+ |> Map.put(:sites, 1)+ |> Quota.suggest_tier(nil, @highest_growth_plan, @highest_business_plan, nil)++ assert suggested_tier == :growth+ end+test "returns :growth if usage within growth limits",%{team: team} dosuggested_tier =diff --git a/test/plausible_web/live/choose_plan_test.exs b/test/plausible_web/live/choose_plan_test.exsindex 3fd8a3c23e..263c419a5e 100644--- a/test/plausible_web/live/choose_plan_test.exs+++ b/test/plausible_web/live/choose_plan_test.exs@@ -1,1405 +1,1432 @@defmodule PlausibleWeb.Live.ChoosePlanTest douse PlausibleWeb.ConnCase, async: true- use Plausible.Teams.Test- @moduletag :ee_only-- import Phoenix.LiveViewTest- import Plausible.Test.Support.HTML- require Plausible.Billing.Subscription.Status- alias Plausible.{Repo, Billing, Billing.Subscription}-- @v1_10k_yearly_plan_id "572810"- @v1_50m_yearly_plan_id "650653"- @v2_20m_yearly_plan_id "653258"- @v5_starter_5m_monthly_plan_id "910425"- @v4_growth_10k_monthly_plan_id "857097"- @v4_growth_200k_yearly_plan_id "857081"- @v5_growth_10k_yearly_plan_id "910430"- @v5_growth_200k_yearly_plan_id "910434"- @v4_business_5m_monthly_plan_id "857111"- @v5_business_5m_monthly_plan_id "910457"- @v3_business_10k_monthly_plan_id "857481"-- @monthly_interval_button ~s/label[phx-click="set_interval"][phx-value-interval="monthly"]/- @yearly_interval_button ~s/label[phx-click="set_interval"][phx-value-interval="yearly"]/- @interval_button_active_class "bg-indigo-600 text-white"- @slider_input ~s/input[name="slider"]/- @slider_value "#slider-value"-- @starter_plan_box "#starter-plan-box"- @starter_plan_tooltip "#starter-plan-box .tooltip-content"- @starter_price_tag_amount "#starter-price-tag-amount"- @starter_price_tag_interval "#starter-price-tag-interval"- @starter_discount_price_tag_amount "#starter-discount-price-tag-amount"- @starter_discount_price_tag_strikethrough_amount "#starter-discount-price-tag-strikethrough-amount"- @starter_vat_notice "#starter-vat-notice"- @starter_highlight_pill "#{@starter_plan_box} #highlight-pill"- @starter_checkout_button "#starter-checkout"-- @growth_plan_box "#growth-plan-box"- @growth_plan_tooltip "#growth-plan-box .tooltip-content"- @growth_price_tag_amount "#growth-price-tag-amount"- @growth_price_tag_interval "#growth-price-tag-interval"- @growth_discount_price_tag_amount "#growth-discount-price-tag-amount"- @growth_discount_price_tag_strikethrough_amount "#growth-discount-price-tag-strikethrough-amount"- @growth_vat_notice "#growth-vat-notice"- @growth_highlight_pill "#{@growth_plan_box} #highlight-pill"- @growth_checkout_button "#growth-checkout"-- @business_plan_box "#business-plan-box"- @business_price_tag_amount "#business-price-tag-amount"- @business_price_tag_interval "#business-price-tag-interval"- @business_discount_price_tag_amount "#business-discount-price-tag-amount"- @business_discount_price_tag_strikethrough_amount "#business-discount-price-tag-strikethrough-amount"- @business_vat_notice "#business-vat-notice"- @business_highlight_pill "#{@business_plan_box} #highlight-pill"- @business_checkout_button "#business-checkout"-- @enterprise_plan_box "#enterprise-plan-box"- @enterprise_highlight_pill "#enterprise-highlight-pill"-- @slider_volumes ["10k", "100k", "200k", "500k", "1M", "2M", "5M", "10M", "10M+"]-- describe "for a user with no subscription" do- setup [:create_user, :create_site, :log_in]-- test "displays basic page content", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)-- assert doc =~ "Upgrade your trial"- assert doc =~ "Back to Settings"- assert doc =~ "You have used"- assert doc =~ "<b>0</b>"- assert doc =~ "billable pageviews in the last 30 days"- assert doc =~ "Any other questions?"- assert doc =~ "What happens if I go over my monthly pageview limit?"- assert doc =~ "Enterprise"- assert doc =~ "+ VAT"- end-- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])- end- test "displays plan benefits", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)-- starter_box = text_of_element(doc, @starter_plan_box)- growth_box = text_of_element(doc, @growth_plan_box)- business_box = text_of_element(doc, @business_plan_box)- enterprise_box = text_of_element(doc, @enterprise_plan_box)-- assert starter_box =~ "Intuitive, fast and privacy-friendly dashboard"- assert starter_box =~ "Email/Slack reports"- assert starter_box =~ "Google Analytics import"- assert starter_box =~ "Goals and custom events"- assert starter_box =~ "One site"- assert starter_box =~ "3 years of data retention"-- assert growth_box =~ "Up to 3 team members"- assert growth_box =~ "Up to 3 sites"- assert growth_box =~ "Team Management"- assert growth_box =~ "Shared Links"- assert growth_box =~ "Shared Segments"-- assert business_box =~ "Everything in Growth"- assert business_box =~ "Up to 10 team members"- assert business_box =~ "Up to 10 sites"- assert business_box =~ "Stats API (600 requests per hour)"- assert business_box =~ "Looker Studio Connector"- assert business_box =~ "Custom Properties"- assert business_box =~ "Funnels"- assert business_box =~ "Ecommerce revenue attribution"- assert business_box =~ "Priority support"-- refute business_box =~ "Goals and custom events"-- assert enterprise_box =~ "Everything in Business"- assert enterprise_box =~ "10+ team members"- assert enterprise_box =~ "50+ sites"- assert enterprise_box =~ "600+ Stats API requests per hour"- assert enterprise_box =~ "Sites API access for"- assert enterprise_box =~ "Technical onboarding"-- assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~- "https://plausible.io/white-label-web-analytics"- end+ on_ee do+ use Plausible.Teams.Test+ @moduletag :ee_only++ import Phoenix.LiveViewTest+ import Plausible.Test.Support.HTML+ require Plausible.Billing.Subscription.Status+ alias Plausible.{Repo, Billing, Billing.Subscription}++ @v1_10k_yearly_plan_id "572810"+ @v1_50m_yearly_plan_id "650653"+ @v2_20m_yearly_plan_id "653258"+ @v5_starter_5m_monthly_plan_id "910425"+ @v4_growth_10k_monthly_plan_id "857097"+ @v4_growth_200k_yearly_plan_id "857081"+ @v5_growth_10k_yearly_plan_id "910430"+ @v5_growth_200k_yearly_plan_id "910434"+ @v4_business_5m_monthly_plan_id "857111"+ @v5_business_5m_monthly_plan_id "910457"+ @v3_business_10k_monthly_plan_id "857481"++ @monthly_interval_button ~s/label[phx-click="set_interval"][phx-value-interval="monthly"]/+ @yearly_interval_button ~s/label[phx-click="set_interval"][phx-value-interval="yearly"]/+ @interval_button_active_class "bg-indigo-600 text-white"+ @slider_input ~s/input[name="slider"]/+ @slider_value "#slider-value"++ @starter_plan_box "#starter-plan-box"+ @starter_plan_tooltip "#starter-plan-box .tooltip-content"+ @starter_price_tag_amount "#starter-price-tag-amount"+ @starter_price_tag_interval "#starter-price-tag-interval"+ @starter_discount_price_tag_amount "#starter-discount-price-tag-amount"+ @starter_discount_price_tag_strikethrough_amount "#starter-discount-price-tag-strikethrough-amount"+ @starter_vat_notice "#starter-vat-notice"+ @starter_highlight_pill "#{@starter_plan_box} #highlight-pill"+ @starter_checkout_button "#starter-checkout"++ @growth_plan_box "#growth-plan-box"+ @growth_plan_tooltip "#growth-plan-box .tooltip-content"+ @growth_price_tag_amount "#growth-price-tag-amount"+ @growth_price_tag_interval "#growth-price-tag-interval"+ @growth_discount_price_tag_amount "#growth-discount-price-tag-amount"+ @growth_discount_price_tag_strikethrough_amount "#growth-discount-price-tag-strikethrough-amount"+ @growth_vat_notice "#growth-vat-notice"+ @growth_highlight_pill "#{@growth_plan_box} #highlight-pill"+ @growth_checkout_button "#growth-checkout"++ @business_plan_box "#business-plan-box"+ @business_price_tag_amount "#business-price-tag-amount"+ @business_price_tag_interval "#business-price-tag-interval"+ @business_discount_price_tag_amount "#business-discount-price-tag-amount"+ @business_discount_price_tag_strikethrough_amount "#business-discount-price-tag-strikethrough-amount"+ @business_vat_notice "#business-vat-notice"+ @business_highlight_pill "#{@business_plan_box} #highlight-pill"+ @business_checkout_button "#business-checkout"++ @enterprise_plan_box "#enterprise-plan-box"+ @enterprise_highlight_pill "#enterprise-highlight-pill"++ @slider_volumes ["10k", "100k", "200k", "500k", "1M", "2M", "5M", "10M", "10M+"]++ describe "for a user with no subscription" do+ setup [:create_user, :create_site, :log_in]++ setup %{user: user} do+ {:ok, team} = Plausible.Teams.get_or_create(user)++ trial_expiry_date = Plausible.Teams.Billing.starter_tier_launch() |> Date.shift(day: -30)++ Ecto.Changeset.change(team, %{trial_expiry_date: trial_expiry_date})+ |> Repo.update()++ :ok+ end- test "default billing interval is yearly, and can switch to monthly", %{conn: conn} do- {:ok, lv, doc} = get_liveview(conn)+ test "displays basic page content", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)++ assert doc =~ "Upgrade your trial"+ assert doc =~ "Back to Settings"+ assert doc =~ "You have used"+ assert doc =~ "<b>0</b>"+ assert doc =~ "billable pageviews in the last 30 days"+ assert doc =~ "Any other questions?"+ assert doc =~ "What happens if I go over my monthly pageview limit?"+ assert doc =~ "Enterprise"+ assert doc =~ "+ VAT"+ end- assert class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class- refute class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- doc = element(lv, @monthly_interval_button) |> render_click()+ test "displays plan benefits", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)++ starter_box = text_of_element(doc, @starter_plan_box)+ growth_box = text_of_element(doc, @growth_plan_box)+ business_box = text_of_element(doc, @business_plan_box)+ enterprise_box = text_of_element(doc, @enterprise_plan_box)++ assert starter_box =~ "Intuitive, fast and privacy-friendly dashboard"+ assert starter_box =~ "Email/Slack reports"+ assert starter_box =~ "Google Analytics import"+ assert starter_box =~ "Goals and custom events"+ assert starter_box =~ "One site"+ assert starter_box =~ "3 years of data retention"++ assert growth_box =~ "Up to 3 team members"+ assert growth_box =~ "Up to 3 sites"+ assert growth_box =~ "Team Management"+ assert growth_box =~ "Shared Links"+ assert growth_box =~ "Shared Segments"++ assert business_box =~ "Everything in Growth"+ assert business_box =~ "Up to 10 team members"+ assert business_box =~ "Up to 10 sites"+ assert business_box =~ "Stats API (600 requests per hour)"+ assert business_box =~ "Looker Studio Connector"+ assert business_box =~ "Custom Properties"+ assert business_box =~ "Funnels"+ assert business_box =~ "Ecommerce revenue attribution"++ refute business_box =~ "Goals and custom events"++ assert enterprise_box =~ "Everything in Business"+ assert enterprise_box =~ "10+ team members"+ assert enterprise_box =~ "10+ sites"+ assert enterprise_box =~ "600+ Stats API requests per hour"+ assert enterprise_box =~ "Sites API access for"+ assert enterprise_box =~ "Technical onboarding"+ assert enterprise_box =~ "Priority support"++ assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~+ "https://plausible.io/white-label-web-analytics"+ end- refute class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class- assert class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class- end+ test "default billing interval is yearly, and can switch to monthly", %{conn: conn} do+ {:ok, lv, doc} = get_liveview(conn)- test "default pageview limit is 10k", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @slider_value) == "10k"- assert text_of_element(doc, @starter_price_tag_amount) == "€90"- assert text_of_element(doc, @growth_price_tag_amount) == "€140"- assert text_of_element(doc, @business_price_tag_amount) == "€190"- end+ assert class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class+ refute class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class- test "pageview slider changes selected volume and prices shown", %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)-- doc = set_slider(lv, "100k")- assert text_of_element(doc, @slider_value) == "100k"- assert text_of_element(doc, @starter_price_tag_amount) == "€190"- assert text_of_element(doc, @growth_price_tag_amount) == "€290"- assert text_of_element(doc, @business_price_tag_amount) == "€390"-- doc = set_slider(lv, "200k")- assert text_of_element(doc, @slider_value) == "200k"- assert text_of_element(doc, @starter_price_tag_amount) == "€290"- assert text_of_element(doc, @growth_price_tag_amount) == "€440"- assert text_of_element(doc, @business_price_tag_amount) == "€590"-- doc = set_slider(lv, "500k")- assert text_of_element(doc, @slider_value) == "500k"- assert text_of_element(doc, @starter_price_tag_amount) == "€490"- assert text_of_element(doc, @growth_price_tag_amount) == "€740"- assert text_of_element(doc, @business_price_tag_amount) == "€990"-- doc = set_slider(lv, "1M")- assert text_of_element(doc, @slider_value) == "1M"- assert text_of_element(doc, @starter_price_tag_amount) == "€690"- assert text_of_element(doc, @growth_price_tag_amount) == "€1,040"- assert text_of_element(doc, @business_price_tag_amount) == "€1,390"-- doc = set_slider(lv, "2M")- assert text_of_element(doc, @slider_value) == "2M"- assert text_of_element(doc, @starter_price_tag_amount) == "€890"- assert text_of_element(doc, @growth_price_tag_amount) == "€1,340"- assert text_of_element(doc, @business_price_tag_amount) == "€1,790"-- doc = set_slider(lv, "5M")- assert text_of_element(doc, @slider_value) == "5M"- assert text_of_element(doc, @starter_price_tag_amount) == "€1,290"- assert text_of_element(doc, @growth_price_tag_amount) == "€1,940"- assert text_of_element(doc, @business_price_tag_amount) == "€2,590"-- doc = set_slider(lv, "10M")- assert text_of_element(doc, @slider_value) == "10M"- assert text_of_element(doc, @starter_price_tag_amount) == "€1,690"- assert text_of_element(doc, @growth_price_tag_amount) == "€2,540"- assert text_of_element(doc, @business_price_tag_amount) == "€3,390"- end+ doc = element(lv, @monthly_interval_button) |> render_click()- test "displays monthly discount for yearly plans", %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)+ refute class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class+ assert class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class+ end- doc = set_slider(lv, "200k")+ test "default pageview limit is 10k", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @slider_value) == "10k"+ assert text_of_element(doc, @starter_price_tag_amount) == "€90"+ assert text_of_element(doc, @growth_price_tag_amount) == "€140"+ assert text_of_element(doc, @business_price_tag_amount) == "€190"+ end- assert text_of_element(doc, @starter_price_tag_amount) == "€290"- assert text_of_element(doc, @starter_discount_price_tag_amount) == "€24.17"- assert text_of_element(doc, @starter_discount_price_tag_strikethrough_amount) == "€29"- assert text_of_element(doc, @starter_vat_notice) == "+ VAT if applicable"+ test "pageview slider changes selected volume and prices shown", %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)++ doc = set_slider(lv, "100k")+ assert text_of_element(doc, @slider_value) == "100k"+ assert text_of_element(doc, @starter_price_tag_amount) == "€190"+ assert text_of_element(doc, @growth_price_tag_amount) == "€290"+ assert text_of_element(doc, @business_price_tag_amount) == "€390"++ doc = set_slider(lv, "200k")+ assert text_of_element(doc, @slider_value) == "200k"+ assert text_of_element(doc, @starter_price_tag_amount) == "€290"+ assert text_of_element(doc, @growth_price_tag_amount) == "€440"+ assert text_of_element(doc, @business_price_tag_amount) == "€590"++ doc = set_slider(lv, "500k")+ assert text_of_element(doc, @slider_value) == "500k"+ assert text_of_element(doc, @starter_price_tag_amount) == "€490"+ assert text_of_element(doc, @growth_price_tag_amount) == "€740"+ assert text_of_element(doc, @business_price_tag_amount) == "€990"++ doc = set_slider(lv, "1M")+ assert text_of_element(doc, @slider_value) == "1M"+ assert text_of_element(doc, @starter_price_tag_amount) == "€690"+ assert text_of_element(doc, @growth_price_tag_amount) == "€1,040"+ assert text_of_element(doc, @business_price_tag_amount) == "€1,390"++ doc = set_slider(lv, "2M")+ assert text_of_element(doc, @slider_value) == "2M"+ assert text_of_element(doc, @starter_price_tag_amount) == "€890"+ assert text_of_element(doc, @growth_price_tag_amount) == "€1,340"+ assert text_of_element(doc, @business_price_tag_amount) == "€1,790"++ doc = set_slider(lv, "5M")+ assert text_of_element(doc, @slider_value) == "5M"+ assert text_of_element(doc, @starter_price_tag_amount) == "€1,290"+ assert text_of_element(doc, @growth_price_tag_amount) == "€1,940"+ assert text_of_element(doc, @business_price_tag_amount) == "€2,590"++ doc = set_slider(lv, "10M")+ assert text_of_element(doc, @slider_value) == "10M"+ assert text_of_element(doc, @starter_price_tag_amount) == "€1,690"+ assert text_of_element(doc, @growth_price_tag_amount) == "€2,540"+ assert text_of_element(doc, @business_price_tag_amount) == "€3,390"+ end- assert text_of_element(doc, @growth_price_tag_amount) == "€440"- assert text_of_element(doc, @growth_discount_price_tag_amount) == "€36.67"- assert text_of_element(doc, @growth_discount_price_tag_strikethrough_amount) == "€44"- assert text_of_element(doc, @growth_vat_notice) == "+ VAT if applicable"+ test "displays monthly discount for yearly plans", %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)- assert text_of_element(doc, @business_price_tag_amount) == "€590"- assert text_of_element(doc, @business_discount_price_tag_amount) == "€49.17"- assert text_of_element(doc, @business_discount_price_tag_strikethrough_amount) == "€59"- assert text_of_element(doc, @business_vat_notice) == "+ VAT if applicable"- end+ doc = set_slider(lv, "200k")- test "renders contact links for all tiers when enterprise-level volume selected",- %{- conn: conn- } do- {:ok, lv, _doc} = get_liveview(conn)-- doc = set_slider(lv, "10M+")-- assert text_of_element(doc, "#starter-custom-price") =~ "Custom"- assert text_of_element(doc, @starter_plan_box) =~ "Contact us"- assert text_of_element(doc, "#growth-custom-price") =~ "Custom"- assert text_of_element(doc, @growth_plan_box) =~ "Contact us"- assert text_of_element(doc, "#business-custom-price") =~ "Custom"- assert text_of_element(doc, @business_plan_box) =~ "Contact us"-- doc = set_slider(lv, "10M")-- refute text_of_element(doc, "#starter-custom-price") =~ "Custom"- refute text_of_element(doc, @starter_plan_box) =~ "Contact us"- refute text_of_element(doc, "#growth-custom-price") =~ "Custom"- refute text_of_element(doc, @growth_plan_box) =~ "Contact us"- refute text_of_element(doc, "#business-custom-price") =~ "Custom"- refute text_of_element(doc, @business_plan_box) =~ "Contact us"- end+ assert text_of_element(doc, @starter_price_tag_amount) == "€290"+ assert text_of_element(doc, @starter_discount_price_tag_amount) == "€24.17"+ assert text_of_element(doc, @starter_discount_price_tag_strikethrough_amount) == "€29"+ assert text_of_element(doc, @starter_vat_notice) == "+ VAT if applicable"- test "switching billing interval changes prices", %{conn: conn} do- {:ok, lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @growth_price_tag_amount) == "€440"+ assert text_of_element(doc, @growth_discount_price_tag_amount) == "€36.67"+ assert text_of_element(doc, @growth_discount_price_tag_strikethrough_amount) == "€44"+ assert text_of_element(doc, @growth_vat_notice) == "+ VAT if applicable"- assert text_of_element(doc, @starter_price_tag_amount) == "€90"- assert text_of_element(doc, @starter_price_tag_interval) == "/year"+ assert text_of_element(doc, @business_price_tag_amount) == "€590"+ assert text_of_element(doc, @business_discount_price_tag_amount) == "€49.17"+ assert text_of_element(doc, @business_discount_price_tag_strikethrough_amount) == "€59"+ assert text_of_element(doc, @business_vat_notice) == "+ VAT if applicable"+ end- assert text_of_element(doc, @growth_price_tag_amount) == "€140"- assert text_of_element(doc, @growth_price_tag_interval) == "/year"+ test "renders contact links for all tiers when enterprise-level volume selected",+ %{+ conn: conn+ } do+ {:ok, lv, _doc} = get_liveview(conn)++ doc = set_slider(lv, "10M+")++ assert text_of_element(doc, "#starter-custom-price") =~ "Custom"+ assert text_of_element(doc, @starter_plan_box) =~ "Contact us"+ assert text_of_element(doc, "#growth-custom-price") =~ "Custom"+ assert text_of_element(doc, @growth_plan_box) =~ "Contact us"+ assert text_of_element(doc, "#business-custom-price") =~ "Custom"+ assert text_of_element(doc, @business_plan_box) =~ "Contact us"++ doc = set_slider(lv, "10M")++ refute text_of_element(doc, "#starter-custom-price") =~ "Custom"+ refute text_of_element(doc, @starter_plan_box) =~ "Contact us"+ refute text_of_element(doc, "#growth-custom-price") =~ "Custom"+ refute text_of_element(doc, @growth_plan_box) =~ "Contact us"+ refute text_of_element(doc, "#business-custom-price") =~ "Custom"+ refute text_of_element(doc, @business_plan_box) =~ "Contact us"+ end- assert text_of_element(doc, @business_price_tag_amount) == "€190"- assert text_of_element(doc, @business_price_tag_interval) == "/year"+ test "switching billing interval changes prices", %{conn: conn} do+ {:ok, lv, doc} = get_liveview(conn)- doc = element(lv, @monthly_interval_button) |> render_click()+ assert text_of_element(doc, @starter_price_tag_amount) == "€90"+ assert text_of_element(doc, @starter_price_tag_interval) == "/year"- assert text_of_element(doc, @starter_price_tag_amount) == "€9"- assert text_of_element(doc, @starter_price_tag_interval) == "/month"+ assert text_of_element(doc, @growth_price_tag_amount) == "€140"+ assert text_of_element(doc, @growth_price_tag_interval) == "/year"- assert text_of_element(doc, @growth_price_tag_amount) == "€14"- assert text_of_element(doc, @growth_price_tag_interval) == "/month"+ assert text_of_element(doc, @business_price_tag_amount) == "€190"+ assert text_of_element(doc, @business_price_tag_interval) == "/year"- assert text_of_element(doc, @business_price_tag_amount) == "€19"- assert text_of_element(doc, @business_price_tag_interval) == "/month"- end+ doc = element(lv, @monthly_interval_button) |> render_click()- test "checkout buttons are 'paddle buttons' with dynamic onclick attribute", %{- conn: conn,- user: user- } do- {:ok, lv, _doc} = get_liveview(conn)- {:ok, team} = Plausible.Teams.get_by_owner(user)-- set_slider(lv, "200k")- doc = element(lv, @yearly_interval_button) |> render_click()-- assert %{- "disableLogout" => true,- "email" => user.email,- "passthrough" => "ee:true;user:#{user.id};team:#{team.id}",- "product" => @v5_growth_200k_yearly_plan_id,- "success" => Routes.billing_path(PlausibleWeb.Endpoint, :upgrade_success),- "theme" => "none"- } == get_paddle_checkout_params(find(doc, @growth_checkout_button))-- set_slider(lv, "5M")- doc = element(lv, @monthly_interval_button) |> render_click()-- assert get_paddle_checkout_params(find(doc, @starter_checkout_button))["product"] ==- @v5_starter_5m_monthly_plan_id-- assert get_paddle_checkout_params(find(doc, @business_checkout_button))["product"] ==- @v5_business_5m_monthly_plan_id- end+ assert text_of_element(doc, @starter_price_tag_amount) == "€9"+ assert text_of_element(doc, @starter_price_tag_interval) == "/month"- test "warns about losing access to a feature", %{conn: conn, site: site} do- Plausible.Props.allow(site, ["author"])+ assert text_of_element(doc, @growth_price_tag_amount) == "€14"+ assert text_of_element(doc, @growth_price_tag_interval) == "/month"- {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @business_price_tag_amount) == "€19"+ assert text_of_element(doc, @business_price_tag_interval) == "/month"+ end- assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~- "if (confirm(\"This plan does not support Custom Properties, which you have been using. By subscribing to this plan, you will not have access to this feature.\")) {Paddle.Checkout.open"- end+ test "checkout buttons are 'paddle buttons' with dynamic onclick attribute", %{+ conn: conn,+ user: user+ } do+ {:ok, lv, _doc} = get_liveview(conn)+ {:ok, team} = Plausible.Teams.get_by_owner(user)++ set_slider(lv, "200k")+ doc = element(lv, @yearly_interval_button) |> render_click()++ assert %{+ "disableLogout" => true,+ "email" => user.email,+ "passthrough" => "ee:true;user:#{user.id};team:#{team.id}",+ "product" => @v5_growth_200k_yearly_plan_id,+ "success" => Routes.billing_path(PlausibleWeb.Endpoint, :upgrade_success),+ "theme" => "none"+ } == get_paddle_checkout_params(find(doc, @growth_checkout_button))++ set_slider(lv, "5M")+ doc = element(lv, @monthly_interval_button) |> render_click()++ assert get_paddle_checkout_params(find(doc, @starter_checkout_button))["product"] ==+ @v5_starter_5m_monthly_plan_id++ assert get_paddle_checkout_params(find(doc, @business_checkout_button))["product"] ==+ @v5_business_5m_monthly_plan_id+ end- test "recommends Starter", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)+ test "warns about losing access to a feature", %{conn: conn, site: site} do+ Plausible.Props.allow(site, ["author"])- assert text_of_element(doc, @starter_highlight_pill) == "Recommended"- refute element_exists?(doc, @growth_highlight_pill)- refute element_exists?(doc, @business_highlight_pill)- end+ {:ok, _lv, doc} = get_liveview(conn)- test "recommends Growth", %{conn: conn, site: site} do- for _ <- 1..3, do: add_guest(site, role: :viewer)+ assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~+ "if (confirm(\"This plan does not support Custom Properties, which you have been using. By subscribing to this plan, you will not have access to this feature.\")) {Paddle.Checkout.open"+ end- {:ok, _lv, doc} = get_liveview(conn)+ test "recommends Starter", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)- refute element_exists?(doc, @starter_highlight_pill)- assert text_of_element(doc, @growth_highlight_pill) == "Recommended"- refute element_exists?(doc, @business_highlight_pill)- end+ assert text_of_element(doc, @starter_highlight_pill) == "Recommended"+ refute element_exists?(doc, @growth_highlight_pill)+ refute element_exists?(doc, @business_highlight_pill)+ end- test "recommends Business", %{conn: conn, site: site} do- insert(:goal, site: site, currency: :USD, event_name: "Purchase")+ test "recommends Growth", %{conn: conn, site: site} do+ for _ <- 1..3, do: add_guest(site, role: :viewer)- {:ok, _lv, doc} = get_liveview(conn)+ {:ok, _lv, doc} = get_liveview(conn)- refute element_exists?(doc, @starter_highlight_pill)- assert text_of_element(doc, @business_highlight_pill) == "Recommended"- refute element_exists?(doc, @growth_highlight_pill)- end+ refute element_exists?(doc, @starter_highlight_pill)+ assert text_of_element(doc, @growth_highlight_pill) == "Recommended"+ refute element_exists?(doc, @business_highlight_pill)+ end- test "recommends Business when pending ownership site used a premium feature", %{- conn: conn,- user: user- } do- previous_owner = insert(:user)- site = new_site(owner: previous_owner)+ test "recommends Business", %{conn: conn, site: site} do+ insert(:goal, site: site, currency: :USD, event_name: "Purchase")- insert(:goal, site: site, currency: :USD, event_name: "Purchase")+ {:ok, _lv, doc} = get_liveview(conn)- invite_transfer(site, user, inviter: previous_owner)+ refute element_exists?(doc, @starter_highlight_pill)+ assert text_of_element(doc, @business_highlight_pill) == "Recommended"+ refute element_exists?(doc, @growth_highlight_pill)+ end- {:ok, _lv, doc} = get_liveview(conn)+ test "recommends Business when pending ownership site used a premium feature", %{+ conn: conn,+ user: user+ } do+ previous_owner = insert(:user)+ site = new_site(owner: previous_owner)- assert text_of_element(doc, @business_highlight_pill) == "Recommended"- refute element_exists?(doc, @growth_highlight_pill)- end+ insert(:goal, site: site, currency: :USD, event_name: "Purchase")- test "recommends Business when team member limit for Growth exceeded due to pending ownerships",- %{conn: conn, user: user} do- owned_site = new_site(owner: user)- add_guest(owned_site, role: :editor)- add_guest(owned_site, role: :editor)+ invite_transfer(site, user, inviter: previous_owner)- previous_owner = new_user()+ {:ok, _lv, doc} = get_liveview(conn)- pending_ownership_site = new_site(owner: previous_owner)- add_guest(pending_ownership_site, role: :viewer)+ assert text_of_element(doc, @business_highlight_pill) == "Recommended"+ refute element_exists?(doc, @growth_highlight_pill)+ end- invite_transfer(pending_ownership_site, user, inviter: previous_owner)+ test "recommends Business when team member limit for Growth exceeded due to pending ownerships",+ %{conn: conn, user: user} do+ owned_site = new_site(owner: user)+ add_guest(owned_site, role: :editor)+ add_guest(owned_site, role: :editor)- {:ok, _lv, doc} = get_liveview(conn)+ previous_owner = new_user()- assert text_of_element(doc, @business_highlight_pill) == "Recommended"- refute element_exists?(doc, @growth_highlight_pill)- end+ pending_ownership_site = new_site(owner: previous_owner)+ add_guest(pending_ownership_site, role: :viewer)- test "recommends Business when Growth site limit exceeded due to a pending ownership", %{- conn: conn,- user: user- } do- for _ <- 1..2, do: new_site(owner: user)- assert user |> team_of() |> Plausible.Teams.Billing.site_usage() == 3+ invite_transfer(pending_ownership_site, user, inviter: previous_owner)- another_user = new_user()- pending_ownership_site = new_site(owner: another_user)+ {:ok, _lv, doc} = get_liveview(conn)- invite_transfer(pending_ownership_site, user, inviter: another_user)+ assert text_of_element(doc, @business_highlight_pill) == "Recommended"+ refute element_exists?(doc, @growth_highlight_pill)+ end- {:ok, _lv, doc} = get_liveview(conn)+ test "recommends Business when Growth site limit exceeded due to a pending ownership", %{+ conn: conn,+ user: user+ } do+ for _ <- 1..2, do: new_site(owner: user)+ assert user |> team_of() |> Plausible.Teams.Billing.site_usage() == 3- assert text_of_element(doc, @business_highlight_pill) == "Recommended"- refute element_exists?(doc, @growth_highlight_pill)- end+ another_user = new_user()+ pending_ownership_site = new_site(owner: another_user)- @tag :slow- test "allows upgrade to a 100k plan with a pageview allowance margin of 0.15 when trial is active",- %{conn: conn, site: site} do- generate_usage_for(site, 115_000)+ invite_transfer(pending_ownership_site, user, inviter: another_user)- {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "100k")+ {:ok, _lv, doc} = get_liveview(conn)- refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"- refute element_exists?(doc, @growth_plan_tooltip)+ assert text_of_element(doc, @business_highlight_pill) == "Recommended"+ refute element_exists?(doc, @growth_highlight_pill)+ end- generate_usage_for(site, 1)+ @tag :slow+ test "allows upgrade to a 100k plan with a pageview allowance margin of 0.15 when trial is active",+ %{conn: conn, site: site, user: user} do+ {:ok, team} = Plausible.Teams.get_or_create(user)- {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "100k")+ new_trial_expiry_date =+ Plausible.Teams.Billing.starter_tier_launch() |> Date.shift(day: 31)- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ # NOTE: This is temporary, making sure that the trial is treated as active,+ # but at the same time, ineligible for seeing the old upgrade page.+ Ecto.Changeset.change(team, %{trial_expiry_date: new_trial_expiry_date})+ |> Repo.update!()- assert text_of_element(doc, @growth_plan_tooltip) ==- "Your usage exceeds the following limit(s): Monthly pageview limit"- end+ generate_usage_for(site, 115_000)- test "allows upgrade to a 10k plan with a pageview allowance margin of 0.3 when trial ended 10 days ago",- %{conn: conn, site: site, user: user} do- user- |> team_of()- |> Ecto.Changeset.change(trial_expiry_date: Date.shift(Date.utc_today(), day: -10))- |> Repo.update!()+ {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, "100k")- generate_usage_for(site, 13_000)+ refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ refute element_exists?(doc, @growth_plan_tooltip)- {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "10k")+ generate_usage_for(site, 1)- refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, "100k")- generate_usage_for(site, 1)+ assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"- {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "10k")+ assert text_of_element(doc, @growth_plan_tooltip) ==+ "Your usage exceeds the following limit(s): Monthly pageview limit"+ end- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"- end+ test "allows upgrade to a 10k plan with a pageview allowance margin of 0.3 when trial ended 10 days ago",+ %{conn: conn, site: site, user: user} do+ team =+ user+ |> team_of()+ |> Ecto.Changeset.change(trial_expiry_date: Date.shift(Date.utc_today(), day: -10))+ |> Repo.update!()- test "pageview allowance margin on upgrade is 0.1 when trial ended more than 10 days ago", %{- conn: conn,- site: site,- user: user- } do- user- |> team_of()- |> Ecto.Changeset.change(trial_expiry_date: Date.shift(Date.utc_today(), day: -11))- |> Repo.update!()+ generate_usage_for(site, 13_000)- generate_usage_for(site, 11_000)+ {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, "10k")- {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "10k")+ # NOTE: drop the else clause once Starter tier is live for a trial that ended recently+ if Plausible.Teams.Billing.show_new_upgrade_page?(team) do+ refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ else+ refute element_exists?(doc, @starter_plan_box)+ end- refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"- generate_usage_for(site, 1)+ generate_usage_for(site, 1)- {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "10k")+ {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, "10k")- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"- end- end+ # NOTE: drop the else clause once Starter tier is live for a trial that ended recently+ if Plausible.Teams.Billing.show_new_upgrade_page?(team) do+ refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ else+ refute element_exists?(doc, @starter_plan_box)+ end- describe "for a user with an active v5 growth subscription plan" do- setup [:create_user, :create_site, :log_in, :subscribe_v5_growth]+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ end- test "displays basic page content", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)+ test "pageview allowance margin on upgrade is 0.1 when trial ended more than 10 days ago",+ %{+ conn: conn,+ site: site,+ user: user+ } do+ user+ |> team_of()+ |> Ecto.Changeset.change(trial_expiry_date: Date.shift(Date.utc_today(), day: -30))+ |> Repo.update!()- assert doc =~ "Change your subscription plan"- assert doc =~ "Any other questions?"- assert doc =~ "What happens if I go over my monthly pageview limit?"- end+ generate_usage_for(site, 11_000)- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])- end+ {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, "10k")- test "displays plan benefits", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)-- starter_box = text_of_element(doc, @starter_plan_box)- growth_box = text_of_element(doc, @growth_plan_box)- business_box = text_of_element(doc, @business_plan_box)- enterprise_box = text_of_element(doc, @enterprise_plan_box)-- assert starter_box =~ "Intuitive, fast and privacy-friendly dashboard"- assert starter_box =~ "Email/Slack reports"- assert starter_box =~ "Google Analytics import"- assert starter_box =~ "Goals and custom events"- assert starter_box =~ "One site"- assert starter_box =~ "3 years of data retention"-- assert growth_box =~ "Up to 3 team members"- assert growth_box =~ "Up to 3 sites"- assert growth_box =~ "Team Management"- assert growth_box =~ "Shared Links"- assert growth_box =~ "Shared Segments"-- assert business_box =~ "Everything in Growth"- assert business_box =~ "Up to 10 team members"- assert business_box =~ "Up to 10 sites"- assert business_box =~ "Stats API (600 requests per hour)"- assert business_box =~ "Looker Studio Connector"- assert business_box =~ "Custom Properties"- assert business_box =~ "Funnels"- assert business_box =~ "Ecommerce revenue attribution"- assert business_box =~ "Priority support"- assert business_box =~ "5 years of data retention"-- refute business_box =~ "Goals and custom events"-- assert enterprise_box =~ "Everything in Business"- assert enterprise_box =~ "10+ team members"- assert enterprise_box =~ "50+ sites"- assert enterprise_box =~ "600+ Stats API requests per hour"- assert enterprise_box =~ "Sites API access for"- assert enterprise_box =~ "Technical onboarding"- assert enterprise_box =~ "5+ years of data retention"-- assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~- "https://plausible.io/white-label-web-analytics"- end+ refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"- test "displays usage in the last cycle", %{conn: conn, site: site} do- yesterday = NaiveDateTime.utc_now() |> NaiveDateTime.add(-1, :day)+ generate_usage_for(site, 1)- populate_stats(site, [- build(:pageview, timestamp: yesterday),- build(:pageview, timestamp: yesterday)- ])+ {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, "10k")- {:ok, _lv, doc} = get_liveview(conn)- assert doc =~ "You have used"- assert doc =~ "<b>2</b>"- assert doc =~ "billable pageviews in the last billing cycle"+ assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ endend- test "renders notice about pending ownerships and counts their usage", %{- conn: conn,- user: user,- site: site- } do- yesterday = NaiveDateTime.utc_now() |> NaiveDateTime.add(-1, :day)+ describe "for a user with an active v5 growth subscription plan" do+ setup [:create_user, :create_site, :log_in, :subscribe_v5_growth]- populate_stats(site, [- build(:pageview, timestamp: yesterday)- ])+ test "displays basic page content", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)- another_user = new_user()+ assert doc =~ "Change your subscription plan"+ assert doc =~ "Any other questions?"+ assert doc =~ "What happens if I go over my monthly pageview limit?"+ end- pending_site = new_site(owner: another_user)- add_guest(pending_site, role: :editor)- add_guest(pending_site, role: :viewer)- add_guest(pending_site, role: :viewer)+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- populate_stats(pending_site, [- build(:pageview, timestamp: yesterday)- ])+ test "displays plan benefits", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)++ starter_box = text_of_element(doc, @starter_plan_box)+ growth_box = text_of_element(doc, @growth_plan_box)+ business_box = text_of_element(doc, @business_plan_box)+ enterprise_box = text_of_element(doc, @enterprise_plan_box)++ assert starter_box =~ "Intuitive, fast and privacy-friendly dashboard"+ assert starter_box =~ "Email/Slack reports"+ assert starter_box =~ "Google Analytics import"+ assert starter_box =~ "Goals and custom events"+ assert starter_box =~ "One site"+ assert starter_box =~ "3 years of data retention"++ assert growth_box =~ "Up to 3 team members"+ assert growth_box =~ "Up to 3 sites"+ assert growth_box =~ "Team Management"+ assert growth_box =~ "Shared Links"+ assert growth_box =~ "Shared Segments"++ assert business_box =~ "Everything in Growth"+ assert business_box =~ "Up to 10 team members"+ assert business_box =~ "Up to 10 sites"+ assert business_box =~ "Stats API (600 requests per hour)"+ assert business_box =~ "Looker Studio Connector"+ assert business_box =~ "Custom Properties"+ assert business_box =~ "Funnels"+ assert business_box =~ "Ecommerce revenue attribution"+ assert business_box =~ "5 years of data retention"++ refute business_box =~ "Goals and custom events"++ assert enterprise_box =~ "Everything in Business"+ assert enterprise_box =~ "10+ team members"+ assert enterprise_box =~ "10+ sites"+ assert enterprise_box =~ "600+ Stats API requests per hour"+ assert enterprise_box =~ "Sites API access for"+ assert enterprise_box =~ "Technical onboarding"+ assert enterprise_box =~ "Priority support"+ assert enterprise_box =~ "5+ years of data retention"++ assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~+ "https://plausible.io/white-label-web-analytics"+ end- invite_transfer(pending_site, user, inviter: another_user)+ test "displays usage in the last cycle", %{conn: conn, site: site} do+ yesterday = NaiveDateTime.utc_now() |> NaiveDateTime.add(-1, :day)- {:ok, _lv, doc} = get_liveview(conn)+ populate_stats(site, [+ build(:pageview, timestamp: yesterday),+ build(:pageview, timestamp: yesterday)+ ])- check_notice_titles(doc, [Billing.pending_site_ownerships_notice_title()])- assert doc =~ "Your account has been invited to become the owner of a site"+ {:ok, _lv, doc} = get_liveview(conn)+ assert doc =~ "You have used"+ assert doc =~ "<b>2</b>"+ assert doc =~ "billable pageviews in the last billing cycle"+ end- assert text_of_element(doc, @starter_plan_tooltip) =~- "Your usage exceeds the following limit(s):"+ test "renders notice about pending ownerships and counts their usage", %{+ conn: conn,+ user: user,+ site: site+ } do+ yesterday = NaiveDateTime.utc_now() |> NaiveDateTime.add(-1, :day)- assert text_of_element(doc, @starter_plan_tooltip) =~- "Team member limit"+ populate_stats(site, [+ build(:pageview, timestamp: yesterday)+ ])- assert text_of_element(doc, @starter_plan_tooltip) =~- "Site limit"+ another_user = new_user()- assert text_of_element(doc, @growth_plan_tooltip) ==- "Your usage exceeds the following limit(s): Team member limit"+ pending_site = new_site(owner: another_user)+ add_guest(pending_site, role: :editor)+ add_guest(pending_site, role: :viewer)+ add_guest(pending_site, role: :viewer)- assert doc =~ "<b>2</b>"- assert doc =~ "billable pageviews in the last billing cycle"- end+ populate_stats(pending_site, [+ build(:pageview, timestamp: yesterday)+ ])- test "warns about losing access to a feature used by a pending ownership site and recommends business tier",- %{- conn: conn,- user: user- } do- another_user = new_user()- pending_site = new_site(owner: another_user)+ invite_transfer(pending_site, user, inviter: another_user)- Plausible.Props.allow(pending_site, ["author"])+ {:ok, _lv, doc} = get_liveview(conn)- invite_transfer(pending_site, user, inviter: another_user)+ check_notice_titles(doc, [Billing.pending_site_ownerships_notice_title()])+ assert doc =~ "Your account has been invited to become the owner of a site"- {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @starter_plan_tooltip) =~+ "Your usage exceeds the following limit(s):"- assert doc =~ "Your account has been invited to become the owner of a site"+ assert text_of_element(doc, @starter_plan_tooltip) =~+ "Team member limit"- assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~- "if (confirm(\"This plan does not support Custom Properties, which you have been using. By subscribing to this plan, you will not have access to this feature.\")) {window.location ="+ assert text_of_element(doc, @starter_plan_tooltip) =~+ "Site limit"- assert text_of_element(doc, @business_highlight_pill) == "Recommended"- refute element_exists?(doc, @growth_highlight_pill)- end+ assert text_of_element(doc, @growth_plan_tooltip) ==+ "Your usage exceeds the following limit(s): Team member limit"- test "gets default selected interval from current subscription plan", %{- conn: conn,- user: user- } do- {:ok, _lv, doc} = get_liveview(conn)- assert class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class+ assert doc =~ "<b>2</b>"+ assert doc =~ "billable pageviews in the last billing cycle"+ end- subscribe_to_plan(user, @v4_growth_10k_monthly_plan_id)+ test "warns about losing access to a feature used by a pending ownership site and recommends business tier",+ %{+ conn: conn,+ user: user+ } do+ another_user = new_user()+ pending_site = new_site(owner: another_user)- {:ok, _lv, doc} = get_liveview(conn)- assert class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class- end+ Plausible.Props.allow(pending_site, ["author"])- test "sets pageview slider according to last cycle usage", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @slider_value) == "10k"- end+ invite_transfer(pending_site, user, inviter: another_user)- test "pageview slider changes selected volume", %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)+ {:ok, _lv, doc} = get_liveview(conn)- doc = set_slider(lv, "100k")- assert text_of_element(doc, @slider_value) == "100k"+ assert doc =~ "Your account has been invited to become the owner of a site"- doc = set_slider(lv, "10k")- assert text_of_element(doc, @slider_value) == "10k"- end+ assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~+ "if (confirm(\"This plan does not support Custom Properties, which you have been using. By subscribing to this plan, you will not have access to this feature.\")) {window.location ="- test "makes it clear that the user is currently on a growth tier", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @business_highlight_pill) == "Recommended"+ refute element_exists?(doc, @growth_highlight_pill)+ end- class = class_of_element(doc, @growth_plan_box)+ test "gets default selected interval from current subscription plan", %{+ conn: conn,+ user: user+ } do+ {:ok, _lv, doc} = get_liveview(conn)+ assert class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class- assert class =~ "ring-2"- assert class =~ "ring-indigo-600"- assert text_of_element(doc, @growth_highlight_pill) == "Current"- end+ subscribe_to_plan(user, @v4_growth_10k_monthly_plan_id)- test "checkout button text and click-disabling CSS classes are dynamic", %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)+ {:ok, _lv, doc} = get_liveview(conn)+ assert class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class+ end- doc = set_slider(lv, "200k")+ test "sets pageview slider according to last cycle usage", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @slider_value) == "10k"+ end- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Currently on this plan"- assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"+ test "pageview slider changes selected volume", %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"+ doc = set_slider(lv, "100k")+ assert text_of_element(doc, @slider_value) == "100k"- doc = element(lv, @monthly_interval_button) |> render_click()+ doc = set_slider(lv, "10k")+ assert text_of_element(doc, @slider_value) == "10k"+ end- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Change billing interval"- assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"+ test "makes it clear that the user is currently on a growth tier", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)- doc = set_slider(lv, "1M")+ class = class_of_element(doc, @growth_plan_box)- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Upgrade"- assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"+ assert class =~ "ring-2"+ assert class =~ "ring-indigo-600"+ assert text_of_element(doc, @growth_highlight_pill) == "Current"+ end- doc = set_slider(lv, "100k")+ test "checkout button text and click-disabling CSS classes are dynamic", %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Downgrade"- assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"- end+ doc = set_slider(lv, "200k")- test "checkout buttons are dynamic links to /billing/change-plan/preview/<plan_id>", %{- conn: conn- } do- {:ok, lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Currently on this plan"+ assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"- growth_checkout_button = find(doc, @growth_checkout_button)+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"- assert text_of_attr(growth_checkout_button, "onclick") =~- "if (true) {window.location = '#{Routes.billing_path(conn, :change_plan_preview, @v5_growth_10k_yearly_plan_id)}'}"+ doc = element(lv, @monthly_interval_button) |> render_click()- set_slider(lv, "5M")- doc = element(lv, @monthly_interval_button) |> render_click()+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Change billing interval"+ assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"- starter_checkout_button = find(doc, @starter_checkout_button)+ doc = set_slider(lv, "1M")- assert text_of_attr(starter_checkout_button, "onclick") =~- "if (true) {window.location = '#{Routes.billing_path(conn, :change_plan_preview, @v5_starter_5m_monthly_plan_id)}'}"+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Upgrade"+ assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"- business_checkout_button = find(doc, @business_checkout_button)+ doc = set_slider(lv, "100k")- assert text_of_attr(business_checkout_button, "onclick") =~- "if (true) {window.location = '#{Routes.billing_path(conn, :change_plan_preview, @v5_business_5m_monthly_plan_id)}'}"- end- end+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Downgrade"+ assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"+ end- describe "for a user with an active v4 business subscription plan" do- setup [:create_user, :create_site, :log_in, :subscribe_v4_business]+ test "checkout buttons are dynamic links to /billing/change-plan/preview/<plan_id>", %{+ conn: conn+ } do+ {:ok, lv, doc} = get_liveview(conn)- test "sets pageview slider according to last cycle usage", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @slider_value) == "10k"- end+ growth_checkout_button = find(doc, @growth_checkout_button)- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])- end+ assert text_of_attr(growth_checkout_button, "onclick") =~+ "if (true) {window.location = '#{Routes.billing_path(conn, :change_plan_preview, @v5_growth_10k_yearly_plan_id)}'}"- test "highlights Business box as the 'Current' tier", %{- conn: conn,- site: site- } do- insert(:goal, site: site, currency: :USD, event_name: "Purchase")+ set_slider(lv, "5M")+ doc = element(lv, @monthly_interval_button) |> render_click()- {:ok, _lv, doc} = get_liveview(conn)+ starter_checkout_button = find(doc, @starter_checkout_button)- class = class_of_element(doc, @business_plan_box)+ assert text_of_attr(starter_checkout_button, "onclick") =~+ "if (true) {window.location = '#{Routes.billing_path(conn, :change_plan_preview, @v5_starter_5m_monthly_plan_id)}'}"- assert class =~ "ring-2"- assert class =~ "ring-indigo-600"- assert text_of_element(doc, @business_highlight_pill) == "Current"+ business_checkout_button = find(doc, @business_checkout_button)- refute element_exists?(doc, @starter_highlight_pill)- refute element_exists?(doc, @growth_highlight_pill)+ assert text_of_attr(business_checkout_button, "onclick") =~+ "if (true) {window.location = '#{Routes.billing_path(conn, :change_plan_preview, @v5_business_5m_monthly_plan_id)}'}"+ endend- test "recommends Enterprise when site limit exceeds Business tier due to pending ownerships",- %{- conn: conn,- user: user- } do- team = team_of(user)+ describe "for a user with an active v4 business subscription plan" do+ setup [:create_user, :create_site, :log_in, :subscribe_v4_business]- for _ <- 1..49 do- new_site(owner: user)+ test "sets pageview slider according to last cycle usage", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @slider_value) == "10k"end- assert 50 = Plausible.Teams.Billing.quota_usage(team).sites+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- another_user = new_user()- pending_ownership_site = new_site(owner: another_user)+ test "highlights Business box as the 'Current' tier", %{+ conn: conn,+ site: site+ } do+ insert(:goal, site: site, currency: :USD, event_name: "Purchase")- invite_transfer(pending_ownership_site, user, inviter: another_user)+ {:ok, _lv, doc} = get_liveview(conn)- {:ok, _lv, doc} = get_liveview(conn)+ class = class_of_element(doc, @business_plan_box)- assert text_of_element(doc, @enterprise_highlight_pill) == "Recommended"- refute element_exists?(doc, @starter_highlight_pill)- refute element_exists?(doc, @business_highlight_pill)- refute element_exists?(doc, @growth_highlight_pill)- end+ assert class =~ "ring-2"+ assert class =~ "ring-indigo-600"+ assert text_of_element(doc, @business_highlight_pill) == "Current"- test "checkout button text and click-disabling CSS classes are dynamic", %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)+ refute element_exists?(doc, @starter_highlight_pill)+ refute element_exists?(doc, @growth_highlight_pill)+ end- doc = set_slider(lv, "5M")+ test "recommends Enterprise when site limit exceeds Business tier due to pending ownerships",+ %{+ conn: conn,+ user: user+ } do+ team = team_of(user)- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"- assert text_of_element(doc, @business_checkout_button) == "Currently on this plan"+ for _ <- 1..49 do+ new_site(owner: user)+ end- assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none bg-gray-400"+ assert 50 = Plausible.Teams.Billing.quota_usage(team).sites- doc = element(lv, @yearly_interval_button) |> render_click()+ another_user = new_user()+ pending_ownership_site = new_site(owner: another_user)- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"- assert text_of_element(doc, @business_checkout_button) == "Change billing interval"+ invite_transfer(pending_ownership_site, user, inviter: another_user)- doc = set_slider(lv, "10M")+ {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"- assert text_of_element(doc, @business_checkout_button) == "Upgrade"+ assert text_of_element(doc, @enterprise_highlight_pill) == "Recommended"+ refute element_exists?(doc, @starter_highlight_pill)+ refute element_exists?(doc, @business_highlight_pill)+ refute element_exists?(doc, @growth_highlight_pill)+ end- doc = set_slider(lv, "100k")+ test "checkout button text and click-disabling CSS classes are dynamic", %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)- assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"- assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"- assert text_of_element(doc, @business_checkout_button) == "Downgrade"- end+ doc = set_slider(lv, "5M")- test "checkout is disabled when team member usage exceeds rendered plan limit", %{- conn: conn,- site: site- } do- for _ <- 1..4, do: add_guest(site, role: :viewer)+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"+ assert text_of_element(doc, @business_checkout_button) == "Currently on this plan"- {:ok, _lv, doc} = get_liveview(conn)+ assert class_of_element(doc, @business_checkout_button) =~+ "pointer-events-none bg-gray-400"- assert text_of_element(doc, @starter_plan_box) =~ "Your usage exceeds this plan"- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ doc = element(lv, @yearly_interval_button) |> render_click()- assert text_of_element(doc, @starter_plan_tooltip) ==- "Your usage exceeds the following limit(s): Team member limit"+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"+ assert text_of_element(doc, @business_checkout_button) == "Change billing interval"- assert text_of_element(doc, @growth_plan_box) =~ "Your usage exceeds this plan"- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ doc = set_slider(lv, "10M")- assert text_of_element(doc, @growth_plan_tooltip) ==- "Your usage exceeds the following limit(s): Team member limit"- end+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"+ assert text_of_element(doc, @business_checkout_button) == "Upgrade"- test "checkout is disabled when sites usage exceeds rendered plan limit", %{- conn: conn,- user: user- } do- for _ <- 1..11, do: new_site(owner: user)+ doc = set_slider(lv, "100k")- {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @starter_checkout_button) == "Downgrade to Starter"+ assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"+ assert text_of_element(doc, @business_checkout_button) == "Downgrade"+ end- assert text_of_element(doc, @starter_plan_box) =~ "Your usage exceeds this plan"- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ test "checkout is disabled when team member usage exceeds rendered plan limit", %{+ conn: conn,+ site: site+ } do+ for _ <- 1..4, do: add_guest(site, role: :viewer)- assert text_of_element(doc, @starter_plan_tooltip) ==- "Your usage exceeds the following limit(s): Site limit"+ {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @growth_plan_box) =~ "Your usage exceeds this plan"- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ assert text_of_element(doc, @starter_plan_box) =~ "Your usage exceeds this plan"+ assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- assert text_of_element(doc, @growth_plan_tooltip) ==- "Your usage exceeds the following limit(s): Site limit"- end+ assert text_of_element(doc, @starter_plan_tooltip) ==+ "Your usage exceeds the following limit(s): Team member limit"- test "when more than one limit is exceeded, the tooltip enumerates them", %{- conn: conn,- user: user- } do- for _ <- 1..11, do: new_site(owner: user)+ assert text_of_element(doc, @growth_plan_box) =~ "Your usage exceeds this plan"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- site = new_site(owner: user)- for _ <- 1..4, do: add_guest(site, role: :viewer)+ assert text_of_element(doc, @growth_plan_tooltip) ==+ "Your usage exceeds the following limit(s): Team member limit"+ end- {:ok, _lv, doc} = get_liveview(conn)+ test "checkout is disabled when sites usage exceeds rendered plan limit", %{+ conn: conn,+ user: user+ } do+ for _ <- 1..11, do: new_site(owner: user)- assert text_of_element(doc, @starter_plan_tooltip) =~ "Team member limit"- assert text_of_element(doc, @starter_plan_tooltip) =~ "Site limit"+ {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @growth_plan_tooltip) =~ "Team member limit"- assert text_of_element(doc, @growth_plan_tooltip) =~ "Site limit"- end+ assert text_of_element(doc, @starter_plan_box) =~ "Your usage exceeds this plan"+ assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"++ assert text_of_element(doc, @starter_plan_tooltip) ==+ "Your usage exceeds the following limit(s): Site limit"- test "checkout is not disabled when pageview usage exceeded but next upgrade allowed by override",- %{- conn: conn,- user: user,- site: site- } do- now = NaiveDateTime.utc_now()+ assert text_of_element(doc, @growth_plan_box) =~ "Your usage exceeds this plan"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- generate_usage_for(site, 11_000, Timex.shift(now, days: -5))- generate_usage_for(site, 11_000, Timex.shift(now, days: -35))+ assert text_of_element(doc, @growth_plan_tooltip) ==+ "Your usage exceeds the following limit(s): Site limit"+ end- user- |> team_of()- |> Ecto.Changeset.change(allow_next_upgrade_override: true)- |> Plausible.Repo.update!()+ test "when more than one limit is exceeded, the tooltip enumerates them", %{+ conn: conn,+ user: user+ } do+ for _ <- 1..11, do: new_site(owner: user)- {:ok, lv, _doc} = get_liveview(conn)+ site = new_site(owner: user)+ for _ <- 1..4, do: add_guest(site, role: :viewer)- doc = set_slider(lv, "10k")+ {:ok, _lv, doc} = get_liveview(conn)- refute text_of_element(doc, @growth_plan_box) =~ "Your usage exceeds this plan"- refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- end+ assert text_of_element(doc, @starter_plan_tooltip) =~ "Team member limit"+ assert text_of_element(doc, @starter_plan_tooltip) =~ "Site limit"- test "warns about losing access to a feature", %{conn: conn, user: user, site: site} do- Plausible.Props.allow(site, ["author"])- insert(:goal, currency: :USD, site: site, event_name: "Purchase")- insert(:api_key, user: user)+ assert text_of_element(doc, @growth_plan_tooltip) =~ "Team member limit"+ assert text_of_element(doc, @growth_plan_tooltip) =~ "Site limit"+ end- {:ok, _lv, doc} = get_liveview(conn)+ test "checkout is not disabled when pageview usage exceeded but next upgrade allowed by override",+ %{+ conn: conn,+ user: user,+ site: site+ } do+ now = NaiveDateTime.utc_now()- assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~- "if (confirm(\"This plan does not support Custom Properties, Revenue Goals and Stats API, which you have been using. By subscribing to this plan, you will not have access to these features.\")) {window.location = "- end- end+ generate_usage_for(site, 11_000, Timex.shift(now, days: -5))+ generate_usage_for(site, 11_000, Timex.shift(now, days: -35))- describe "for a user with a v3 business (unlimited team members) subscription plan" do- setup [:create_user, :create_site, :log_in]+ user+ |> team_of()+ |> Ecto.Changeset.change(allow_next_upgrade_override: true)+ |> Plausible.Repo.update!()- setup %{user: user} = context do- create_subscription_for(user, paddle_plan_id: @v3_business_10k_monthly_plan_id)- {:ok, context}- end+ {:ok, lv, _doc} = get_liveview(conn)- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])- end+ doc = set_slider(lv, "10k")- test "displays plan benefits", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)-- starter_box = text_of_element(doc, @starter_plan_box)- growth_box = text_of_element(doc, @growth_plan_box)- business_box = text_of_element(doc, @business_plan_box)- enterprise_box = text_of_element(doc, @enterprise_plan_box)-- assert starter_box =~ "Intuitive, fast and privacy-friendly dashboard"- assert starter_box =~ "Email/Slack reports"- assert starter_box =~ "Google Analytics import"- assert starter_box =~ "Goals and custom events"- assert starter_box =~ "One site"- assert starter_box =~ "3 years of data retention"-- assert growth_box =~ "Up to 3 team members"- assert growth_box =~ "Up to 3 sites"- assert growth_box =~ "Team Management"- assert growth_box =~ "Shared Links"- assert growth_box =~ "Shared Segments"-- assert business_box =~ "Everything in Growth"- assert business_box =~ "Unlimited team members"- assert business_box =~ "Up to 50 sites"- assert business_box =~ "Stats API (600 requests per hour)"- assert business_box =~ "Looker Studio Connector"- assert business_box =~ "Custom Properties"- assert business_box =~ "Funnels"- assert business_box =~ "Ecommerce revenue attribution"- assert business_box =~ "Priority support"-- refute business_box =~ "Goals and custom events"-- assert enterprise_box =~ "Everything in Business"- assert enterprise_box =~ "50+ sites"- assert enterprise_box =~ "600+ Stats API requests per hour"- assert enterprise_box =~ "Sites API access for"- assert enterprise_box =~ "Technical onboarding"-- refute enterprise_box =~ "team members"-- assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~- "https://plausible.io/white-label-web-analytics"- end- end+ refute text_of_element(doc, @growth_plan_box) =~ "Your usage exceeds this plan"+ refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ end++ test "warns about losing access to a feature", %{conn: conn, user: user, site: site} do+ Plausible.Props.allow(site, ["author"])+ insert(:goal, currency: :USD, site: site, event_name: "Purchase")+ insert(:api_key, user: user)- describe "for a user with a past_due subscription" do- setup [:create_user, :create_site, :log_in, :create_past_due_subscription]+ {:ok, _lv, doc} = get_liveview(conn)- test "renders failed payment notice and link to update billing details", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [Billing.subscription_past_due_notice_title()])- assert doc =~ "There was a problem with your latest payment"- assert doc =~ "https://update.billing.details"+ assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~+ "if (confirm(\"This plan does not support Custom Properties, Revenue Goals and Stats API, which you have been using. By subscribing to this plan, you will not have access to these features.\")) {window.location = "+ endend- test "checkout buttons are disabled + notice about billing details (unless plan owned already)",- %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)+ describe "for a user with a v3 business (unlimited team members) subscription plan" do+ setup [:create_user, :create_site, :log_in]++ setup %{user: user} = context do+ create_subscription_for(user, paddle_plan_id: @v3_business_10k_monthly_plan_id)+ {:ok, context}+ end++ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- doc = set_slider(lv, "200k")+ test "displays plan benefits", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)++ starter_box = text_of_element(doc, @starter_plan_box)+ growth_box = text_of_element(doc, @growth_plan_box)+ business_box = text_of_element(doc, @business_plan_box)+ enterprise_box = text_of_element(doc, @enterprise_plan_box)++ assert starter_box =~ "Intuitive, fast and privacy-friendly dashboard"+ assert starter_box =~ "Email/Slack reports"+ assert starter_box =~ "Google Analytics import"+ assert starter_box =~ "Goals and custom events"+ assert starter_box =~ "One site"+ assert starter_box =~ "3 years of data retention"++ assert growth_box =~ "Up to 3 team members"+ assert growth_box =~ "Up to 3 sites"+ assert growth_box =~ "Team Management"+ assert growth_box =~ "Shared Links"+ assert growth_box =~ "Shared Segments"++ assert business_box =~ "Everything in Growth"+ assert business_box =~ "Unlimited team members"+ assert business_box =~ "Up to 50 sites"+ assert business_box =~ "Stats API (600 requests per hour)"+ assert business_box =~ "Looker Studio Connector"+ assert business_box =~ "Custom Properties"+ assert business_box =~ "Funnels"+ assert business_box =~ "Ecommerce revenue attribution"++ refute business_box =~ "Goals and custom events"++ assert enterprise_box =~ "Everything in Business"+ assert enterprise_box =~ "50+ sites"+ assert enterprise_box =~ "600+ Stats API requests per hour"+ assert enterprise_box =~ "Sites API access for"+ assert enterprise_box =~ "Technical onboarding"+ assert enterprise_box =~ "Priority support"++ refute enterprise_box =~ "team members"++ assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~+ "https://plausible.io/white-label-web-analytics"+ end+ end- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"- assert text_of_element(doc, @growth_checkout_button) =~ "Currently on this plan"- refute element_exists?(doc, "#{@growth_checkout_button} + div")+ describe "for a user with a past_due subscription" do+ setup [:create_user, :create_site, :log_in, :create_past_due_subscription]- assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none bg-gray-400"+ test "renders failed payment notice and link to update billing details", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.subscription_past_due_notice_title()])+ assert doc =~ "There was a problem with your latest payment"+ assert doc =~ "https://update.billing.details"+ end- assert text_of_element(doc, "#{@business_checkout_button} + div") =~- "Please update your billing details first"+ test "checkout buttons are disabled + notice about billing details (unless plan owned already)",+ %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "1M")+ doc = set_slider(lv, "200k")- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"+ assert text_of_element(doc, @growth_checkout_button) =~ "Currently on this plan"+ refute element_exists?(doc, "#{@growth_checkout_button} + div")- assert text_of_element(doc, "#{@growth_checkout_button} + div") =~- "Please update your billing details first"+ assert class_of_element(doc, @business_checkout_button) =~+ "pointer-events-none bg-gray-400"- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none bg-gray-400"+ assert text_of_element(doc, "#{@business_checkout_button} + div") =~+ "Please update your billing details first"- assert text_of_element(doc, "#{@starter_checkout_button} + div") =~- "Please update your billing details first"- end- end+ doc = set_slider(lv, "1M")- describe "for a user with a paused subscription" do- setup [:create_user, :create_site, :log_in, :create_paused_subscription]+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"- test "renders subscription paused notice and link to update billing details", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [Billing.subscription_paused_notice_title()])- assert doc =~ "Your subscription is paused due to failed payments"- assert doc =~ "https://update.billing.details"+ assert text_of_element(doc, "#{@growth_checkout_button} + div") =~+ "Please update your billing details first"+ endend- test "checkout buttons are disabled + notice about billing details when plan not owned already",- %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)+ describe "for a user with a paused v4 subscription" do+ setup [:create_user, :create_site, :log_in, :create_paused_subscription]- doc = set_slider(lv, "200k")+ test "renders subscription paused notice and link to update billing details", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.subscription_paused_notice_title()])+ assert doc =~ "Your subscription is paused due to failed payments"+ assert doc =~ "https://update.billing.details"+ end- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"- assert text_of_element(doc, @growth_checkout_button) =~ "Currently on this plan"- refute element_exists?(doc, "#{@growth_checkout_button} + div")+ test "checkout buttons are disabled + notice about billing details when plan not owned already",+ %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)- assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none bg-gray-400"+ doc = set_slider(lv, "200k")- assert text_of_element(doc, "#{@business_checkout_button} + div") =~- "Please update your billing details first"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"+ assert text_of_element(doc, @growth_checkout_button) =~ "Currently on this plan"+ refute element_exists?(doc, "#{@growth_checkout_button} + div")- doc = set_slider(lv, "1M")+ assert class_of_element(doc, @business_checkout_button) =~+ "pointer-events-none bg-gray-400"- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"+ assert text_of_element(doc, "#{@business_checkout_button} + div") =~+ "Please update your billing details first"- assert text_of_element(doc, "#{@growth_checkout_button} + div") =~- "Please update your billing details first"+ doc = set_slider(lv, "1M")- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none bg-gray-400"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"- assert text_of_element(doc, "#{@starter_checkout_button} + div") =~- "Please update your billing details first"+ assert text_of_element(doc, "#{@growth_checkout_button} + div") =~+ "Please update your billing details first"+ endend- end- describe "for a user with a cancelled, but still active subscription" do- setup [:create_user, :create_site, :log_in, :create_cancelled_subscription]+ describe "for a user with a cancelled, but still active v4 subscription" do+ setup [:create_user, :create_site, :log_in, :create_cancelled_subscription]- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])- end+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- test "checkout buttons are paddle buttons", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)+ test "checkout buttons are paddle buttons", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)- assert text_of_attr(find(doc, @starter_checkout_button), "onclick") =~- "Paddle.Checkout.open"+ assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~+ "Paddle.Checkout.open"- assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~ "Paddle.Checkout.open"+ assert text_of_attr(find(doc, @business_checkout_button), "onclick") =~+ "Paddle.Checkout.open"+ end- assert text_of_attr(find(doc, @business_checkout_button), "onclick") =~- "Paddle.Checkout.open"- end+ test "currently owned tier is highlighted", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @growth_highlight_pill) == "Current"+ end- test "currently owned tier is highlighted", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @growth_highlight_pill) == "Current"+ test "can subscribe again to the currently owned (but cancelled) plan", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ endend- test "can subscribe again to the currently owned (but cancelled) plan", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- end- end+ describe "for a user with a cancelled and expired subscription" do+ setup [:create_user, :create_site, :log_in, :create_cancelled_subscription]- describe "for a user with a cancelled and expired subscription" do- setup [:create_user, :create_site, :log_in, :create_cancelled_subscription]+ setup %{user: user} do+ user+ |> team_of()+ |> Repo.preload(:subscription)+ |> Map.fetch!(:subscription)+ |> Subscription.changeset(%{next_bill_date: Timex.shift(Timex.now(), months: -2)})+ |> Repo.update!()- setup %{user: user} do- user- |> team_of()- |> Repo.preload(:subscription)- |> Map.fetch!(:subscription)- |> Subscription.changeset(%{next_bill_date: Timex.shift(Timex.now(), months: -2)})- |> Repo.update!()+ :ok+ end- :ok- end+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])+ test "highlights recommended tier", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ assert text_of_element(doc, @starter_highlight_pill) == "Recommended"+ refute element_exists?(doc, @growth_highlight_pill)+ refute element_exists?(doc, @business_highlight_pill)+ endend- test "highlights recommended tier", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @starter_highlight_pill) == "Recommended"- refute text_of_element(doc, @growth_highlight_pill) == "Recommended"- refute text_of_element(doc, @business_highlight_pill) == "Recommended"- end- end+ describe "for a grandfathered user with a high volume plan" do+ setup [:create_user, :create_site, :log_in]- describe "for a grandfathered user with a high volume plan" do- setup [:create_user, :create_site, :log_in]+ test "does not render any global notices", %{conn: conn, user: user} do+ create_subscription_for(user, paddle_plan_id: @v1_50m_yearly_plan_id)+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- test "does not render any global notices", %{conn: conn, user: user} do- create_subscription_for(user, paddle_plan_id: @v1_50m_yearly_plan_id)- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])- end+ test "on a 50M v1 plan, Starter plans are not rendered, Growth plans are available at 20M, 50M, 50M+, and Business plans are up to 10M",+ %{conn: conn, user: user} do+ create_subscription_for(user, paddle_plan_id: @v1_50m_yearly_plan_id)- test "on a 50M v1 plan, Growth plans are available at 20M, 50M, 50M+, but Starter and Business plans are not",- %{conn: conn, user: user} do- create_subscription_for(user, paddle_plan_id: @v1_50m_yearly_plan_id)-- {:ok, lv, _doc} = get_liveview(conn)-- doc = set_slider(lv, 8)- assert text_of_element(doc, @slider_value) == "20M"- assert text_of_element(doc, @starter_plan_box) =~ "Contact us"- assert text_of_element(doc, @business_plan_box) =~ "Contact us"- assert text_of_element(doc, @growth_price_tag_amount) == "€1,800"- assert text_of_element(doc, @growth_price_tag_interval) == "/year"-- doc = set_slider(lv, 9)- assert text_of_element(doc, @slider_value) == "50M"- assert text_of_element(doc, @starter_plan_box) =~ "Contact us"- assert text_of_element(doc, @business_plan_box) =~ "Contact us"- assert text_of_element(doc, @growth_price_tag_amount) == "€2,640"- assert text_of_element(doc, @growth_price_tag_interval) == "/year"-- doc = set_slider(lv, 10)- assert text_of_element(doc, @slider_value) == "50M+"- assert text_of_element(doc, @starter_plan_box) =~ "Contact us"- assert text_of_element(doc, @business_plan_box) =~ "Contact us"- assert text_of_element(doc, @growth_plan_box) =~ "Contact us"-- doc = set_slider(lv, 7)- assert text_of_element(doc, @slider_value) == "10M"- refute text_of_element(doc, @starter_plan_box) =~ "Contact us"- refute text_of_element(doc, @business_plan_box) =~ "Contact us"- refute text_of_element(doc, @growth_plan_box) =~ "Contact us"- end+ {:ok, lv, doc} = get_liveview(conn)- test "on a 20M v2 plan, Growth tiers are available at 20M and 20M+, but not 50M",- %{conn: conn, user: user} do- create_subscription_for(user, paddle_plan_id: @v2_20m_yearly_plan_id)+ refute element_exists?(doc, @starter_plan_box)- {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, 8)+ assert text_of_element(doc, @slider_value) == "20M"+ assert text_of_element(doc, @business_plan_box) =~ "Contact us"+ assert text_of_element(doc, @growth_price_tag_amount) == "€1,800"+ assert text_of_element(doc, @growth_price_tag_interval) == "/year"- doc = set_slider(lv, 8)- assert text_of_element(doc, @slider_value) == "20M"- assert text_of_element(doc, @growth_price_tag_amount) == "€2,250"- assert text_of_element(doc, @growth_price_tag_interval) == "/year"+ doc = set_slider(lv, 9)+ assert text_of_element(doc, @slider_value) == "50M"+ assert text_of_element(doc, @business_plan_box) =~ "Contact us"+ assert text_of_element(doc, @growth_price_tag_amount) == "€2,640"+ assert text_of_element(doc, @growth_price_tag_interval) == "/year"- doc = set_slider(lv, 9)- assert text_of_element(doc, @slider_value) == "20M+"- assert text_of_element(doc, @growth_plan_box) =~ "Contact us"- end- end+ doc = set_slider(lv, 10)+ assert text_of_element(doc, @slider_value) == "50M+"+ assert text_of_element(doc, @business_plan_box) =~ "Contact us"+ assert text_of_element(doc, @growth_plan_box) =~ "Contact us"- describe "for a grandfathered user on a v1 10k plan" do- setup [:create_user, :create_site, :log_in]+ doc = set_slider(lv, 7)+ assert text_of_element(doc, @slider_value) == "10M"+ refute text_of_element(doc, @business_plan_box) =~ "Contact us"+ refute text_of_element(doc, @growth_plan_box) =~ "Contact us"+ end- setup %{user: user} = context do- create_subscription_for(user, paddle_plan_id: @v1_10k_yearly_plan_id)- {:ok, context}- end+ test "on a 20M v2 plan, Growth tiers are available at 20M and 20M+, but not 50M",+ %{conn: conn, user: user} do+ create_subscription_for(user, paddle_plan_id: @v2_20m_yearly_plan_id)- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])- end+ {:ok, lv, _doc} = get_liveview(conn)- test "v1 20M and 50M Growth plans are not available",- %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, 8)+ assert text_of_element(doc, @slider_value) == "20M"+ assert text_of_element(doc, @growth_price_tag_amount) == "€2,250"+ assert text_of_element(doc, @growth_price_tag_interval) == "/year"- doc = set_slider(lv, 8)- assert text_of_element(doc, @slider_value) == "10M+"- assert text_of_element(doc, @growth_plan_box) =~ "Contact us"+ doc = set_slider(lv, 9)+ assert text_of_element(doc, @slider_value) == "20M+"+ assert text_of_element(doc, @growth_plan_box) =~ "Contact us"+ endend- test "displays grandfathering notice in the Growth box instead of benefits", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- growth_box = text_of_element(doc, @growth_plan_box)- assert growth_box =~ "Your subscription has been grandfathered"- refute growth_box =~ "Intuitive, fast and privacy-friendly dashboard"- end+ describe "for a grandfathered user on a v1 10k plan" do+ setup [:create_user, :create_site, :log_in]- test "displays Starter, Business and Enterprise benefits", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)-- starter_box = text_of_element(doc, @starter_plan_box)- business_box = text_of_element(doc, @business_plan_box)- enterprise_box = text_of_element(doc, @enterprise_plan_box)-- assert starter_box =~ "Intuitive, fast and privacy-friendly dashboard"- assert starter_box =~ "Email/Slack reports"- assert starter_box =~ "Google Analytics import"- assert starter_box =~ "Goals and custom events"- assert starter_box =~ "One site"- assert starter_box =~ "3 years of data retention"-- assert business_box =~ "Everything in Growth"- assert business_box =~ "Funnels"- assert business_box =~ "Ecommerce revenue attribution"- assert business_box =~ "Priority support"-- refute business_box =~ "Goals and custom events"- refute business_box =~ "Unlimited team members"- refute business_box =~ "Up to 50 sites"- refute business_box =~ "Stats API (600 requests per hour)"- refute business_box =~ "Looker Studio Connector"- refute business_box =~ "Custom Properties"-- assert enterprise_box =~ "Everything in Business"- assert enterprise_box =~ "50+ sites"- assert enterprise_box =~ "600+ Stats API requests per hour"- assert enterprise_box =~ "Sites API access for"- assert enterprise_box =~ "Technical onboarding"-- assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~- "https://plausible.io/white-label-web-analytics"-- refute enterprise_box =~ "10+ team members"- refute enterprise_box =~ "Unlimited team members"- end- end+ setup %{user: user} = context do+ create_subscription_for(user, paddle_plan_id: @v1_10k_yearly_plan_id)+ {:ok, context}+ end- describe "for a user without a trial_expiry_date (invited user) who owns a site (transferred)" do- setup [:create_user, :create_site, :log_in]+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end- setup %{user: user} do- user- |> team_of()- |> Ecto.Changeset.change(trial_expiry_date: nil)- |> Repo.update!()+ test "v1 20M and 50M Growth plans are not available",+ %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)- :ok- end+ doc = set_slider(lv, 8)+ assert text_of_element(doc, @slider_value) == "10M+"+ assert text_of_element(doc, @growth_plan_box) =~ "Contact us"+ end- test "does not render any global notices", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [])+ test "displays plan benefits", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)++ refute element_exists?(doc, @starter_plan_box)+ growth_box = text_of_element(doc, @growth_plan_box)+ business_box = text_of_element(doc, @business_plan_box)+ enterprise_box = text_of_element(doc, @enterprise_plan_box)++ assert growth_box =~ "Up to 50 sites"+ assert growth_box =~ "Unlimited team members"+ assert growth_box =~ "Team Management"+ assert growth_box =~ "Saved Segments"+ assert growth_box =~ "Goals and custom events"+ assert growth_box =~ "Custom Properties"+ assert growth_box =~ "Stats API (600 requests per hour)"+ assert growth_box =~ "Looker Studio Connector"+ assert growth_box =~ "Shared Links"+ assert growth_box =~ "Embedded Dashboards"++ assert business_box =~ "Everything in Growth"+ assert business_box =~ "Funnels"+ assert business_box =~ "Ecommerce revenue attribution"++ refute business_box =~ "Goals and custom events"+ refute business_box =~ "Unlimited team members"+ refute business_box =~ "Up to 50 sites"+ refute business_box =~ "Stats API (600 requests per hour)"+ refute business_box =~ "Looker Studio Connector"+ refute business_box =~ "Custom Properties"++ assert enterprise_box =~ "Everything in Business"+ assert enterprise_box =~ "50+ sites"+ assert enterprise_box =~ "600+ Stats API requests per hour"+ assert enterprise_box =~ "Sites API access for"+ assert enterprise_box =~ "Technical onboarding"+ assert enterprise_box =~ "Priority support"++ assert text_of_attr(find(doc, "#{@enterprise_plan_box} p a"), "href") =~+ "https://plausible.io/white-label-web-analytics"++ refute enterprise_box =~ "10+ team members"+ refute enterprise_box =~ "Unlimited team members"+ endend- test "allows to upgrade", %{conn: conn} do- {:ok, lv, _doc} = get_liveview(conn)- doc = set_slider(lv, "100k")+ describe "for a user without a trial_expiry_date (invited user) who owns a site (transferred)" do+ setup [:create_user, :create_site, :log_in]- refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"- end- end+ setup %{user: user} do+ user+ |> team_of()+ |> Ecto.Changeset.change(trial_expiry_date: nil)+ |> Repo.update!()++ :ok+ end- describe "for a free_10k subscription" do- setup [:create_user, :create_site, :log_in, :subscribe_free_10k]+ test "does not render any global notices", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [])+ end++ test "allows to upgrade", %{conn: conn} do+ {:ok, lv, _doc} = get_liveview(conn)+ doc = set_slider(lv, "100k")- test "recommends starter tier", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- assert element_exists?(doc, @starter_highlight_pill)- refute element_exists?(doc, @growth_highlight_pill)- refute element_exists?(doc, @business_highlight_pill)+ refute class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ endend- test "recommends Business tier when premium features used", %{conn: conn, site: site} do- insert(:goal, currency: :USD, site: site, event_name: "Purchase")+ describe "for a free_10k subscription" do+ setup [:create_user, :create_site, :log_in, :subscribe_free_10k]- {:ok, _lv, doc} = get_liveview(conn)+ test "recommends starter tier", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ assert element_exists?(doc, @starter_highlight_pill)+ refute element_exists?(doc, @growth_highlight_pill)+ refute element_exists?(doc, @business_highlight_pill)+ end- assert text_of_element(doc, @business_plan_box) =~ "Recommended"- refute text_of_element(doc, @growth_plan_box) =~ "Recommended"- refute text_of_element(doc, @starter_plan_box) =~ "Recommended"- end+ test "recommends Business tier when premium features used", %{conn: conn, site: site} do+ insert(:goal, currency: :USD, site: site, event_name: "Purchase")++ {:ok, _lv, doc} = get_liveview(conn)- test "renders Paddle upgrade buttons", %{conn: conn, user: user} do- {:ok, lv, _doc} = get_liveview(conn)- {:ok, team} = Plausible.Teams.get_by_owner(user)-- set_slider(lv, "200k")- doc = element(lv, @yearly_interval_button) |> render_click()-- assert %{- "disableLogout" => true,- "email" => user.email,- "passthrough" => "ee:true;user:#{user.id};team:#{team.id}",- "product" => @v5_growth_200k_yearly_plan_id,- "success" => Routes.billing_path(PlausibleWeb.Endpoint, :upgrade_success),- "theme" => "none"- } == get_paddle_checkout_params(find(doc, @growth_checkout_button))+ assert text_of_element(doc, @business_plan_box) =~ "Recommended"+ refute text_of_element(doc, @growth_plan_box) =~ "Recommended"+ refute text_of_element(doc, @starter_plan_box) =~ "Recommended"+ end++ test "renders Paddle upgrade buttons", %{conn: conn, user: user} do+ {:ok, lv, _doc} = get_liveview(conn)+ {:ok, team} = Plausible.Teams.get_by_owner(user)++ set_slider(lv, "200k")+ doc = element(lv, @yearly_interval_button) |> render_click()++ assert %{+ "disableLogout" => true,+ "email" => user.email,+ "passthrough" => "ee:true;user:#{user.id};team:#{team.id}",+ "product" => @v5_growth_200k_yearly_plan_id,+ "success" => Routes.billing_path(PlausibleWeb.Endpoint, :upgrade_success),+ "theme" => "none"+ } == get_paddle_checkout_params(find(doc, @growth_checkout_button))+ endend- end- describe "for a user with no sites" do- setup [:create_user, :log_in]+ describe "for a user with no sites" do+ setup [:create_user, :log_in]++ test "does not allow to subscribe and renders notice", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)- test "does not allow to subscribe and renders notice", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.upgrade_ineligible_notice_title()])- check_notice_titles(doc, [Billing.upgrade_ineligible_notice_title()])+ assert text_of_element(doc, "#upgrade-eligible-notice") =~+ "You cannot start a subscription"- assert text_of_element(doc, "#upgrade-eligible-notice") =~ "You cannot start a subscription"- assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @starter_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ endend- end- describe "for a user with no sites but pending ownership transfer" do- setup [:create_user, :log_in]+ describe "for a user with no sites but pending ownership transfer" do+ setup [:create_user, :log_in]- setup %{user: user} do- old_owner = new_user()- site = new_site(owner: old_owner)- invite_transfer(site, user, inviter: old_owner)+ setup %{user: user} do+ old_owner = new_user()+ site = new_site(owner: old_owner)+ invite_transfer(site, user, inviter: old_owner)- :ok- end+ :ok+ end- test "renders only the pending ownership transfer notice", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)- check_notice_titles(doc, [Billing.pending_site_ownerships_notice_title()])- end+ test "renders only the pending ownership transfer notice", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)+ check_notice_titles(doc, [Billing.pending_site_ownerships_notice_title()])+ end- test "allows to subscribe", %{conn: conn} do- {:ok, _lv, doc} = get_liveview(conn)+ test "allows to subscribe", %{conn: conn} do+ {:ok, _lv, doc} = get_liveview(conn)- assert text_of_element(doc, @starter_plan_box) =~ "Recommended"- refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"- refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ assert text_of_element(doc, @starter_plan_box) =~ "Recommended"+ refute class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none"+ refute class_of_element(doc, @business_checkout_button) =~ "pointer-events-none"+ endend- end- # Checks the given HTML document for the presence of all possible billing- # notices. For those expected, we assert that only one is present. Others- # should not appear in the document.- defp check_notice_titles(doc, expected) do- [- Billing.dashboard_locked_notice_title(),- Billing.active_grace_period_notice_title(),- Billing.subscription_cancelled_notice_title(),- Billing.subscription_past_due_notice_title(),- Billing.subscription_paused_notice_title(),- Billing.upgrade_ineligible_notice_title(),- Billing.pending_site_ownerships_notice_title()- ]- |> Enum.each(fn title ->- if title in expected do- assert length(String.split(doc, title)) == 2- else- refute doc =~ title- end- end)- end+ # Checks the given HTML document for the presence of all possible billing+ # notices. For those expected, we assert that only one is present. Others+ # should not appear in the document.+ defp check_notice_titles(doc, expected) do+ [+ Billing.dashboard_locked_notice_title(),+ Billing.active_grace_period_notice_title(),+ Billing.subscription_cancelled_notice_title(),+ Billing.subscription_past_due_notice_title(),+ Billing.subscription_paused_notice_title(),+ Billing.upgrade_ineligible_notice_title(),+ Billing.pending_site_ownerships_notice_title()+ ]+ |> Enum.each(fn title ->+ if title in expected do+ assert length(String.split(doc, title)) == 2+ else+ refute doc =~ title+ end+ end)+ end- defp subscribe_v5_growth(%{user: user}) do- create_subscription_for(user, paddle_plan_id: @v5_growth_200k_yearly_plan_id)- end+ defp subscribe_v5_growth(%{user: user}) do+ create_subscription_for(user, paddle_plan_id: @v5_growth_200k_yearly_plan_id)+ end- defp subscribe_v4_business(%{user: user}) do- create_subscription_for(user, paddle_plan_id: @v4_business_5m_monthly_plan_id)- end+ defp subscribe_v4_business(%{user: user}) do+ create_subscription_for(user, paddle_plan_id: @v4_business_5m_monthly_plan_id)+ end- defp create_past_due_subscription(%{user: user}) do- create_subscription_for(user,- paddle_plan_id: @v4_growth_200k_yearly_plan_id,- status: Subscription.Status.past_due(),- update_url: "https://update.billing.details"- )- end+ defp create_past_due_subscription(%{user: user}) do+ create_subscription_for(user,+ paddle_plan_id: @v4_growth_200k_yearly_plan_id,+ status: Subscription.Status.past_due(),+ update_url: "https://update.billing.details"+ )+ end- defp create_paused_subscription(%{user: user}) do- create_subscription_for(user,- paddle_plan_id: @v4_growth_200k_yearly_plan_id,- status: Subscription.Status.paused(),- update_url: "https://update.billing.details"- )- end+ defp create_paused_subscription(%{user: user}) do+ create_subscription_for(user,+ paddle_plan_id: @v4_growth_200k_yearly_plan_id,+ status: Subscription.Status.paused(),+ update_url: "https://update.billing.details"+ )+ end- defp create_cancelled_subscription(%{user: user}) do- create_subscription_for(user,- paddle_plan_id: @v4_growth_200k_yearly_plan_id,- status: Subscription.Status.deleted()- )- end+ defp create_cancelled_subscription(%{user: user}) do+ create_subscription_for(user,+ paddle_plan_id: @v4_growth_200k_yearly_plan_id,+ status: Subscription.Status.deleted()+ )+ end- defp create_subscription_for(user, subscription_opts) do- {paddle_plan_id, subscription_opts} = Keyword.pop(subscription_opts, :paddle_plan_id)+ defp create_subscription_for(user, subscription_opts) do+ {paddle_plan_id, subscription_opts} = Keyword.pop(subscription_opts, :paddle_plan_id)- user =- subscribe_to_plan(user, paddle_plan_id, subscription_opts)+ user =+ subscribe_to_plan(user, paddle_plan_id, subscription_opts)- {:ok, user: user}- end+ {:ok, user: user}+ end- defp subscribe_free_10k(%{user: user}) do- user = subscribe_to_plan(user, "free_10k")- {:ok, user: user}- end+ defp subscribe_free_10k(%{user: user}) do+ user = subscribe_to_plan(user, "free_10k")+ {:ok, user: user}+ end- defp get_liveview(conn) do- conn = assign(conn, :live_module, PlausibleWeb.Live.ChoosePlan)- {:ok, _lv, _doc} = live(conn, Routes.billing_path(conn, :choose_plan))- end+ defp get_liveview(conn) do+ conn = assign(conn, :live_module, PlausibleWeb.Live.ChoosePlan)+ {:ok, _lv, _doc} = live(conn, Routes.billing_path(conn, :choose_plan))+ end- defp get_paddle_checkout_params(element) do- with onclick <- text_of_attr(element, "onclick"),- [[_, checkout_params_str]] <- Regex.scan(~r/Paddle\.Checkout\.open\((.*?)\)/, onclick),- {:ok, checkout_params} <- Jason.decode(checkout_params_str) do- checkout_params+ defp get_paddle_checkout_params(element) do+ with onclick <- text_of_attr(element, "onclick"),+ [[_, checkout_params_str]] <- Regex.scan(~r/Paddle\.Checkout\.open\((.*?)\)/, onclick),+ {:ok, checkout_params} <- Jason.decode(checkout_params_str) do+ checkout_params+ endend- end- defp set_slider(lv, volume) when is_binary(volume) do- index = Enum.find_index(@slider_volumes, &(&1 == volume))- set_slider(lv, index)- end+ defp set_slider(lv, volume) when is_binary(volume) do+ index = Enum.find_index(@slider_volumes, &(&1 == volume))+ set_slider(lv, index)+ end- defp set_slider(lv, index) do- lv- |> element(@slider_input)- |> render_change(%{slider: index})+ defp set_slider(lv, index) do+ lv+ |> element(@slider_input)+ |> render_change(%{slider: index})+ endendenddiff --git a/test/plausible_web/live/legacy_choose_plan_test.exs b/test/plausible_web/live/legacy_choose_plan_test.exsindex a9c28c9a40..e191d45180 100644--- a/test/plausible_web/live/legacy_choose_plan_test.exs+++ b/test/plausible_web/live/legacy_choose_plan_test.exs@@ -1253,7 +1253,8 @@ defmodule PlausibleWeb.Live.LegacyChoosePlanTest doenddefp disable_starter_tier(%{user: user}) do- FunWithFlags.disable(:starter_tier, for_actor: user)+ {:ok, team} = Plausible.Teams.get_or_create(user)+ FunWithFlags.disable(:starter_tier, for_actor: team):okendend