From 4267ea3f462c2da0a0806dd8670b749bf6bbd4a9 Mon Sep 17 00:00:00 2001 From: dante01yoon <6510430+dante01yoon@users.noreply.github.com> Date: Mon, 3 Aug 2026 03:40:52 +0000 Subject: [PATCH] fix: keep local credits top-up available Amp-Thread-ID: https://ampcode.com/threads/T-019fc51c-ba4d-72a9-9fc1-18eb9f7c791b Co-authored-by: Amp --- .../tests/dialogs/creditsTile.spec.ts | 54 +++++++++++++++++-- .../components/CreditsTile.test.ts | 19 +++++++ .../subscription/components/CreditsTile.vue | 3 +- .../CurrentUserPopoverWorkspace.test.ts | 22 ++++++++ .../CurrentUserPopoverWorkspace.vue | 4 +- .../dialogService.topUpCredits.test.ts | 17 +++++- src/services/dialogService.ts | 2 +- 7 files changed, 114 insertions(+), 7 deletions(-) diff --git a/browser_tests/tests/dialogs/creditsTile.spec.ts b/browser_tests/tests/dialogs/creditsTile.spec.ts index 726ff769b8e..c83095ed8fe 100644 --- a/browser_tests/tests/dialogs/creditsTile.spec.ts +++ b/browser_tests/tests/dialogs/creditsTile.spec.ts @@ -69,7 +69,11 @@ const mockBillingStatus: BillingStatusResponse = { has_funds: true } -async function mockCloudBoot(page: Page, billingControlEnabled = true) { +async function mockCloudBoot( + page: Page, + billingControlEnabled = true, + subscriptionTier: 'FREE' | 'PRO' = 'PRO' +) { // Frontend-origin boot endpoints (proxied to the backend in production). // `/api/features` is the remote-config source: production builds resolve // workspace availability and the billing UX rollout from it (the `ff:` @@ -134,7 +138,7 @@ async function mockCloudBoot(page: Page, billingControlEnabled = true) { r.fulfill( jsonRoute({ is_active: true, - subscription_tier: 'PRO', + subscription_tier: subscriptionTier, subscription_duration: 'MONTHLY', renewal_date: '2099-02-20T12:00:00Z', end_date: null @@ -148,7 +152,9 @@ async function mockCloudBoot(page: Page, billingControlEnabled = true) { // Workspace billing (flag-on path) — a personal workspace now routes through // `/api/billing/*`. await page.route('**/api/billing/status', (r) => - r.fulfill(jsonRoute(mockBillingStatus)) + r.fulfill( + jsonRoute({ ...mockBillingStatus, subscription_tier: subscriptionTier }) + ) ) await page.route('**/api/billing/balance', (r) => r.fulfill(balanceRoute(DEFAULT_BALANCE)) @@ -322,6 +328,48 @@ test.describe('Credits tile (Plan & Credits)', { tag: '@cloud' }, () => { }) }) +test.describe('Local credits flow', () => { + test('keeps top-up available after the credits settings load a free tier', async ({ + page + }) => { + test.setTimeout(60_000) + + await mockCloudBoot(page, true, 'FREE') + const settingsDialog = await openSettings(page) + await page.keyboard.press('Escape') + await expect(settingsDialog).toBeHidden() + + const topUpDialog = new TopUpCreditsDialog(page) + await page.getByRole('button', { name: 'Current user' }).click() + await page.getByTestId('add-credits-button').click() + await expect(topUpDialog.heading).toBeVisible() + await page.keyboard.press('Escape') + + await page + .getByRole('button', { name: /^Settings/ }) + .first() + .click() + await expect(settingsDialog).toBeVisible() + await settingsDialog + .locator('nav') + .getByRole('button', { name: 'Credits', exact: true }) + .click() + + const creditsPanel = settingsDialog.getByRole('main') + await expect( + creditsPanel.getByRole('heading', { name: 'Credits' }) + ).toBeVisible() + await expect( + creditsPanel.getByRole('button', { name: 'Upgrade to add credits' }) + ).toHaveCount(0) + + await page.keyboard.press('Escape') + await page.getByRole('button', { name: 'Current user' }).click() + await page.getByTestId('add-credits-button').click() + await expect(topUpDialog.heading).toBeVisible() + }) +}) + test.describe('Top-up 3DS verification', { tag: '@cloud' }, () => { test.describe.configure({ timeout: 60_000 }) diff --git a/src/platform/cloud/subscription/components/CreditsTile.test.ts b/src/platform/cloud/subscription/components/CreditsTile.test.ts index a5719d054a7..3e4983145ec 100644 --- a/src/platform/cloud/subscription/components/CreditsTile.test.ts +++ b/src/platform/cloud/subscription/components/CreditsTile.test.ts @@ -18,6 +18,7 @@ type Subscription = Pick & { type TeamStop = CurrentTeamCreditStop const state = vi.hoisted(() => ({ + isCloud: true, balance: null as Balance | null, subscription: null as Subscription | null, isActiveSubscription: false, @@ -33,6 +34,12 @@ const state = vi.hoisted(() => ({ toastErrorHandler: vi.fn() })) +vi.mock('@/platform/distribution/types', () => ({ + get isCloud() { + return state.isCloud + } +})) + vi.mock('@/composables/useErrorHandling', () => ({ useErrorHandling: () => ({ wrapWithErrorHandlingAsync: @@ -159,6 +166,7 @@ function activeProSubscription() { describe('CreditsTile', () => { beforeEach(() => { + state.isCloud = true state.balance = null state.subscription = null state.isActiveSubscription = false @@ -376,6 +384,17 @@ describe('CreditsTile', () => { expect(state.showPricingTable).toHaveBeenCalledOnce() }) + it('offers add-credits to local free-tier users', async () => { + activeProSubscription() + state.isCloud = false + state.isFreeTier = true + renderTile() + + expect(screen.queryByText('Upgrade to add credits')).toBeNull() + await userEvent.click(screen.getByText('Add credits')) + expect(state.showTopUpCreditsDialog).toHaveBeenCalledOnce() + }) + it('hides the action button when the user lacks the top-up permission', () => { activeProSubscription() state.canTopUp = false diff --git a/src/platform/cloud/subscription/components/CreditsTile.vue b/src/platform/cloud/subscription/components/CreditsTile.vue index 78a84ff88a6..23f7485020c 100644 --- a/src/platform/cloud/subscription/components/CreditsTile.vue +++ b/src/platform/cloud/subscription/components/CreditsTile.vue @@ -188,7 +188,7 @@