diff --git a/browser_tests/tests/currentUserPopoverCredits.spec.ts b/browser_tests/tests/currentUserPopoverCredits.spec.ts index 55b95f0cc3f..a01ce3afcbf 100644 --- a/browser_tests/tests/currentUserPopoverCredits.spec.ts +++ b/browser_tests/tests/currentUserPopoverCredits.spec.ts @@ -151,7 +151,7 @@ const test = comfyPageFixture.extend({ }) test.describe('Current user popover credits row', { tag: '@cloud' }, () => { - test('keeps both action buttons inside the popover when cancelled but active', async ({ + test('shows only Add credits, inside the popover, when cancelled but active', async ({ comfyPage }) => { const page = comfyPage.page @@ -163,18 +163,19 @@ test.describe('Current user popover credits row', { tag: '@cloud' }, () => { await expect(popover).toBeVisible() const addCredits = page.getByTestId('add-credits-button') - const resubscribe = page.getByRole('button', { name: 'Resubscribe' }) await expect(addCredits).toBeVisible() - await expect(resubscribe).toBeVisible() + await expect(page.getByRole('button', { name: 'Resubscribe' })).toHaveCount( + 0 + ) const popoverBox = await popover.boundingBox() - const resubscribeBox = await resubscribe.boundingBox() + const addCreditsBox = await addCredits.boundingBox() expect(popoverBox).not.toBeNull() - expect(resubscribeBox).not.toBeNull() + expect(addCreditsBox).not.toBeNull() const popoverRight = popoverBox!.x + popoverBox!.width - const resubscribeRight = resubscribeBox!.x + resubscribeBox!.width - expect(resubscribeRight).toBeLessThanOrEqual(popoverRight) + const addCreditsRight = addCreditsBox!.x + addCreditsBox!.width + expect(addCreditsRight).toBeLessThanOrEqual(popoverRight) }) test('keeps the user card inside the single popover frame', async ({ diff --git a/browser_tests/tests/workspaceSwitcher.spec.ts b/browser_tests/tests/workspaceSwitcher.spec.ts index 724b812550e..eb46e5b02c9 100644 --- a/browser_tests/tests/workspaceSwitcher.spec.ts +++ b/browser_tests/tests/workspaceSwitcher.spec.ts @@ -145,7 +145,10 @@ test.describe('Workspace switcher', { tag: '@cloud' }, () => { await comfyPage.toast.closeToasts() await page.getByRole('button', { name: 'Current user' }).click() - await expect(page.getByTestId('add-credits-button')).toBeEnabled() + await expect( + page.getByRole('button', { name: /^(Subscribe|Resubscribe)$/ }) + ).toBeVisible() + await expect(page.getByTestId('add-credits-button')).toHaveCount(0) const longWorkspaceCapabilities = page.waitForResponse( (response) => response.url().includes('/api/billing/capabilities') && diff --git a/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts index 6a740d72cfe..0fe4398440a 100644 --- a/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts @@ -203,6 +203,7 @@ describe('CurrentUserPopoverWorkspace', () => { () => ({ amountMicros: 100, currency: 'USD' }) satisfies BalanceInfo ) billingContext.isLoading = ref(false) + billingContext.isInitialized = ref(true) vi.mocked(useBillingContext).mockReturnValue(billingContext) const workspaceUI = vi.mocked(useAccountUI()) workspaceUI.permissions = computed(() => ({ @@ -491,18 +492,60 @@ describe('CurrentUserPopoverWorkspace', () => { ).toHaveBeenCalledExactlyOnceWith({ source: 'avatar_menu_plans' }) }) - it('offers add-credits alongside Subscribe for an unsubscribed Cloud owner', () => { + it.for(['personal', 'team'] as const)( + 'offers only Subscribe, not Add credits, to an unsubscribed Cloud owner in a %s workspace', + (workspaceType) => { + state.canAccessSubscriptionFeatures = false + useBillingCapabilities().canTopUp = computed(() => true) + useBillingCapabilities().canSubscribeSelfServe = computed(() => true) + state.canManageSubscription = true + + renderComponent(workspaceType) + + expect( + screen.getByRole('button', { name: 'Subscribe' }) + ).toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + } + ) + + it('shows no billing action until capabilities resolve', () => { state.canAccessSubscriptionFeatures = false useBillingCapabilities().canTopUp = computed(() => true) useBillingCapabilities().canSubscribeSelfServe = computed(() => true) - state.canManageSubscription = true + useBillingCapabilities().hasResolvedCapabilities = computed(() => false) renderComponent('personal') - expect(screen.getByTestId('add-credits-button')).toBeInTheDocument() expect( - screen.getByRole('button', { name: 'Subscribe' }) + screen.queryByRole('button', { name: 'Subscribe' }) + ).not.toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + }) + + it('shows no billing action on Cloud until the billing status loads', () => { + useBillingCapabilities().canTopUp = computed(() => true) + vi.mocked(useBillingContext()).isInitialized = ref(false) + + renderComponent('personal') + + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + }) + + it('offers Update payment alone, without the add-credits refusal, to a past-due owner', () => { + useBillingCapabilities().topUpDenial = computed(() => 'payment_past_due') + useBillingCapabilities().paymentRecoveryAvailable = + paymentRecoveryAvailableFact(true) + + renderComponent('team') + + expect( + screen.getByRole('button', { name: 'Update payment' }) ).toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + expect( + screen.queryByText('Update your payment method to add credits.') + ).not.toBeInTheDocument() }) it('offers add-credits instead of the upgrade upsell on the Local free tier', () => { @@ -687,8 +730,7 @@ describe('CurrentUserPopoverWorkspace', () => { } ) - it('keeps billing controls and resubscribe available to a promoted owner', async () => { - const user = userEvent.setup() + it('keeps billing controls available to a promoted owner and prefers Add credits over Resubscribe on an ending plan', () => { state.isCancelled = true useBillingCapabilities().canTopUp = computed(() => true) state.canManageSubscription = true @@ -701,6 +743,33 @@ describe('CurrentUserPopoverWorkspace', () => { expect(screen.getByTestId('add-credits-button')).toBeInTheDocument() expect(screen.getByTestId('plans-pricing-menu-item')).toBeInTheDocument() expect(screen.getByTestId('manage-plan-menu-item')).toBeInTheDocument() + expect( + screen.queryByRole('button', { name: 'Resubscribe' }) + ).not.toBeInTheDocument() + }) + + it('offers Resubscribe instead of a disabled Add credits on an ending plan', () => { + state.isCancelled = true + state.canManageSubscriptionLifecycle = true + state.canReactivatePlan = true + useBillingCapabilities().topUpDenial = computed( + () => 'topup_purchases_paused' + ) + + renderComponent('team') + + expect( + screen.getByRole('button', { name: 'Resubscribe' }) + ).toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + }) + + it('opens the pricing table from Resubscribe when the ending plan has no Add credits', async () => { + const user = userEvent.setup() + state.isCancelled = true + state.canManageSubscriptionLifecycle = true + state.canReactivatePlan = true + renderComponent('team') await user.click(screen.getByRole('button', { name: 'Resubscribe' })) diff --git a/src/platform/account/components/CurrentUserPopoverWorkspace.vue b/src/platform/account/components/CurrentUserPopoverWorkspace.vue index dae693e910f..744c14163a7 100644 --- a/src/platform/account/components/CurrentUserPopoverWorkspace.vue +++ b/src/platform/account/components/CurrentUserPopoverWorkspace.vue @@ -95,7 +95,7 @@