Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions browser_tests/tests/currentUserPopoverCredits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ({
Expand Down
5 changes: 4 additions & 1 deletion browser_tests/tests/workspaceSwitcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => ({
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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
Expand All @@ -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' }))

Expand Down
34 changes: 29 additions & 5 deletions src/platform/account/components/CurrentUserPopoverWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<i class="icon-[lucide--circle-help]" />
</Button>
<Button
v-if="addCredits.kind !== 'hidden'"
v-if="creditsRowAction === 'addCredits'"
variant="secondary"
size="sm"
data-testid="add-credits-button"
Expand All @@ -107,7 +107,7 @@
{{ $t('subscription.addCredits') }}
</Button>
<Button
v-if="paymentRecoveryAvailable"
v-if="creditsRowAction === 'updatePayment'"
variant="secondary"
size="sm"
:loading="isUpdatingPayment"
Expand All @@ -116,7 +116,7 @@
{{ $t('workspacePanel.billingStatus.updatePayment') }}
</Button>
<SubscribeButton
v-if="showSubscribeAction && isPersonalWorkspace"
v-if="creditsRowAction === 'planAction' && isPersonalWorkspace"
:fluid="false"
:label="
isCancelled
Expand All @@ -127,7 +127,7 @@
button-variant="subscribe"
/>
<Button
v-if="showSubscribeAction && !isPersonalWorkspace"
v-if="creditsRowAction === 'planAction' && !isPersonalWorkspace"
variant="primary"
size="sm"
@click="handleOpenSubscriptionAction"
Expand Down Expand Up @@ -355,6 +355,7 @@ const {
subscription,
balance,
isLoading,
isInitialized: isBillingInitialized,
fetchBalance
} = useBillingContext()

Expand All @@ -363,7 +364,10 @@ const subscriptionDialog = useSubscriptionDialog()

const { locale, t } = useI18n()
const refusalReason = computed(() =>
addCredits.value.kind === 'disabled' ? t(addCredits.value.reasonKey) : null
creditsRowAction.value === 'addCredits' &&
addCredits.value.kind === 'disabled'
? t(addCredits.value.reasonKey)
: null
)
const isLoadingBalance = isLoading

Expand Down Expand Up @@ -414,6 +418,26 @@ const showSubscribeAction = computed(
canTopUp.value))
)

type CreditsRowAction = 'updatePayment' | 'planAction' | 'addCredits'

function pickCreditsRowAction(): CreditsRowAction | null {
if (paymentRecoveryAvailable.value) return 'updatePayment'
if (!showSubscribeAction.value) {
return addCredits.value.kind === 'hidden' ? null : 'addCredits'
}
if (!canAccessSubscriptionFeatures.value) return 'planAction'
return addCredits.value.kind === 'enabled' ? 'addCredits' : 'planAction'
}

const isBillingLoading = computed(
() =>
!hasResolvedCapabilities.value || (isCloud && !isBillingInitialized.value)
)

const creditsRowAction = computed((): CreditsRowAction | null =>
isBillingLoading.value ? null : pickCreditsRowAction()
)

const handleOpenUserSettings = () => {
settingsDialog.show('user')
emit('close')
Expand Down
Loading