Leon4gr45 commited on
Commit
188e680
·
verified ·
1 Parent(s): c368d78

Delete test/plausible_web/components/billing/billing_test.exs with huggingface_hub

Browse files
test/plausible_web/components/billing/billing_test.exs DELETED
@@ -1,402 +0,0 @@
1
- defmodule PlausibleWeb.Components.BillingTest do
2
- use Plausible.DataCase
3
- import Phoenix.Component
4
- import Phoenix.LiveViewTest, only: [rendered_to_string: 1]
5
-
6
- describe "feature_gate/1" do
7
- setup [:create_user]
8
-
9
- test "renders a blur overlay if the feature is locked", %{user: user} do
10
- html =
11
- %{
12
- current_user: user,
13
- current_team: user |> subscribe_to_growth_plan() |> team_of(),
14
- locked?: true
15
- }
16
- |> render_feature_gate()
17
-
18
- assert element_exists?(html, "#feature-gate-inner-block-container")
19
- assert element_exists?(html, "#feature-gate-overlay")
20
- assert text_of_element(html, "#feature-gate-overlay") =~ "Upgrade to unlock"
21
- end
22
-
23
- test "renders a blur overlay for a teamless account", %{user: user} do
24
- html =
25
- %{
26
- current_user: user,
27
- current_team: nil,
28
- locked?: true
29
- }
30
- |> render_feature_gate()
31
-
32
- assert element_exists?(html, "#feature-gate-inner-block-container")
33
- assert element_exists?(html, "#feature-gate-overlay")
34
- assert text_of_element(html, "#feature-gate-overlay") =~ "Upgrade to unlock"
35
- end
36
-
37
- test "does not render a blur overlay if feature access is granted", %{user: user} do
38
- html =
39
- %{
40
- current_user: user,
41
- current_team: user |> subscribe_to_business_plan() |> team_of(),
42
- locked?: false
43
- }
44
- |> render_feature_gate()
45
-
46
- assert element_exists?(html, "#feature-gate-inner-block-container")
47
- refute element_exists?(html, "#feature-gate-overlay")
48
- end
49
-
50
- test "renders upgrade cta linking to the upgrade page if user role is :owner", %{user: user} do
51
- html =
52
- %{
53
- current_user: user,
54
- current_team: user |> subscribe_to_growth_plan() |> team_of(),
55
- locked?: true
56
- }
57
- |> render_feature_gate()
58
-
59
- assert text_of_element(html, "#lock-notice") =~ "upgrade your subscription"
60
- end
61
-
62
- test "renders upgrade cta linking to the upgrade page if user role is :billing", %{user: user} do
63
- team = user |> subscribe_to_growth_plan() |> team_of()
64
- billing = add_member(team, role: :billing)
65
-
66
- html =
67
- %{
68
- current_user: billing,
69
- current_team: team,
70
- locked?: true
71
- }
72
- |> render_feature_gate()
73
-
74
- assert text_of_element(html, "#lock-notice") =~ "upgrade your subscription"
75
- end
76
-
77
- test "renders upgrade cta instructing to contact owner if user role is not :owner nor :billing",
78
- %{
79
- user: user
80
- } do
81
- team = user |> subscribe_to_growth_plan() |> team_of()
82
- editor = add_member(team, role: :editor)
83
-
84
- html =
85
- %{
86
- current_user: editor,
87
- current_team: team,
88
- locked?: true
89
- }
90
- |> render_feature_gate()
91
-
92
- assert text_of_element(html, "#lock-notice") =~ "ask your team owner"
93
- end
94
-
95
- test "renders upgrade cta linking to the upgrade page when user is not a team member (e.g. super-admin)",
96
- %{
97
- user: user
98
- } do
99
- team = user |> subscribe_to_growth_plan() |> team_of()
100
- other_user = new_user()
101
-
102
- html =
103
- %{
104
- current_user: other_user,
105
- current_team: team,
106
- locked?: true
107
- }
108
- |> render_feature_gate()
109
-
110
- assert text_of_element(html, "#lock-notice") =~ "upgrade your subscription"
111
- end
112
- end
113
-
114
- defp render_feature_gate(assigns) do
115
- ~H"""
116
- <PlausibleWeb.Components.Billing.feature_gate {assigns}>
117
- <div>content...</div>
118
- </PlausibleWeb.Components.Billing.feature_gate>
119
- """
120
- |> rendered_to_string()
121
- end
122
-
123
- describe "usage_progress_bar/1" do
124
- test "renders progress bar with green color at 0% usage" do
125
- html = render_progress_bar(0, 10_000)
126
-
127
- assert html =~ "width: 0"
128
- assert html =~ "bg-green-500 dark:bg-green-600"
129
- end
130
-
131
- test "renders progress bar with green color at 50% usage" do
132
- html = render_progress_bar(5_000, 10_000)
133
-
134
- assert html =~ "width: 50.0%"
135
- assert html =~ "bg-green-500 dark:bg-green-600"
136
- end
137
-
138
- test "renders progress bar with green color at 90% usage" do
139
- html = render_progress_bar(9_000, 10_000)
140
-
141
- assert html =~ "width: 90.0%"
142
- assert html =~ "bg-green-500 dark:bg-green-600"
143
- end
144
-
145
- test "renders progress bar with gradient at 95% usage" do
146
- html = render_progress_bar(9_500, 10_000)
147
-
148
- assert html =~ "width: 95.0%"
149
- assert html =~ "bg-gradient-to-r from-green-500 via-yellow-500 via-[80%] to-orange-500"
150
- end
151
-
152
- test "renders progress bar with red gradient at 100% usage" do
153
- html = render_progress_bar(10_000, 10_000)
154
-
155
- assert html =~ "width: 100.0%"
156
- assert html =~ "bg-gradient-to-r from-green-500 via-orange-500 via-[80%] to-red-500"
157
- end
158
-
159
- test "caps percentage at 100% when usage exceeds limit" do
160
- html = render_progress_bar(15_000, 10_000)
161
-
162
- assert html =~ "width: 100.0%"
163
- assert html =~ "bg-gradient-to-r from-green-500 via-orange-500 via-[80%] to-red-500"
164
- end
165
-
166
- test "handles unlimited limit" do
167
- html = render_progress_bar(5_000, :unlimited)
168
-
169
- assert html =~ "width: 0%"
170
- assert html =~ "bg-green-500 dark:bg-green-600"
171
- end
172
-
173
- test "handles zero limit" do
174
- html = render_progress_bar(0, 0)
175
-
176
- assert html =~ "width: 0%"
177
- assert html =~ "bg-gray-200 dark:bg-gray-700"
178
- end
179
- end
180
-
181
- describe "render_monthly_pageview_usage/1" do
182
- @cycle %{
183
- pageviews: 0,
184
- custom_events: 0,
185
- total: 0,
186
- date_range: Date.range(~D[2024-01-01], ~D[2024-01-31]),
187
- per_site: []
188
- }
189
-
190
- test "only shows current cycle when neither last nor current cycle is exceeded" do
191
- usage = %{
192
- current_cycle: @cycle,
193
- last_cycle: @cycle,
194
- penultimate_cycle: @cycle
195
- }
196
-
197
- html = render_monthly_pageview_usage(usage, 10_000)
198
-
199
- assert element_exists?(html, "#total_pageviews_current_cycle")
200
- refute element_exists?(html, "#total_pageviews_last_cycle")
201
- refute element_exists?(html, "#total_pageviews_penultimate_cycle")
202
- end
203
-
204
- test "shows all three cycles when last cycle is exceeded" do
205
- usage = %{
206
- current_cycle: @cycle,
207
- last_cycle: %{@cycle | total: 11_000},
208
- penultimate_cycle: @cycle
209
- }
210
-
211
- html = render_monthly_pageview_usage(usage, 10_000)
212
-
213
- assert element_exists?(html, "#total_pageviews_current_cycle")
214
- assert element_exists?(html, "#total_pageviews_last_cycle")
215
- assert element_exists?(html, "#total_pageviews_penultimate_cycle")
216
- end
217
-
218
- test "shows all three cycles when current cycle is exceeded" do
219
- usage = %{
220
- current_cycle: %{@cycle | total: 11_000},
221
- last_cycle: @cycle,
222
- penultimate_cycle: @cycle
223
- }
224
-
225
- html = render_monthly_pageview_usage(usage, 10_000)
226
-
227
- assert element_exists?(html, "#total_pageviews_current_cycle")
228
- assert element_exists?(html, "#total_pageviews_last_cycle")
229
- assert element_exists?(html, "#total_pageviews_penultimate_cycle")
230
- end
231
-
232
- test "shows all three cycles when both last and current cycles are exceeded" do
233
- usage = %{
234
- current_cycle: %{@cycle | total: 11_000},
235
- last_cycle: %{@cycle | total: 11_000},
236
- penultimate_cycle: @cycle
237
- }
238
-
239
- html = render_monthly_pageview_usage(usage, 10_000)
240
-
241
- assert element_exists?(html, "#total_pageviews_current_cycle")
242
- assert element_exists?(html, "#total_pageviews_last_cycle")
243
- assert element_exists?(html, "#total_pageviews_penultimate_cycle")
244
- end
245
-
246
- test "shows 'Pageviews' and 'Custom events' labels when no per-site breakdown" do
247
- usage = %{current_cycle: @cycle, last_cycle: @cycle, penultimate_cycle: @cycle}
248
-
249
- html = render_monthly_pageview_usage(usage, 10_000)
250
-
251
- assert text_of_element(html, "#pageviews_current_cycle") =~ "Pageviews"
252
- refute text_of_element(html, "#pageviews_current_cycle") =~ "Total pageviews"
253
- assert text_of_element(html, "#custom_events_current_cycle") =~ "Custom events"
254
- refute text_of_element(html, "#custom_events_current_cycle") =~ "Total custom events"
255
- end
256
-
257
- test "shows 'Total pageviews' and 'Total custom events' labels when per-site breakdown is present" do
258
- cycle_with_sites = %{
259
- @cycle
260
- | per_site: [
261
- %{domain: "example.com", pageviews: 100, custom_events: 50, total: 150},
262
- %{domain: "app.example.com", pageviews: 200, custom_events: 30, total: 230}
263
- ]
264
- }
265
-
266
- usage = %{current_cycle: cycle_with_sites, last_cycle: @cycle, penultimate_cycle: @cycle}
267
-
268
- html = render_monthly_pageview_usage(usage, 10_000)
269
-
270
- assert text_of_element(html, "#pageviews_current_cycle") =~ "Total pageviews"
271
- assert text_of_element(html, "#custom_events_current_cycle") =~ "Total custom events"
272
- end
273
-
274
- test "renders per-site breakdown when sites are present" do
275
- cycle_with_sites = %{
276
- @cycle
277
- | per_site: [
278
- %{domain: "example.com", pageviews: 100, custom_events: 50, total: 150},
279
- %{domain: "app.example.com", pageviews: 200, custom_events: 30, total: 230}
280
- ]
281
- }
282
-
283
- usage = %{current_cycle: cycle_with_sites, last_cycle: @cycle, penultimate_cycle: @cycle}
284
-
285
- html = render_monthly_pageview_usage(usage, 10_000)
286
-
287
- assert element_exists?(html, "#per_site_breakdown_current_cycle")
288
- assert text_of_element(html, "#per_site_breakdown_current_cycle") =~ "example.com"
289
- assert text_of_element(html, "#per_site_breakdown_current_cycle") =~ "app.example.com"
290
- end
291
-
292
- test "does not render per-site breakdown when sites list is empty" do
293
- usage = %{current_cycle: @cycle, last_cycle: @cycle, penultimate_cycle: @cycle}
294
-
295
- html = render_monthly_pageview_usage(usage, 10_000)
296
-
297
- refute element_exists?(html, "#per_site_breakdown_current_cycle")
298
- end
299
-
300
- test "current cycle is expanded by default when no per-site breakdown" do
301
- usage = %{current_cycle: @cycle, last_cycle: @cycle, penultimate_cycle: @cycle}
302
-
303
- html = render_monthly_pageview_usage(usage, 10_000)
304
-
305
- assert html =~ "{ open: true }"
306
- end
307
-
308
- test "current cycle is not expanded by default when per-site breakdown is present" do
309
- cycle_with_sites = %{
310
- @cycle
311
- | per_site: [
312
- %{domain: "example.com", pageviews: 100, custom_events: 50, total: 150},
313
- %{domain: "app.example.com", pageviews: 200, custom_events: 30, total: 230}
314
- ]
315
- }
316
-
317
- usage = %{current_cycle: cycle_with_sites, last_cycle: @cycle, penultimate_cycle: @cycle}
318
-
319
- html = render_monthly_pageview_usage(usage, 10_000)
320
-
321
- refute html =~ "{ open: true }"
322
- end
323
-
324
- test "renders a total link when total_pageview_usage_domain is provided" do
325
- usage = %{current_cycle: @cycle, last_cycle: @cycle, penultimate_cycle: @cycle}
326
-
327
- html =
328
- render_monthly_pageview_usage(usage, 10_000,
329
- total_pageview_usage_domain: "my-site.example.com"
330
- )
331
-
332
- assert element_exists?(html, "[data-test-id='total-pageviews-dashboard-link']")
333
- assert html =~ "/my-site.example.com?period=custom"
334
- end
335
-
336
- test "renders no total link when no domain is provided" do
337
- usage = %{current_cycle: @cycle, last_cycle: @cycle, penultimate_cycle: @cycle}
338
-
339
- html = render_monthly_pageview_usage(usage, 10_000)
340
-
341
- refute element_exists?(html, "[data-test-id='total-pageviews-dashboard-link']")
342
- end
343
-
344
- test "per-site breakdown shows a dashboard link for each site" do
345
- cycle_with_sites = %{
346
- @cycle
347
- | per_site: [
348
- %{domain: "example.com", pageviews: 100, custom_events: 50, total: 150},
349
- %{domain: "app.example.com", pageviews: 200, custom_events: 30, total: 230}
350
- ]
351
- }
352
-
353
- usage = %{current_cycle: cycle_with_sites, last_cycle: @cycle, penultimate_cycle: @cycle}
354
-
355
- html = render_monthly_pageview_usage(usage, 10_000)
356
-
357
- assert html =~ "/example.com?period=custom"
358
- assert html =~ "/app.example.com?period=custom"
359
- end
360
-
361
- test "dashboard links include the billing cycle date range" do
362
- usage = %{current_cycle: @cycle, last_cycle: @cycle, penultimate_cycle: @cycle}
363
-
364
- html =
365
- render_monthly_pageview_usage(usage, 10_000,
366
- total_pageview_usage_domain: "my-site.example.com"
367
- )
368
-
369
- assert html =~
370
- "/my-site.example.com?period=custom&amp;from=2024-01-01&amp;to=2024-01-31"
371
- end
372
- end
373
-
374
- defp render_progress_bar(usage, limit) do
375
- assigns = %{usage: usage, limit: limit}
376
-
377
- ~H"""
378
- <PlausibleWeb.Components.Billing.usage_progress_bar
379
- usage={@usage}
380
- limit={@limit}
381
- />
382
- """
383
- |> rendered_to_string()
384
- end
385
-
386
- defp render_monthly_pageview_usage(usage, limit, opts \\ []) do
387
- assigns = %{
388
- usage: usage,
389
- limit: limit,
390
- total_pageview_usage_domain: opts[:total_pageview_usage_domain]
391
- }
392
-
393
- ~H"""
394
- <PlausibleWeb.Components.Billing.render_monthly_pageview_usage
395
- usage={@usage}
396
- limit={@limit}
397
- total_pageview_usage_domain={@total_pageview_usage_domain}
398
- />
399
- """
400
- |> rendered_to_string()
401
- end
402
- end