Skip to content
Merged
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
4 changes: 3 additions & 1 deletion packages/account-ui/src/billing/tab/BillingBanner.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export const PlanStatus: Story = {
view: {
kind: 'planStatus',
title: 'Your Team plan ends on November 20, 2026',
body: "You won't be charged again. Members keep full access until then. Resume your plan to keep your team's shared credits."
body: "You won't be charged again. Members keep full access until then. Resume your plan to keep your team's shared credits.",
action: 'resumePlan',
href: null
}
}
}
Expand Down
24 changes: 21 additions & 3 deletions packages/account-ui/src/billing/tab/BillingBanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('BillingBanner', () => {
},
{
case: 'a plan status',
view: { kind: 'planStatus', ...text },
view: { kind: 'planStatus', ...text, action: null, href: null },
controls: [],
icon: 'text-muted-foreground',
shell: ['rounded-2xl', 'p-4']
Expand Down Expand Up @@ -168,9 +168,24 @@ describe('BillingBanner', () => {
},
role: 'link',
name: 'Contact support'
},
{
view: { kind: 'planStatus', ...text, action: 'resumePlan', href: null },
role: 'button',
name: 'Resume plan'
},
{
view: {
kind: 'planStatus',
...text,
action: 'choosePlan',
href: 'https://platform.test/profile/billing/plans'
},
role: 'link',
name: 'Choose a plan'
}
])(
'emits the $view.kind action instead of performing it',
'emits the $view.kind $view.action action instead of performing it',
async ({ view, role, name }) => {
const { onAction } = renderBanner(view)
const control = screen.getByRole(role, { name })
Expand Down Expand Up @@ -209,7 +224,10 @@ describe('BillingBanner', () => {
},
row: 'sm:flex-row'
},
{ view: { kind: 'planStatus', ...text }, row: '@2xl:flex-row' },
{
view: { kind: 'planStatus', ...text, action: null, href: null },
row: '@2xl:flex-row'
},
{
view: {
kind: 'topupCheckout',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export const billingBannerCopy: BillingBannerCopy = {
addCredits: 'Add credits',
updatePayment: 'Update payment',
verifyPayment: 'Complete verification',
contactSupport: 'Contact support'
contactSupport: 'Contact support',
resumePlan: 'Resume plan',
choosePlan: 'Choose a plan',
contactSales: 'Contact sales'
},
planCheckout: {
verifyPayment: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const views: Record<BillingBannerKind, BillingBannerView> = {
action: 'contactSupport',
href: 'https://comfy.org/contact/'
},
planStatus: { kind: 'planStatus', ...text },
planStatus: { kind: 'planStatus', ...text, action: null, href: null },
autoTopUp: {
kind: 'autoTopUp',
...text,
Expand Down
11 changes: 9 additions & 2 deletions packages/account-ui/src/billing/tab/billingBannerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type BillingBannerAction =
| 'updatePayment'
| 'verifyPayment'
| 'contactSupport'
| 'resumePlan'
| 'choosePlan'
| 'contactSales'

export interface BillingBannerText {
readonly title: string
Expand Down Expand Up @@ -40,7 +43,11 @@ export type BillingBannerView = BillingBannerText &
readonly action: 'contactSupport'
readonly href: string
}
| { readonly kind: 'planStatus' }
| {
readonly kind: 'planStatus'
readonly action: 'resumePlan' | 'choosePlan' | 'contactSales' | null
readonly href: string | null
}
| {
readonly kind: 'autoTopUp'
readonly action: 'updatePayment'
Expand Down Expand Up @@ -150,7 +157,7 @@ export function billingBannerLook(view: BillingBannerView): BillingBannerLook {
windowBreakpoint: true
}
case 'planStatus':
return look(true, true, null)
return look(true, true, view.action, view.href)
case 'autoTopUp':
return look(false, false, view.action, view.href)
case 'credit':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,17 +1073,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', () => {
Expand Down Expand Up @@ -1470,18 +1527,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
Expand All @@ -1493,9 +1561,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
Expand All @@ -1505,7 +1576,7 @@ describe('BillingTab', () => {
...screen.queryAllByRole('button'),
...screen.queryAllByRole('link')
].filter((el) => el.dataset.variant === 'inverted')
).toHaveLength(1)
).toHaveLength(whiteActions)
}
)

Expand Down Expand Up @@ -2037,7 +2108,7 @@ describe('BillingTab banner stack parity with selectBillingBanners', () => {
action: 'contactSupport',
href: 'https://comfy.org/contact/'
},
planStatus: { kind: 'planStatus', ...text },
planStatus: { kind: 'planStatus', ...text, action: null, href: null },
autoTopUp: {
kind: 'autoTopUp',
...text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const copy: BillingBannerCopy = {
addCredits: t('workspacePanel.billingTab.credits.addCredits'),
updatePayment: t(`${bs}.updatePayment`),
verifyPayment: t(`${bs}.planCheckout.verifyPayment.action`),
contactSupport: t(`${bs}.parked.contactSupport`)
contactSupport: t(`${bs}.parked.contactSupport`),
resumePlan: t(`${bs}.ending.reactivate`),
choosePlan: t('workspacePanel.billingTab.plan.actions.choosePlan'),
contactSales: t(`${bs}.ending.contactSales`)
},
planCheckout: {
verifyPayment: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ const copy: Pick<BillingBannerCopy, 'dismiss' | 'actions'> = {
addCredits: t(`${bs}.outOfCredits.addCredits`),
updatePayment: t(`${bs}.updatePayment`),
verifyPayment: t(`${bs}.planCheckout.verifyPayment.action`),
contactSupport: t(`${bs}.parked.contactSupport`)
contactSupport: t(`${bs}.parked.contactSupport`),
resumePlan: t(`${bs}.ending.reactivate`),
choosePlan: t('workspacePanel.billingTab.plan.actions.choosePlan'),
contactSales: t(`${bs}.ending.contactSales`)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ const copy: Pick<BillingBannerCopy, 'dismiss' | 'actions'> = {
addCredits: t(`${bs}.outOfCredits.addCredits`),
updatePayment: t(`${bs}.updatePayment`),
verifyPayment: t(`${bs}.planCheckout.verifyPayment.action`),
contactSupport: t(`${bs}.parked.contactSupport`)
contactSupport: t(`${bs}.parked.contactSupport`),
resumePlan: t(`${bs}.ending.reactivate`),
choosePlan: t('workspacePanel.billingTab.plan.actions.choosePlan'),
contactSales: t(`${bs}.ending.contactSales`)
}
}

Expand Down Expand Up @@ -173,12 +176,14 @@ describe('BillingBanner parity with the Billing tab plan status banner', () => {
enter: () => void
title: () => string
body: () => string
action?: 'resumePlan' | 'choosePlan' | 'contactSales'
}>([
{
case: 'a team plan ending',
enter: () => ending(),
title: () => t(`${bs}.ending.title`, { date: 'October 28, 2026' }),
body: () => t(`${bs}.ending.body`)
body: () => t(`${bs}.ending.body`),
action: 'resumePlan'
},
{
case: 'a team plan ending, for a member',
Expand All @@ -200,7 +205,8 @@ describe('BillingBanner parity with the Billing tab plan status banner', () => {
plan: 'Pro',
date: 'October 28, 2026'
}),
body: () => t(`${bs}.ending.personalBody`)
body: () => t(`${bs}.ending.personalBody`),
action: 'resumePlan'
},
{
case: 'an Enterprise plan ending inside the notice window',
Expand All @@ -211,7 +217,8 @@ describe('BillingBanner parity with the Billing tab plan status banner', () => {
},
title: () =>
t(`${bs}.ending.enterpriseTitle`, { date: 'October 28, 2026' }),
body: () => t(`${bs}.ending.enterpriseBody`)
body: () => t(`${bs}.ending.enterpriseBody`),
action: 'contactSales'
},
{
case: 'a scheduled plan change',
Expand Down Expand Up @@ -261,7 +268,7 @@ describe('BillingBanner parity with the Billing tab plan status banner', () => {
}),
body: () => t(`${bs}.planEnded.personalBody`)
}
])('renders $case the same', ({ enter, title, body }) => {
])('renders $case the same', ({ enter, title, body, action = null }) => {
enter()
const app = render(BillingStatusBanner, {
props: { section: 'billing' },
Expand All @@ -272,7 +279,13 @@ describe('BillingBanner parity with the Billing tab plan status banner', () => {

const pkg = render(BillingBanner, {
props: {
view: { kind: 'planStatus', title: title(), body: body() },
view: {
kind: 'planStatus',
title: title(),
body: body(),
action,
href: null
},
copy
}
})
Expand Down
Loading
Loading