diff --git a/src/platform/account/components/dialogs/settings/BillingTab.test.ts b/src/platform/account/components/dialogs/settings/BillingTab.test.ts index 95f08fb2b27..906f7933af7 100644 --- a/src/platform/account/components/dialogs/settings/BillingTab.test.ts +++ b/src/platform/account/components/dialogs/settings/BillingTab.test.ts @@ -1068,17 +1068,74 @@ describe('BillingTab', () => { arrange(scenario) } - it('shows Plan ending with the plan row keeping the actions', () => { + it('shows Plan ending with Resume plan on both the banner and the plan row', () => { arrangeOnCloud(ending) const banner = screen.getByRole('status') expect(banner).toHaveTextContent( 'Your Pro plan ends on October 28, 2026' ) - expect(within(banner).queryAllByRole('button')).toEqual([]) expect( - screen.getByRole('button', { name: 'Resume plan' }) - ).toBeInTheDocument() + within(banner) + .queryAllByRole('button') + .map((button) => button.textContent.trim()) + ).toEqual(['Resume plan']) + expect( + screen.getAllByRole('button', { name: 'Resume plan' }) + ).toHaveLength(2) + }) + + const ended: Scenario = { + subscription: { + ...activeSubscription, + isActive: false, + endDate: '2026-09-01T00:00:00Z' + }, + subscriptionStatus: 'ended' + } + + it('shows Plan ended with Choose a plan as the white button on both the banner and the plan row', async () => { + arrangeOnCloud(ended) + + const bannerLink = within(screen.getByRole('status')).getByRole( + 'link', + { name: 'Choose a plan' } + ) + const plansLink = { + variant: 'inverted', + href: expect.stringMatching( + /^https:\/\/platform\.test\/profile\/billing\/plans\?workspace=ws_1&correlation_id=.+$/ + ) + } + expect( + screen + .getAllByRole('link', { name: 'Choose a plan' }) + .map((link) => ({ + variant: link.dataset.variant, + href: link.getAttribute('href') + })) + ).toEqual([plansLink, plansLink]) + bannerLink.addEventListener('click', (event) => event.preventDefault()) + + await userEvent.click(bannerLink) + + expect( + vi.mocked(useTelemetry)()?.trackBillingEvent + ).toHaveBeenCalledWith( + expect.objectContaining({ + operation: 'platform_handoff', + target: 'plans' + }) + ) + }) + + it('shows Plan ended without Choose a plan when the server withholds can_open_plans', () => { + arrangeOnCloud({ ...ended, canOpenPlans: false }) + + expect(screen.getByRole('status')).toBeInTheDocument() + expect( + screen.queryByRole('link', { name: 'Choose a plan' }) + ).not.toBeInTheDocument() }) it('shows no lifecycle banner on an active plan', () => { @@ -1465,18 +1522,29 @@ describe('BillingTab', () => { isCloud: true, choosePlan: 'inverted', addCredits: 'secondary', - planEndedBanners: 1 + planEndedBanners: 1, + choosePlanLinks: 2, + whiteActions: 2 }, { surface: 'local ComfyUI', isCloud: false, choosePlan: 'secondary', addCredits: 'inverted', - planEndedBanners: 0 + planEndedBanners: 0, + choosePlanLinks: 1, + whiteActions: 1 } ])( - 'keeps one white button on $surface when an ended plan is out of credits', - async ({ isCloud, choosePlan, addCredits, planEndedBanners }) => { + 'keeps one white action on $surface when an ended plan is out of credits', + async ({ + isCloud, + choosePlan, + addCredits, + planEndedBanners, + choosePlanLinks, + whiteActions + }) => { distribution.isCloud = isCloud onTestFinished(() => { distribution.isCloud = false @@ -1488,9 +1556,12 @@ describe('BillingTab', () => { }) await screen.findByTestId('billing-auto-top-up-status') - expect( - screen.getByRole('link', { name: 'Choose a plan' }) - ).toHaveAttribute('data-variant', choosePlan) + const choosePlanVariants = screen + .getAllByRole('link', { name: 'Choose a plan' }) + .map((link) => link.dataset.variant) + expect(choosePlanVariants).toEqual( + Array(choosePlanLinks).fill(choosePlan) + ) expect(addCreditsVariants()).toEqual([addCredits]) expect(screen.queryAllByText(/^Your .*plan has ended$/)).toHaveLength( planEndedBanners @@ -1500,7 +1571,7 @@ describe('BillingTab', () => { ...screen.queryAllByRole('button'), ...screen.queryAllByRole('link') ].filter((el) => el.dataset.variant === 'inverted') - ).toHaveLength(1) + ).toHaveLength(whiteActions) } ) diff --git a/src/platform/billing/components/settings/BillingStatusBanner.stories.ts b/src/platform/billing/components/settings/BillingStatusBanner.stories.ts index e8c35cb8340..47a4d260e79 100644 --- a/src/platform/billing/components/settings/BillingStatusBanner.stories.ts +++ b/src/platform/billing/components/settings/BillingStatusBanner.stories.ts @@ -5,6 +5,7 @@ import { i18n } from '@/i18n' import type { BillingContextMockState } from '@/storybook/mocks/useBillingContext' import { setBillingContextMock } from '@/storybook/mocks/useBillingContext' import { + setBillingCapabilitiesMock, setCanSubscribeSelfServeMock, setCanTopUpMock } from '@/storybook/mocks/useBillingCapabilities' @@ -30,7 +31,13 @@ import BillingStatusBanner from './BillingStatusBanner.vue' const meta: Meta = { title: 'Platform/Workspace/BillingStatusBanner', component: BillingStatusBanner, - parameters: { layout: 'fullscreen' } + parameters: { layout: 'fullscreen' }, + argTypes: { + section: { + control: 'select', + options: ['planCredits', 'members', 'allowlist', 'billing'] + } + } } export default meta @@ -69,17 +76,30 @@ const member: Partial = { function story( billing: Partial, workspace: Partial, - capabilities: { canTopUp?: boolean; canSubscribeSelfServe?: boolean } = {} + capabilities: { + canTopUp?: boolean + canSubscribeSelfServe?: boolean + canOpenPlans?: boolean + } = {} ): Story { + const canManageSubscription = workspace.canManageSubscription ?? true + const served = { + canTopUp: true, + canSubscribeSelfServe: false, + canOpenPlans: canManageSubscription, + ...capabilities + } return { beforeEach() { - // Dates in the copy go through vue-i18n's `d()`, so pin the locale rather - // than inherit the developer's. i18n.global.locale.value = 'en' setBillingContextMock({ isTeamPlan: true, ...billing }) setWorkspaceUIMock(workspace) - setCanTopUpMock(capabilities.canTopUp ?? true) - setCanSubscribeSelfServeMock(capabilities.canSubscribeSelfServe ?? false) + setBillingCapabilitiesMock({ + canManageSubscription, + canOpenPlans: served.canOpenPlans + }) + setCanTopUpMock(served.canTopUp) + setCanSubscribeSelfServeMock(served.canSubscribeSelfServe) } } } diff --git a/src/platform/billing/components/settings/BillingStatusBanner.test.ts b/src/platform/billing/components/settings/BillingStatusBanner.test.ts index c0f4978bef3..4b8783d883c 100644 --- a/src/platform/billing/components/settings/BillingStatusBanner.test.ts +++ b/src/platform/billing/components/settings/BillingStatusBanner.test.ts @@ -5,6 +5,7 @@ import { canManageBillingFact, runDeniedPaymentPastDueFact } from '@/platform/billing/composables/__mocks__/useBillingCapabilities' +import { receiveServerFact } from '@/platform/serverFacts/serverFact' import userEvent from '@testing-library/user-event' import { render, screen, within } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -47,8 +48,7 @@ const state = vi.hoisted(() => ({ manageSubscription: vi.fn( async (): Promise => ({ ok: true }) ), - handleResubscribe: vi.fn(), - showSubscriptionDialog: vi.fn() + handleResubscribe: vi.fn() })) vi.mock( @@ -111,12 +111,30 @@ vi.mock(import('@/platform/billing/composables/useResubscribe'), () => ({ vi.mock(import('@/platform/billing/composables/useBillingDialogs')) -vi.mock( - import('@/platform/billing/subscription/composables/useSubscriptionDialog'), - () => ({ - useSubscriptionDialog: () => ({ show: state.showSubscriptionDialog }) +vi.mock(import('@/platform/workspace/utils/platformLink'), () => ({ + platformLink: (path: `/${string}`, correlationId?: string) => + `https://platform.test${path}?correlation_id=${correlationId}` +})) + +function grantOpenPlans(granted: boolean) { + useBillingCapabilities().canOpenPlans = computed(() => + receiveServerFact('can_open_plans', granted) + ) +} + +function expectChoosePlanLink() { + const link = within(screen.getByRole('status')).getByRole('link', { + name: 'Choose a plan' }) -) + expect(link).toHaveAttribute( + 'href', + expect.stringMatching( + /^https:\/\/platform\.test\/profile\/billing\/plans\?correlation_id=.+$/ + ) + ) + expect(link).toHaveAttribute('target', '_blank') + expect(link).toHaveAttribute('data-variant', 'inverted') +} const i18n = createI18n({ legacy: false, @@ -133,8 +151,8 @@ const i18n = createI18n({ } }, workspacePanel: { + billingTab: { plan: { actions: { choosePlan: 'Choose a plan' } } }, members: { - resubscribe: 'Resubscribe', endedTeamTitle: 'Your Team plan has ended', endedEnterpriseTitle: 'Your Enterprise plan has ended', endedPlanTitle: 'Your plan has ended' @@ -320,7 +338,8 @@ describe('BillingStatusBanner', () => { endDate: '2026-10-28T00:00:00Z' } }, - text: 'Your Team plan ends on' + text: 'Your Team plan ends on', + buttons: ['Resume plan'] }, { name: 'a scheduled change while out of credits', @@ -328,7 +347,8 @@ describe('BillingStatusBanner', () => { scheduledFor('pro-annual') state.subscription = { ...state.subscription!, hasFunds: false } }, - text: 'Your plan changes to' + text: 'Your plan changes to', + buttons: [] }, { name: 'plan ending while out of credits', @@ -340,7 +360,8 @@ describe('BillingStatusBanner', () => { endDate: '2026-10-28T00:00:00Z' } }, - text: 'Your Team plan ends on' + text: 'Your Team plan ends on', + buttons: ['Resume plan'] }, { name: 'plan ended', @@ -356,16 +377,24 @@ describe('BillingStatusBanner', () => { tier: 'PRO' } }, - text: 'Your Team plan ended on September 12, 2026' + text: 'Your Team plan ended on September 12, 2026', + buttons: [] } - ])('shows $name with no buttons', ({ enter, text }) => { - enter() - renderBanner('billing') - - const banner = screen.getByRole('status') - expect(banner).toHaveTextContent(text) - expect(within(banner).queryAllByRole('button')).toEqual([]) - }) + ])( + 'shows $name with its plan action and no Dismiss', + ({ enter, text, buttons }) => { + enter() + renderBanner('billing') + + const banner = screen.getByRole('status') + expect(banner).toHaveTextContent(text) + expect( + within(banner) + .queryAllByRole('button') + .map((button) => button.textContent.trim()) + ).toEqual(buttons) + } + ) it.for([ { @@ -398,6 +427,23 @@ describe('BillingStatusBanner', () => { expect(screen.getByRole('status')).toBeInTheDocument() }) + it('hides Resume plan when the server withholds it', () => { + state.subscription = { + ...state.subscription!, + isCancelled: true, + endDate: '2026-10-28T00:00:00Z' + } + state.canReactivatePlan = false + renderBanner('billing') + + expect(screen.getByRole('status')).toHaveTextContent( + 'Your Team plan ends on' + ) + expect( + screen.queryByRole('button', { name: 'Resume plan' }) + ).not.toBeInTheDocument() + }) + it.for([ { name: 'out of credits', enter: exhausted }, { name: 'paused', enter: pausedState } @@ -984,18 +1030,33 @@ describe('BillingStatusBanner', () => { } } - it('lets a team owner resubscribe through the pricing table', async () => { - endedPlan() - renderBanner() + it.for(['members', 'billing'] as const)( + 'offers Choose a plan on the %s tab when the server grants can_open_plans', + (section) => { + endedPlan() + grantOpenPlans(true) + renderBanner(section) - expect(screen.getByRole('status')).toHaveTextContent( - 'Your Team plan ended on September 12, 2026' - ) - await userEvent.click(screen.getByRole('button', { name: 'Resubscribe' })) - expect(state.showSubscriptionDialog).toHaveBeenCalledWith( - expect.objectContaining({ planMode: 'team' }) - ) - }) + expect(screen.getByRole('status')).toHaveTextContent( + 'Your Team plan ended on September 12, 2026' + ) + expectChoosePlanLink() + } + ) + + it.for(['members', 'billing'] as const)( + 'offers no Choose a plan on the %s tab when the server withholds can_open_plans', + (section) => { + endedPlan() + grantOpenPlans(false) + renderBanner(section) + + expect(screen.getByRole('status')).toBeInTheDocument() + expect( + screen.queryByRole('link', { name: 'Choose a plan' }) + ).not.toBeInTheDocument() + } + ) it('points a team member to the owner', () => { endedPlan() @@ -1006,13 +1067,16 @@ describe('BillingStatusBanner', () => { 'Ask your workspace owner to resubscribe.' ) expect( - screen.queryByRole('button', { name: 'Resubscribe' }) + screen.queryByRole('link', { name: 'Choose a plan' }) ).not.toBeInTheDocument() }) it('sends an Enterprise owner to sales', async () => { endedPlan('ENTERPRISE') state.isTeamPlan = false + useBillingCapabilities().planKind = computed(() => + receiveServerFact('plan_kind', 'sales_managed') + ) const open = vi.spyOn(window, 'open').mockReturnValue(null) renderBanner() @@ -1030,6 +1094,25 @@ describe('BillingStatusBanner', () => { open.mockRestore() }) + it.for(['members', 'billing'] as const)( + 'offers Contact sales instead of Choose a plan on the %s tab when the server serves plan_kind sales_managed', + (section) => { + endedPlan('PRO') + grantOpenPlans(true) + useBillingCapabilities().planKind = computed(() => + receiveServerFact('plan_kind', 'sales_managed') + ) + renderBanner(section) + + expect( + screen.getByRole('button', { name: 'Contact sales' }) + ).toBeInTheDocument() + expect( + screen.queryByRole('link', { name: 'Choose a plan' }) + ).not.toBeInTheDocument() + } + ) + it('dismisses for the session', async () => { endedPlan() renderBanner() @@ -1226,22 +1309,18 @@ describe('BillingStatusBanner', () => { }, { endDate: null, title: 'Your Creator plan has ended' } ])( - 'tells an ended personal plan "$title" and resubscribes on Personal plans', - async ({ endDate, title }) => { + 'tells an ended personal plan "$title" and offers Choose a plan', + ({ endDate, title }) => { personalPlan('CREATOR') endedPlan(endDate) + grantOpenPlans(true) renderBanner() expect(screen.getByRole('status')).toHaveTextContent(title) expect(screen.getByRole('status')).toHaveTextContent( 'Resubscribe to run workflows and get monthly credits again.' ) - await userEvent.click( - screen.getByRole('button', { name: 'Resubscribe' }) - ) - expect(state.showSubscriptionDialog).toHaveBeenCalledWith( - expect.objectContaining({ planMode: 'personal' }) - ) + expectChoosePlanLink() } ) diff --git a/src/platform/billing/components/settings/BillingStatusBanner.vue b/src/platform/billing/components/settings/BillingStatusBanner.vue index 18d5fe19b6f..0081dae6f3b 100644 --- a/src/platform/billing/components/settings/BillingStatusBanner.vue +++ b/src/platform/billing/components/settings/BillingStatusBanner.vue @@ -48,12 +48,18 @@ {{ $t('workspacePanel.billingStatus.ending.reactivate') }}