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
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
<BillingPlanLifecycle :state />
<Button
v-if="action"
as="a"
:href
target="_blank"
rel="noopener"
:variant="action === 'manage' ? 'secondary' : 'inverted'"
class="shrink-0"
@click="track"
@click="emit('openPlan')"
>
{{ $t(`workspacePanel.billingTab.plan.actions.${action}`) }}
<i class="icon-[lucide--external-link] size-4" aria-hidden="true" />
</Button>
</div>
</section>
Expand All @@ -45,19 +40,18 @@ import type {
PlanRowAction,
PlanRowState
} from '@/platform/workspace/components/dialogs/settings/billing/planRow'
import { usePlatformHandoff } from '@/platform/workspace/composables/usePlatformHandoff'

const { state, action, canManageSubscription } = defineProps<{
state: PlanRowState
action: PlanRowAction | null
canManageSubscription: boolean
}>()

const { t, locale } = useI18n()
const emit = defineEmits<{
openPlan: []
}>()

const { href, track } = usePlatformHandoff('/profile/billing/plans', {
target: 'plans'
})
const { t, locale } = useI18n()

const title = computed(() => {
if (state.kind === 'noPlan') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import enMessages from '@/locales/en/main.json'
import { useBillingContext } from '@/composables/billing/useBillingContext'
import { useBillingDialogs } from '@/composables/billing/useBillingDialogs'
import { useSubscriptionPaywall } from '@/composables/billing/useSubscriptionPaywall'
import type { BalanceInfo, SubscriptionInfo } from '@/composables/billing/types'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { receiveServerFact } from '@/platform/serverFacts/serverFact'
Expand All @@ -31,6 +32,7 @@
})
vi.mock(import('@/composables/billing/useBillingContext'))
vi.mock(import('@/composables/billing/useBillingDialogs'))
vi.mock(import('@/composables/billing/useSubscriptionPaywall'))

Check warning on line 35 in src/platform/workspace/components/dialogs/settings/billing/BillingTab.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'workspace/presentation/outer-1' to zone 'billing/application' is not allowed. src/platform/workspace/components/dialogs/settings/billing/BillingTab.test.ts -> src/composables/billing/__mocks__/useSubscriptionPaywall.ts Route the import through an allowed zone or restructure the dependency.
vi.mock(import('@/composables/useFeatureFlags'))
vi.mock(import('@/platform/workspace/composables/useBillingCapabilities'))
vi.mock(import('@/platform/workspace/composables/useWorkspaceUI'))
Expand Down Expand Up @@ -271,7 +273,7 @@
expect(screen.getByTestId('billing-plan-line')).toHaveTextContent(
'Activating your Pro plan…'
)
expect(screen.getByRole('link', { name: 'Manage' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Manage' })).toBeInTheDocument()
})

it('returns to the served status when subscription_state is no longer activating', () => {
Expand All @@ -283,19 +285,17 @@
expect(screen.queryByText(/Activating your/)).not.toBeInTheDocument()
})

it('renders an active plan with Manage and the owner handoff linked to the billing site', () => {
it('opens plan management on Cloud instead of a platform plans page', async () => {
arrange()

expect(screen.getByRole('heading', { name: 'Pro' })).toBeInTheDocument()
expect(screen.getByTestId('billing-plan-line')).toHaveTextContent(
'Billed monthly. Next invoice November 15.'
)
expect(screen.getByRole('link', { name: 'Manage' })).toHaveAttribute(
'href',
expect.stringMatching(
/^https:\/\/platform\.test\/profile\/billing\/plans\?workspace=ws_1&correlation_id=.+$/
)
)
expect(
screen.queryByRole('link', { name: 'Manage' })
).not.toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: 'Manage' }))

expect(
useSubscriptionPaywall().showSubscriptionDialog
).toHaveBeenCalledWith({ reason: 'settings_billing_panel' })
expect(screen.getByRole('link', { name: 'Open billing' })).toHaveAttribute(
'href',
expect.stringMatching(
Expand All @@ -304,11 +304,24 @@
)
})

it('opens Subscribe on Cloud for a workspace with no plan', async () => {
arrange({ subscription: null, subscriptionStatus: null })

expect(
screen.queryByRole('link', { name: 'Subscribe' })
).not.toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: 'Subscribe' }))

expect(
useSubscriptionPaywall().showSubscriptionDialog
).toHaveBeenCalledWith({ reason: 'settings_billing_panel' })
})

it('hides the plan action when the server does not grant it', () => {
arrange({ canSubscribeSelfServe: false })

expect(
screen.queryByRole('link', { name: 'Manage' })
screen.queryByRole('button', { name: 'Manage' })
).not.toBeInTheDocument()
})

Expand Down Expand Up @@ -369,12 +382,6 @@
)

it.for([
{
name: 'the plan action',
scenario: { canManageBilling: true },
link: 'Manage',
destination: { target: 'plans' }
},
{
name: 'the owner handoff',
scenario: { canManageBilling: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
:state="planRow"
:action="action"
:can-manage-subscription="capabilities.canManageSubscription.value"
@open-plan="openPlan"
/>
<BillingCreditsCard
:state="creditsCard"
Expand Down Expand Up @@ -75,6 +76,7 @@ import Button from '@/components/ui/button/Button.vue'
import Skeleton from '@/components/ui/skeleton/Skeleton.vue'
import { useBillingContext } from '@/composables/billing/useBillingContext'
import { useBillingDialogs } from '@/composables/billing/useBillingDialogs'
import { useSubscriptionPaywall } from '@/composables/billing/useSubscriptionPaywall'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { useTelemetry } from '@/platform/telemetry'
import { paymentIntentSourceForAddCreditsClick } from '@/platform/telemetry/utils/paymentIntentSource'
Expand All @@ -98,6 +100,7 @@ const { flags } = useFeatureFlags()
const { state: planRow } = useBillingPlanRow()
const { state: creditsCard } = useBillingCreditsCard(planRow)
const { showTopUpCreditsDialog } = useBillingDialogs()
const { showSubscriptionDialog } = useSubscriptionPaywall()
const telemetry = useTelemetry()

const HANDOFF = {
Expand Down Expand Up @@ -133,6 +136,10 @@ async function retryBalance() {
await billing.fetchBalance().catch(() => undefined)
}

function openPlan() {
showSubscriptionDialog({ reason: 'settings_billing_panel' })
}

function addCredits() {
telemetry?.trackAddApiCreditButtonClicked({ source: 'credits_panel' })
void showTopUpCreditsDialog({
Expand Down
Loading