-
Notifications
You must be signed in to change notification settings - Fork 672
Expand file tree
/
Copy pathSubscriptionPanelContentWorkspace.test.ts
More file actions
1135 lines (1009 loc) · 38 KB
/
Copy pathSubscriptionPanelContentWorkspace.test.ts
File metadata and controls
1135 lines (1009 loc) · 38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { createTestingPinia } from '@pinia/testing'
import { render, screen } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { computed, ref } from 'vue'
import { createI18n } from 'vue-i18n'
import type { BillingType, SubscriptionInfo } from '@/composables/billing/types'
import enMessages from '@/locales/en/main.json'
import * as tierPricing from '@/platform/cloud/subscription/constants/tierPricing'
import type {
BillingStatus,
BillingSubscriptionStatus,
Plan,
TeamCreditStops,
TeamCreditStopSummary
} from '@/platform/workspace/api/workspaceApi'
import SubscriptionPanelContentWorkspace from './SubscriptionPanelContentWorkspace.vue'
const { mockIsSettingUp, mockSubscriptionActionOperation } = vi.hoisted(() => ({
mockIsSettingUp: { value: false },
mockSubscriptionActionOperation: {
value: undefined as { actionUrl: string } | undefined
}
}))
const mockDistributionState = vi.hoisted(() => ({ isCloud: true }))
vi.mock('@/platform/distribution/types', () => ({
get isCloud() {
return mockDistributionState.isCloud
}
}))
const RENEWAL_DATE_ISO = '2026-06-20T12:00:00Z'
const END_DATE_ISO = '2026-01-20T12:00:00Z'
function formatPanelDate(isoDate: string) {
return new Date(isoDate).toLocaleDateString('en', {
month: 'short',
day: 'numeric',
year: 'numeric'
})
}
// The panel displays the subscribed credit stop's per-month price; monthly and
// yearly stops are both per-month figures.
const teamCreditStops: TeamCreditStops = {
default_stop_index: 1,
stops: [
{
id: 'team_700',
credits: 147700,
monthly: { list_price_cents: 70000, price_cents: 66500 },
yearly: { list_price_cents: 70000, price_cents: 63000 }
},
{
id: 'team_2500',
credits: 527500,
monthly: { list_price_cents: 250000, price_cents: 225000 },
yearly: { list_price_cents: 250000, price_cents: 200000 }
}
]
}
const mockSubscriptionStatus = ref<BillingSubscriptionStatus>('active')
const mockBillingStatus = ref<BillingStatus>('paid')
const mockBillingType = ref<BillingType>('workspace')
const mockSubscriptionDuration = ref<'MONTHLY' | 'ANNUAL'>('MONTHLY')
const mockRenewalDate = ref<string | null>(RENEWAL_DATE_ISO)
const mockEndDate = ref<string | null>(END_DATE_ISO)
const mockScheduledPlanSlug = ref<string | null>(null)
const mockChangeAt = ref<string | null>(null)
const mockHasSubscription = ref(true)
const mockIsActiveSubscription = ref(true)
const mockIsInPersonalWorkspace = ref(false)
const mockIsWorkspaceSubscribed = ref(true)
const mockCanManageSubscription = ref(true)
const mockCanManageSubscriptionLifecycle = ref(true)
const mockCanLeaveWorkspace = ref(true)
const mockTeamCreditStops = ref<TeamCreditStops | null>(teamCreditStops)
const mockCurrentTeamCreditStop = ref<TeamCreditStopSummary | null>({
id: 'team_700',
credits_monthly: 147700,
stop_usd: 700
})
const mockManageSubscription = vi.fn()
const mockShowSubscriptionDialog = vi.fn()
const mockResubscribe = vi.fn()
const mockShowLeaveWorkspaceDialog = vi.fn()
const mockShowCancelSubscriptionFlow = vi.fn()
const mockShowEditWorkspaceDialog = vi.fn()
const mockShowDeleteWorkspaceDialog = vi.fn()
type MenuUiConfig = {
showEditWorkspaceMenuItem: boolean
workspaceMenuAction: 'delete' | null
workspaceMenuDisabledTooltip: string | null
}
const ownerUiConfig: MenuUiConfig = {
showEditWorkspaceMenuItem: true,
workspaceMenuAction: 'delete',
workspaceMenuDisabledTooltip:
'workspacePanel.menu.deleteWorkspaceDisabledTooltip'
}
const memberUiConfig: MenuUiConfig = {
showEditWorkspaceMenuItem: false,
workspaceMenuAction: null,
workspaceMenuDisabledTooltip: null
}
const personalUiConfig: MenuUiConfig = {
showEditWorkspaceMenuItem: true,
workspaceMenuAction: null,
workspaceMenuDisabledTooltip: null
}
const mockUiConfig = ref<MenuUiConfig>(ownerUiConfig)
const mockSubscriptionTier = ref<SubscriptionInfo['tier']>('PRO')
const mockPlanSlug = ref('team-monthly')
const mockHasTeamPlan = ref(true)
const mockPlans = ref<Plan[]>([
{
slug: 'pro-annual',
tier: 'PRO',
duration: 'ANNUAL',
price_cents: 96000,
credits_cents: 253200,
max_seats: 1,
availability: { available: true },
seat_summary: {
seat_count: 1,
total_cost_cents: 96000,
total_credits_cents: 253200
}
}
])
const mockSubscription = computed<SubscriptionInfo | null>(() =>
mockHasSubscription.value
? {
isActive: true,
tier: mockSubscriptionTier.value,
duration: mockSubscriptionDuration.value,
planSlug: mockPlanSlug.value,
scheduledPlanSlug: mockScheduledPlanSlug.value,
changeAt: mockChangeAt.value,
renewalDate: mockRenewalDate.value,
endDate: mockEndDate.value,
isCancelled: mockSubscriptionStatus.value === 'canceled',
hasFunds: true
}
: null
)
const mockIsTeamPlan = computed(
() => mockHasSubscription.value && mockHasTeamPlan.value
)
const mockInitialize = vi.fn()
const mockIsLoading = ref(false)
const mockError = ref<string | null>(null)
vi.mock('@/composables/billing/useBillingContext', () => ({
useBillingContext: () => ({
type: mockBillingType,
canAccessSubscriptionFeatures: computed(
() => mockIsActiveSubscription.value
),
isFreeTier: computed(() => mockSubscriptionTier.value === 'FREE'),
billingStatus: mockBillingStatus,
subscriptionStatus: mockSubscriptionStatus,
isTeamPlan: mockIsTeamPlan,
subscription: mockSubscription,
plans: mockPlans,
teamCreditStops: mockTeamCreditStops,
currentTeamCreditStop: mockCurrentTeamCreditStop,
isLoading: mockIsLoading,
error: mockError,
showSubscriptionDialog: mockShowSubscriptionDialog,
manageSubscription: mockManageSubscription,
resubscribe: mockResubscribe,
initialize: mockInitialize,
getMaxSeats: () => 5
})
}))
vi.mock('@/platform/workspace/stores/teamWorkspaceStore', () => ({
useTeamWorkspaceStore: () => ({
isInPersonalWorkspace: mockIsInPersonalWorkspace,
isWorkspaceSubscribed: mockIsWorkspaceSubscribed
})
}))
const mockIsTeamPlanCancelled = computed(
() => mockHasTeamPlan.value && (mockSubscription.value?.isCancelled ?? false)
)
const mockIsSubscriptionCancelled = computed(
() => mockSubscription.value?.isCancelled ?? false
)
const mockIsDeleteDisabled = computed(
() =>
mockIsActiveSubscription.value &&
!(mockSubscription.value?.isCancelled ?? false)
)
vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({
useWorkspaceUI: () => ({
permissions: computed(() => ({
canManageSubscription: mockCanManageSubscription.value,
canManageSubscriptionLifecycle: mockCanManageSubscriptionLifecycle.value,
canLeaveWorkspace: mockCanLeaveWorkspace.value
})),
uiConfig: computed(() => mockUiConfig.value),
isInPersonalWorkspace: mockIsInPersonalWorkspace,
isActiveSubscription: computed(() => mockIsActiveSubscription.value),
isSubscriptionCancelled: mockIsSubscriptionCancelled,
isTeamPlanCancelled: mockIsTeamPlanCancelled,
isDeleteDisabled: mockIsDeleteDisabled,
deleteDisabledTooltipKey: computed(() =>
mockIsDeleteDisabled.value
? mockUiConfig.value.workspaceMenuDisabledTooltip
: null
)
})
}))
vi.mock('@/platform/workspace/stores/billingOperationStore', () => ({
useBillingOperationStore: () => ({
get isSettingUp() {
return mockIsSettingUp.value
},
get subscriptionActionOperation() {
return mockSubscriptionActionOperation.value
}
})
}))
vi.mock('@/services/dialogService', () => ({
useDialogService: () => ({
showCancelSubscriptionFlow: mockShowCancelSubscriptionFlow,
showLeaveWorkspaceDialog: mockShowLeaveWorkspaceDialog,
showEditWorkspaceDialog: mockShowEditWorkspaceDialog,
showDeleteWorkspaceDialog: mockShowDeleteWorkspaceDialog
})
}))
vi.mock(
'@/platform/cloud/subscription/composables/useSubscriptionDialog',
() => ({
useSubscriptionDialog: () => ({ showPricingTable: vi.fn() })
})
)
vi.mock('primevue/usetoast', () => ({
useToast: () => ({ add: vi.fn() })
}))
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: { en: enMessages }
})
const CreditsTileStub = {
props: ['zeroState', 'inactivePlan'],
template:
'<div data-testid="credits-tile" :data-zero-state="String(zeroState)" :data-inactive-plan="String(inactivePlan)" />'
}
const ButtonStub = {
template:
'<button v-bind="$attrs" :disabled="loading" @click="$emit(\'click\', $event)"><slot /></button>',
props: ['variant', 'size', 'loading'],
emits: ['click']
}
const SubscriptionFooterLinksStub = {
props: ['showInvoiceHistory'],
template:
'<div data-testid="subscription-footer-links" :data-show-invoice-history="String(showInvoiceHistory)" />'
}
const DropdownMenuStub = {
props: ['entries'],
template:
'<div data-testid="plan-menu"><slot name="button" /><button v-for="item in (entries || []).filter((e) => !e.separator)" :key="item.label" type="button" :disabled="item.disabled" @click="item.command?.({})">{{ item.label }}</button></div>'
}
function renderComponent({ stubFooter = true } = {}) {
return render(SubscriptionPanelContentWorkspace, {
global: {
plugins: [createTestingPinia({ createSpy: vi.fn }), i18n],
directives: { tooltip: {} },
stubs: {
CreditsTile: CreditsTileStub,
Button: ButtonStub,
...(stubFooter
? { SubscriptionFooterLinks: SubscriptionFooterLinksStub }
: {}),
StatusBadge: true,
DropdownMenu: DropdownMenuStub
}
}
})
}
describe('SubscriptionPanelContentWorkspace', () => {
beforeEach(() => {
mockDistributionState.isCloud = true
mockSubscriptionStatus.value = 'active'
mockBillingStatus.value = 'paid'
mockBillingType.value = 'workspace'
mockRenewalDate.value = RENEWAL_DATE_ISO
mockEndDate.value = END_DATE_ISO
mockScheduledPlanSlug.value = null
mockChangeAt.value = null
mockHasSubscription.value = true
mockIsActiveSubscription.value = true
mockIsInPersonalWorkspace.value = false
mockIsWorkspaceSubscribed.value = true
mockCanManageSubscription.value = true
mockCanManageSubscriptionLifecycle.value = true
mockCanLeaveWorkspace.value = true
mockUiConfig.value = ownerUiConfig
mockSubscriptionTier.value = 'PRO'
mockPlanSlug.value = 'team-monthly'
mockHasTeamPlan.value = true
mockSubscriptionDuration.value = 'MONTHLY'
mockTeamCreditStops.value = teamCreditStops
mockCurrentTeamCreditStop.value = {
id: 'team_700',
credits_monthly: 147700,
stop_usd: 700
}
mockIsLoading.value = false
mockError.value = null
mockIsSettingUp.value = false
mockSubscriptionActionOperation.value = undefined
})
it('keeps verification available in settings without exposing its URL', async () => {
const actionUrl = 'https://verify.example/sensitive-token'
const open = vi.spyOn(window, 'open').mockReturnValue({} as Window)
mockIsSettingUp.value = true
mockSubscriptionActionOperation.value = { actionUrl }
const { container } = renderComponent()
expect(open).not.toHaveBeenCalled()
expect(container.innerHTML).not.toContain(actionUrl)
await userEvent.click(
screen.getByRole('button', { name: 'Complete verification' })
)
expect(open).toHaveBeenCalledWith(
actionUrl,
'_blank',
'noopener,noreferrer'
)
})
it('hides verification from users without billing permission', () => {
mockIsSettingUp.value = true
mockCanManageSubscription.value = false
mockSubscriptionActionOperation.value = {
actionUrl: 'https://verify.example/sensitive-token'
}
renderComponent()
expect(
screen.queryByRole('button', { name: 'Complete verification' })
).not.toBeInTheDocument()
})
it('renders the subscribed credit stop price and renewal subtitle', () => {
renderComponent()
expect(screen.getByText('Team')).toBeInTheDocument()
// Monthly subscription on team_700 -> monthly.price_cents 66500 -> $665.
expect(screen.getByText('$665')).toBeInTheDocument()
expect(screen.getByText('USD / mo')).toBeInTheDocument()
expect(screen.queryByText('USD / mo / member')).not.toBeInTheDocument()
expect(
screen.getByText(`Renews on ${formatPanelDate(RENEWAL_DATE_ISO)}`)
).toBeInTheDocument()
expect(screen.getByTestId('subscription-footer-links')).toBeInTheDocument()
expect(screen.getByTestId('subscription-footer-links')).toHaveAttribute(
'data-show-invoice-history',
'true'
)
})
it('renders Enterprise without price, benefits, or a plan-change action', () => {
mockHasTeamPlan.value = false
mockPlanSlug.value = 'enterprise_monthly'
mockCurrentTeamCreditStop.value = null
renderComponent()
expect(screen.getByText('Enterprise')).toBeInTheDocument()
expect(screen.queryByText('$665')).not.toBeInTheDocument()
expect(screen.queryByText('USD / mo')).not.toBeInTheDocument()
expect(
screen.queryByRole('button', { name: /change plan|upgrade plan/i })
).not.toBeInTheDocument()
expect(
screen.getByText(`Renews on ${formatPanelDate(RENEWAL_DATE_ISO)}`)
).toBeInTheDocument()
})
it('hides Reactivate for a cancelled enterprise plan', () => {
mockHasTeamPlan.value = false
mockPlanSlug.value = 'enterprise_monthly'
mockCurrentTeamCreditStop.value = null
mockSubscriptionStatus.value = 'canceled'
renderComponent()
expect(
screen.queryByRole('button', { name: /reactivate/i })
).not.toBeInTheDocument()
})
it('offers no subscribe or reactivate path for an ended enterprise plan', () => {
mockHasTeamPlan.value = false
mockPlanSlug.value = 'enterprise_monthly'
mockCurrentTeamCreditStop.value = null
mockSubscriptionStatus.value = 'ended'
mockIsActiveSubscription.value = false
renderComponent()
expect(screen.getByText('Enterprise')).toBeInTheDocument()
expect(
screen.queryByRole('button', { name: /subscribe|reactivate/i })
).not.toBeInTheDocument()
})
it('labels a scheduled change to Enterprise', () => {
const basePlans = mockPlans.value
mockScheduledPlanSlug.value = 'enterprise_monthly'
mockChangeAt.value = END_DATE_ISO
mockPlans.value = [
...basePlans,
{
slug: 'enterprise_monthly',
tier: 'PRO',
duration: 'MONTHLY',
price_cents: 0,
credits_cents: 0,
max_seats: 1,
availability: { available: true },
seat_summary: {
seat_count: 1,
total_cost_cents: 0,
total_credits_cents: 0
}
}
]
try {
renderComponent()
expect(
screen.getByText(
`Changes to Enterprise on ${formatPanelDate(END_DATE_ISO)}`
)
).toBeInTheDocument()
} finally {
mockPlans.value = basePlans
}
})
it('shows a scheduled plan change instead of the renewal date', () => {
mockScheduledPlanSlug.value = 'pro-annual'
mockChangeAt.value = END_DATE_ISO
renderComponent()
expect(
screen.getByText(`Changes to Pro on ${formatPanelDate(END_DATE_ISO)}`)
).toBeInTheDocument()
expect(screen.queryByText(/^Renews on/i)).not.toBeInTheDocument()
})
it('does not show an incomplete scheduled plan change', () => {
mockScheduledPlanSlug.value = 'missing-plan'
mockChangeAt.value = END_DATE_ISO
renderComponent()
expect(screen.queryByText(/^Changes to/i)).not.toBeInTheDocument()
expect(screen.queryByText(/^Renews on/i)).not.toBeInTheDocument()
})
it.for([null, 'not-a-date', '2026-02-31T12:00:00Z'])(
'omits renewal copy when the active renewal date is %s',
(renewalDate) => {
mockRenewalDate.value = renewalDate
renderComponent()
expect(screen.queryByText(/^Renews on/i)).not.toBeInTheDocument()
expect(screen.queryByText(/Invalid Date/i)).not.toBeInTheDocument()
}
)
it('uses the yearly stop price for an annual subscription, still shown per month', () => {
mockSubscriptionDuration.value = 'ANNUAL'
mockCurrentTeamCreditStop.value = {
id: 'team_2500',
credits_monthly: 527500,
stop_usd: 2500
}
renderComponent()
// team_2500 yearly.price_cents 200000 -> $2,000, labelled per month.
expect(screen.getByText('$2,000')).toBeInTheDocument()
expect(screen.getByText('USD / mo')).toBeInTheDocument()
})
it('falls back to the per-member tier price until stops resolve', () => {
mockTeamCreditStops.value = null
mockCurrentTeamCreditStop.value = null
renderComponent()
expect(screen.getByText('$100')).toBeInTheDocument()
expect(screen.getByText('USD / mo / member')).toBeInTheDocument()
})
it('falls back to the per-member price when the subscribed stop id is stale', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
mockCurrentTeamCreditStop.value = {
id: 'team_unknown',
credits_monthly: 1,
stop_usd: 1
}
renderComponent()
expect(screen.getByText('$100')).toBeInTheDocument()
expect(screen.getByText('USD / mo / member')).toBeInTheDocument()
expect(warn).toHaveBeenCalledOnce()
warn.mockRestore()
})
it('shows cents when the subscribed stop price is not a whole dollar', () => {
mockTeamCreditStops.value = {
default_stop_index: 0,
stops: [
{
id: 'team_700',
credits: 147700,
monthly: { list_price_cents: 70000, price_cents: 66550 },
yearly: { list_price_cents: 70000, price_cents: 63000 }
}
]
}
renderComponent()
expect(screen.getByText('$665.50')).toBeInTheDocument()
})
it('wires Billing & invoices and Change plan actions for subscription managers', async () => {
const user = userEvent.setup()
renderComponent()
await user.click(screen.getByRole('button', { name: 'Billing & invoices' }))
expect(mockManageSubscription).toHaveBeenCalledOnce()
await user.click(screen.getByRole('button', { name: 'Change plan' }))
expect(mockShowSubscriptionDialog).toHaveBeenCalledOnce()
})
it('preserves local Manage billing and Invoice history actions', async () => {
const user = userEvent.setup()
mockDistributionState.isCloud = false
renderComponent({ stubFooter: false })
expect(
screen.queryByRole('button', { name: 'Billing & invoices' })
).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Manage billing' }))
expect(mockManageSubscription).toHaveBeenCalledOnce()
await user.click(screen.getByRole('button', { name: 'Invoice history' }))
expect(mockManageSubscription).toHaveBeenCalledTimes(2)
})
it('keeps a Personal workspace Team-plan member view read-only', () => {
mockIsInPersonalWorkspace.value = true
mockCanManageSubscription.value = false
mockCanManageSubscriptionLifecycle.value = false
mockCanLeaveWorkspace.value = true
mockUiConfig.value = memberUiConfig
renderComponent()
expect(screen.getByRole('heading', { name: 'Team' })).toBeInTheDocument()
expect(screen.getByTestId('credits-tile')).toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Billing & invoices' })
).not.toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Change plan' })
).not.toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Edit workspace details' })
).not.toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Leave Workspace' })
).toBeInTheDocument()
expect(screen.getByText('Invite members')).toBeInTheDocument()
expect(screen.getByTestId('subscription-footer-links')).toHaveAttribute(
'data-show-invoice-history',
'false'
)
})
it('uses Team-plan change copy in a Personal workspace', () => {
mockIsInPersonalWorkspace.value = true
renderComponent()
expect(
screen.getByRole('button', { name: 'Change plan' })
).toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Upgrade plan' })
).not.toBeInTheDocument()
})
it('keeps billing access in the ended state for an inactive paid Personal workspace', async () => {
const user = userEvent.setup()
mockBillingType.value = 'legacy'
mockIsInPersonalWorkspace.value = true
mockIsActiveSubscription.value = false
mockBillingStatus.value = 'inactive'
renderComponent()
expect(screen.getByText('Your subscription has ended')).toBeInTheDocument()
expect(screen.getByRole('heading', { name: 'Free' })).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Billing & invoices' }))
expect(mockManageSubscription).toHaveBeenCalledOnce()
expect(
screen.getByRole('button', { name: 'Subscribe' })
).toBeInTheDocument()
expect(
screen.queryByRole('heading', { name: 'Team' })
).not.toBeInTheDocument()
})
it('shows subscribe prompt for an ended Standard plan in a Team workspace', () => {
mockSubscriptionStatus.value = 'ended'
mockSubscriptionTier.value = 'STANDARD'
mockPlanSlug.value = 'standard-monthly'
mockHasTeamPlan.value = false
renderComponent()
expect(
screen.getByRole('heading', {
name: 'This workspace is not on a subscription'
})
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Subscribe Now' })
).toBeInTheDocument()
expect(
screen.queryByRole('heading', { name: 'Standard' })
).not.toBeInTheDocument()
})
it.for(['paid', 'payment_failed', 'paused'] as BillingStatus[])(
'keeps billing access for a non-terminal %s personal plan',
(billingStatus) => {
mockIsInPersonalWorkspace.value = true
mockIsActiveSubscription.value = false
mockBillingStatus.value = billingStatus
renderComponent()
expect(screen.getByRole('heading', { name: 'Team' })).toBeInTheDocument()
expect(
screen.queryByText('Your subscription has ended')
).not.toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Subscribe' })
).not.toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Billing & invoices' })
).toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Change plan' })
).not.toBeInTheDocument()
}
)
it('shows dated cancellation copy while a cancelled plan remains active', async () => {
const user = userEvent.setup()
mockSubscriptionStatus.value = 'canceled'
mockScheduledPlanSlug.value = 'pro-annual'
mockChangeAt.value = RENEWAL_DATE_ISO
mockCanLeaveWorkspace.value = false
renderComponent()
expect(
screen.getByText(
`You won't be charged again. Your features remain active until ${formatPanelDate(END_DATE_ISO)}.`
)
).toBeInTheDocument()
expect(
screen.getByText(`Ends on ${formatPanelDate(END_DATE_ISO)}`)
).toBeInTheDocument()
expect(
screen.queryByText(`Renews on ${formatPanelDate(RENEWAL_DATE_ISO)}`)
).not.toBeInTheDocument()
expect(screen.queryByText(/^Changes to/i)).not.toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Billing & invoices' })
).toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Change plan' })
).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Reactivate plan' }))
expect(mockResubscribe).toHaveBeenCalledOnce()
expect(mockShowSubscriptionDialog).not.toHaveBeenCalled()
})
it('shows ended copy for an inactive ended subscription without a date', () => {
mockSubscriptionStatus.value = 'ended'
mockIsActiveSubscription.value = false
mockIsInPersonalWorkspace.value = true
mockEndDate.value = null
renderComponent()
expect(screen.getByText('Your subscription has ended')).toBeInTheDocument()
expect(
screen.getByText('Your subscription is no longer active.')
).toBeInTheDocument()
expect(
screen.queryByText(/features remain active/i)
).not.toBeInTheDocument()
expect(screen.queryByText(/^Ends on/i)).not.toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Subscribe' })
).toBeInTheDocument()
})
it('preserves local inactive Team billing and invoice actions', async () => {
const user = userEvent.setup()
mockDistributionState.isCloud = false
mockSubscriptionStatus.value = 'canceled'
mockIsActiveSubscription.value = false
mockIsWorkspaceSubscribed.value = false
renderComponent({ stubFooter: false })
expect(
screen.getByRole('heading', { name: 'Inactive team subscription' })
).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Billing & invoices' }))
expect(mockManageSubscription).toHaveBeenCalledOnce()
await user.click(screen.getByRole('button', { name: 'Invoice history' }))
expect(mockManageSubscription).toHaveBeenCalledTimes(2)
})
it('renders an ended Team plan for its owner and routes reactivation to checkout', async () => {
mockSubscriptionStatus.value = 'canceled'
mockIsActiveSubscription.value = false
mockIsWorkspaceSubscribed.value = false
const user = userEvent.setup()
renderComponent()
expect(screen.getByText('Your subscription has ended')).toBeInTheDocument()
expect(
screen.getByRole('heading', { name: 'Inactive team subscription' })
).toBeInTheDocument()
expect(
screen.getByText(
'Reactivate your team plan to add more members and run workflows'
)
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Billing & invoices' })
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Reactivate plan' })
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'More Options' })
).toBeInTheDocument()
expect(screen.getByTestId('credits-tile')).toHaveAttribute(
'data-zero-state',
'true'
)
expect(screen.getByTestId('credits-tile')).toHaveAttribute(
'data-inactive-plan',
'true'
)
expect(document.body.textContent).toContain(
'An active plan features everything in Pro, plus:'
)
expect(screen.getByText('Invite members')).toBeInTheDocument()
expect(
screen.getByText('Members can run workflows concurrently')
).toBeInTheDocument()
expect(
screen.getByText('Shared credit pool for all members')
).toBeInTheDocument()
expect(screen.getByText('Role-based permissions')).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Reactivate plan' }))
expect(mockShowSubscriptionDialog).toHaveBeenCalledWith({
reason: 'settings_billing_panel'
})
expect(mockResubscribe).not.toHaveBeenCalled()
})
it('does not show stale renewal copy for an explicitly ended active state', () => {
mockSubscriptionStatus.value = 'ended'
renderComponent()
expect(screen.getByText('Your subscription has ended')).toBeInTheDocument()
expect(screen.queryByText(/^Renews on/i)).not.toBeInTheDocument()
})
it.for([null, 'not-a-date', '2026-02-31T12:00:00Z'])(
'uses safe cancellation copy when the active end date is %s',
(endDate) => {
mockSubscriptionStatus.value = 'canceled'
mockEndDate.value = endDate
renderComponent()
expect(
screen.getByText(
"You won't be charged again. Your features remain active until the end of your billing period."
)
).toBeInTheDocument()
expect(screen.queryByText(/^Ends on/i)).not.toBeInTheDocument()
expect(screen.queryByText(/Invalid Date/i)).not.toBeInTheDocument()
}
)
it('keeps a cancelled Personal plan in a Team workspace reactivatable', () => {
mockSubscriptionStatus.value = 'canceled'
mockHasTeamPlan.value = false
mockIsWorkspaceSubscribed.value = false
renderComponent()
expect(
screen.getByText(`Ends on ${formatPanelDate(END_DATE_ISO)}`)
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Reactivate plan' })
).toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Subscribe Now' })
).not.toBeInTheDocument()
})
it('keeps Billing & invoices available to unsubscribed team owners', async () => {
const user = userEvent.setup()
mockIsActiveSubscription.value = false
mockIsWorkspaceSubscribed.value = false
mockHasSubscription.value = false
renderComponent()
expect(
screen.getByText('This workspace is not on a subscription')
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Subscribe Now' })
).toBeInTheDocument()
expect(screen.getByTestId('credits-tile')).toHaveAttribute(
'data-zero-state',
'true'
)
await user.click(screen.getByRole('button', { name: 'Billing & invoices' }))
expect(mockManageSubscription).toHaveBeenCalledOnce()
})
it('shows a loading indicator instead of a false Free plan while billing loads', () => {
mockHasSubscription.value = false
mockIsLoading.value = true
renderComponent()
expect(screen.getByText('Loading')).toBeInTheDocument()
expect(screen.queryByText('Free')).not.toBeInTheDocument()
expect(screen.queryByText('$0')).not.toBeInTheDocument()
})
it('shows a retry affordance instead of a false Free plan when billing fails', async () => {
const user = userEvent.setup()
mockHasSubscription.value = false
mockError.value = 'network down'
renderComponent()
expect(
screen.getByText("We couldn't load your plan details.")
).toBeInTheDocument()
expect(screen.queryByText('Free')).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Try again' }))
expect(mockInitialize).toHaveBeenCalledOnce()
})
it('shows the zero-state contact-owner view to unsubscribed members', () => {
mockIsActiveSubscription.value = false
mockIsWorkspaceSubscribed.value = false
mockHasSubscription.value = false
mockCanManageSubscription.value = false
mockCanManageSubscriptionLifecycle.value = false
renderComponent()
expect(
screen.getByText('Contact the workspace owner to subscribe')
).toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Subscribe Now' })
).not.toBeInTheDocument()
expect(screen.getByTestId('credits-tile')).toHaveAttribute(
'data-zero-state',
'true'
)
})
it('renders the Free plan header with Subscribe CTA for unsubscribed personal workspaces', async () => {
const user = userEvent.setup()
mockIsInPersonalWorkspace.value = true
mockIsActiveSubscription.value = false
mockHasSubscription.value = false
mockIsWorkspaceSubscribed.value = false
mockUiConfig.value = personalUiConfig
mockCanLeaveWorkspace.value = false
renderComponent()
expect(screen.getByText('Free')).toBeInTheDocument()
expect(screen.getByText('$0')).toBeInTheDocument()
expect(screen.getByText('USD / mo')).toBeInTheDocument()
expect(screen.getByText("What's included:")).toBeInTheDocument()
expect(screen.getByText('10 min max runtime')).toBeInTheDocument()
expect(
screen.queryByText('RTX 6000 Pro (96GB VRAM)')
).not.toBeInTheDocument()
expect(screen.getByTestId('credits-tile')).toHaveAttribute(
'data-zero-state',
'false'
)
await user.click(screen.getByRole('button', { name: 'Billing & invoices' }))
expect(mockManageSubscription).toHaveBeenCalledOnce()
await user.click(screen.getByRole('button', { name: 'Subscribe' }))
expect(mockShowSubscriptionDialog).toHaveBeenCalledOnce()
})
it.for([
{ state: 'never-subscribed', hasSubscription: false, tier: 'PRO' },
{ state: 'Free', hasSubscription: true, tier: 'FREE' }
] as const)(
'keeps billing access for $state personal workspaces',
({ hasSubscription, tier }) => {
mockBillingType.value = 'legacy'
mockBillingStatus.value = 'inactive'
mockSubscriptionTier.value = tier
mockIsInPersonalWorkspace.value = true
mockIsActiveSubscription.value = false
mockHasSubscription.value = hasSubscription
mockIsWorkspaceSubscribed.value = false
mockUiConfig.value = personalUiConfig
mockCanLeaveWorkspace.value = false
renderComponent()
expect(screen.getByRole('heading', { name: 'Free' })).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Billing & invoices' })
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Subscribe' })
).toBeInTheDocument()
}
)
it('lets a Free personal workspace only rename itself (no Cancel or Delete)', async () => {
const user = userEvent.setup()
mockIsInPersonalWorkspace.value = true
mockIsActiveSubscription.value = false
mockHasSubscription.value = false
mockIsWorkspaceSubscribed.value = false
mockUiConfig.value = personalUiConfig
mockCanLeaveWorkspace.value = false
renderComponent()
expect(
screen.queryByRole('button', { name: 'Cancel plan' })
).not.toBeInTheDocument()
expect(
screen.queryByRole('button', { name: 'Delete Workspace' })
).not.toBeInTheDocument()
await user.click(
screen.getByRole('button', { name: 'Edit workspace details' })
)
expect(mockShowEditWorkspaceDialog).toHaveBeenCalledOnce()
})
it('offers a subscribed personal workspace Edit and Cancel without Delete', () => {
mockIsInPersonalWorkspace.value = true
mockIsActiveSubscription.value = true
mockHasSubscription.value = true