From 4c8545ff55affe4e9d2a180be5082ca8a7f4922f Mon Sep 17 00:00:00 2001 From: Maanil Verma Date: Wed, 19 Aug 2026 22:17:11 +0530 Subject: [PATCH 1/5] feat(billing): show load, error, and empty states for local plans --- src/locales/en/main.json | 1 + .../settings/SettingsPlansSection.test.ts | 62 ++- .../dialogs/settings/SettingsPlansSection.vue | 456 ++++++++++-------- 3 files changed, 311 insertions(+), 208 deletions(-) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 08ed194146c..1bc9cabae33 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -2638,6 +2638,7 @@ "comingProjects": "Projects", "enterpriseCopy": "Need more members? Looking for more flexibility or custom features?", "contactUs": "Contact us", + "noPlansAvailable": "No plans are available right now. Check back soon.", "checkoutCaption": "Checkout happens right here: payment details handled securely by Stripe. Prefer no plan? Keep topping up, anytime." }, "credits": { diff --git a/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.test.ts b/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.test.ts index 0f3fa9d9dfe..a4d08cf7d77 100644 --- a/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.test.ts +++ b/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.test.ts @@ -28,7 +28,12 @@ vi.mock('@/composables/billing/useBillingContext', () => ({ useBillingContext: () => ({ fetchPlans: mockFetchPlans, plans: mockCatalogPlans, - currentPlanSlug: mockCurrentPlanSlug + currentPlanSlug: mockCurrentPlanSlug, + // Deliberately inert: these track the legacy activeContext refresh, so the + // fetch-state tests fail if the section reads them instead of the + // useBillingPlans singleton. + isLoading: { value: false }, + error: { value: null } }) })) @@ -98,8 +103,11 @@ function renderSection() { describe('SettingsPlansSection', () => { beforeEach(() => { - useBillingPlans().teamCreditStops.value = null - mockCatalogPlans.value = [] + const billingPlans = useBillingPlans() + billingPlans.teamCreditStops.value = null + billingPlans.isLoading.value = false + billingPlans.error.value = null + mockCatalogPlans.value = yearlyCatalog() mockCurrentPlanSlug.value = null mockFetchPlans.mockReset() mockSubscribeToPersonal.mockReset() @@ -310,4 +318,52 @@ describe('SettingsPlansSection', () => { screen.getByRole('button', { name: 'Subscribe to Team Monthly' }) ).toBeEnabled() }) + + it('renders skeletons and no cards while the catalog is loading', () => { + mockCatalogPlans.value = [] + useBillingPlans().isLoading.value = true + renderSection() + + expect(screen.getByTestId('plans-skeleton')).toBeTruthy() + expect(screen.queryByRole('button', { name: 'Choose Standard' })).toBeNull() + }) + + it('shows the load error with a retry that re-dispatches the fetch', async () => { + mockCatalogPlans.value = [] + useBillingPlans().error.value = 'network down' + renderSection() + + expect(screen.getByText("We couldn't load your plan details.")).toBeTruthy() + expect(screen.queryByRole('button', { name: 'Choose Standard' })).toBeNull() + + await userEvent.click(screen.getByRole('button', { name: 'Try again' })) + expect(mockFetchPlans).toHaveBeenCalledTimes(2) + }) + + it('shows the dedicated empty state when the catalog loads empty', () => { + mockCatalogPlans.value = [] + renderSection() + + expect( + screen.getByText('No plans are available right now. Check back soon.') + ).toBeTruthy() + expect(screen.queryByText("We couldn't load your plan details.")).toBeNull() + expect(screen.queryByRole('button', { name: 'Choose Standard' })).toBeNull() + }) + + it('keeps cached cards rendered through a refetch and a refetch failure', () => { + useBillingPlans().isLoading.value = true + const { unmount } = renderSection() + + expect(screen.getByRole('button', { name: 'Choose Standard' })).toBeTruthy() + expect(screen.queryByTestId('plans-skeleton')).toBeNull() + unmount() + + useBillingPlans().isLoading.value = false + useBillingPlans().error.value = 'refetch failed' + renderSection() + + expect(screen.getByRole('button', { name: 'Choose Standard' })).toBeTruthy() + expect(screen.queryByText("We couldn't load your plan details.")).toBeNull() + }) }) diff --git a/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.vue b/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.vue index 5acb973a529..a9fb287ec2a 100644 --- a/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.vue +++ b/src/platform/workspace/components/dialogs/settings/SettingsPlansSection.vue @@ -1,5 +1,8 @@