test(cloud): plan entry points open the plans dialog

This commit is contained in:
Neil
2026-11-14 16:51:57 -08:00
parent 756a89c83f
commit 7b7f4e26d2
3 changed files with 21 additions and 20 deletions
@@ -19,9 +19,9 @@ vi.mock('@/components/ui/popover', () => ({
PopoverContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>
}))
const openCloudConsole = vi.fn()
vi.mock('@/lib/orca-cloud/open-cloud-console', () => ({
openCloudConsole: (source: string) => openCloudConsole(source)
const openPlansDialog = vi.fn()
vi.mock('@/components/billing/plans/plans-dialog-store', () => ({
openPlansDialog: () => openPlansDialog()
}))
const hosts: ProjectHostSetupOption[] = [
@@ -101,7 +101,7 @@ function render(
}
beforeEach(() => {
openCloudConsole.mockClear()
openPlansDialog.mockClear()
resetOrcaCloudBillingCache()
container = document.createElement('div')
document.body.appendChild(container)
@@ -133,7 +133,7 @@ describe('RunTargetCombobox', () => {
expect(activeText()).toContain('Orca Cloud')
press('Enter')
expect(onRecipeChange).toHaveBeenCalledWith('cloud')
expect(openCloudConsole).not.toHaveBeenCalled()
expect(openPlansDialog).not.toHaveBeenCalled()
})
it('opens the plans page instead of building when there is no plan', () => {
@@ -141,7 +141,7 @@ describe('RunTargetCombobox', () => {
render({ state: 'no-plan', lapsed: false, canManageBilling: true }, onRecipeChange)
press('ArrowDown')
press('Enter')
expect(openCloudConsole).toHaveBeenCalledWith('billing')
expect(openPlansDialog).toHaveBeenCalledTimes(1)
expect(onRecipeChange).not.toHaveBeenCalled()
})
@@ -152,7 +152,7 @@ describe('RunTargetCombobox', () => {
expect(container.textContent).not.toContain('Upgrade')
press('ArrowDown')
press('Enter')
expect(openCloudConsole).not.toHaveBeenCalled()
expect(openPlansDialog).not.toHaveBeenCalled()
expect(onRecipeChange).not.toHaveBeenCalled()
})
@@ -230,11 +230,11 @@ describe('RunTargetCombobox', () => {
press('ArrowDown')
press('Enter')
expect(onRecipeChange).not.toHaveBeenCalled()
expect(openCloudConsole).not.toHaveBeenCalled()
expect(openPlansDialog).not.toHaveBeenCalled()
await act(async () => answer(NO_PLAN))
expect(openCloudConsole).toHaveBeenCalledWith('billing')
expect(openPlansDialog).toHaveBeenCalledTimes(1)
expect(onRecipeChange).not.toHaveBeenCalled()
})
@@ -247,7 +247,7 @@ describe('RunTargetCombobox', () => {
await act(async () => answer(NO_PLAN))
expect(openCloudConsole).not.toHaveBeenCalled()
expect(openPlansDialog).not.toHaveBeenCalled()
})
it('does nothing when a member who cannot fix the block picks Orca Cloud', () => {
@@ -261,7 +261,7 @@ describe('RunTargetCombobox', () => {
).toBe('true')
press('Enter')
expect(onRecipeChange).not.toHaveBeenCalled()
expect(openCloudConsole).not.toHaveBeenCalled()
expect(openPlansDialog).not.toHaveBeenCalled()
})
it('jumps to the ends of the list with Home and End', () => {
@@ -6,9 +6,9 @@ import {
orcaCloudCanStart
} from './orca-cloud-run-target-access'
const openCloudConsole = vi.fn()
vi.mock('@/lib/orca-cloud/open-cloud-console', () => ({
openCloudConsole: (section: string) => openCloudConsole(section)
const openPlansDialog = vi.fn()
vi.mock('@/components/billing/plans/plans-dialog-store', () => ({
openPlansDialog: () => openPlansDialog()
}))
function denied(
@@ -29,7 +29,7 @@ function denied(
describe('Orca Cloud run-target access by role', () => {
beforeEach(() => {
openCloudConsole.mockReset()
openPlansDialog.mockReset()
})
it('carries the role on no plan, so members are not sent to plans they cannot buy', () => {
@@ -38,7 +38,7 @@ describe('Orca Cloud run-target access by role', () => {
expect(owner).toEqual({ state: 'no-plan', lapsed: false, canManageBilling: true })
expect(member).toEqual({ state: 'no-plan', lapsed: true, canManageBilling: false })
expect(getOrcaCloudPick(member)).toEqual({ kind: 'blocked' })
expect(openCloudConsole).not.toHaveBeenCalled()
expect(openPlansDialog).not.toHaveBeenCalled()
})
it('sends an owner or admin to billing in the browser', () => {
@@ -47,7 +47,7 @@ describe('Orca Cloud run-target access by role', () => {
if (pick.kind === 'act') {
pick.run()
}
expect(openCloudConsole).toHaveBeenCalledWith('billing')
expect(openPlansDialog).toHaveBeenCalledTimes(1)
})
it('blocks members at the spend cap and lets owners act', () => {
@@ -14,6 +14,7 @@ const setOverage =
vi.fn<(args: { enabled: boolean; spendCapCents?: number }) => Promise<OrcaBillingOverageResult>>()
const billingStatus = vi.fn<() => Promise<OrcaBillingStatusResult>>()
vi.mock('@/lib/orca-cloud/open-cloud-console', () => ({ openCloudConsole: vi.fn() }))
vi.mock('@/components/billing/plans/plans-dialog-store', () => ({ openPlansDialog: vi.fn() }))
const openPortal = vi.fn(() => Promise.resolve({ status: 'opened' as const }))
@@ -147,8 +148,8 @@ describe('billing blocker on the creating sheet (JA-21)', () => {
expect(onContinue).not.toHaveBeenCalled()
})
it('no plan: Compare plans opens billing in the browser, and returning re-checks once', async () => {
const { openCloudConsole } = await import('@/lib/orca-cloud/open-cloud-console')
it('no plan: Compare plans opens the plans dialog, and returning re-checks once', async () => {
const { openPlansDialog } = await import('@/components/billing/plans/plans-dialog-store')
billingStatus.mockResolvedValue({
status: 'ok',
entitlement: { ...sampleTeam, canStartSandbox: true }
@@ -156,7 +157,7 @@ describe('billing blocker on the creating sheet (JA-21)', () => {
const { onContinue } = renderBlocker('plan')
expect(screen.getByRole('heading', { name: 'Choose a plan' })).toBeTruthy()
fireEvent.click(screen.getByRole('button', { name: 'Compare plans' }))
expect(openCloudConsole).toHaveBeenCalledWith('billing')
expect(openPlansDialog).toHaveBeenCalledOnce()
act(() => {
window.dispatchEvent(new Event('focus'))
})