mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## What Makes the **Free** plan badge next to the organization name (in the org dropdown) a clickable entry point into the upgrade funnel. Resolves [GROWTH-775](https://linear.app/supabase/issue/GROWTH-775). Feedback verbatim: _"if i hit the 'free' button next to my account name it should take you to the upgrade to paid account funnel."_ The badge links to `/org/{slug}/billing?panel=subscriptionPlan&source=org_plan_badge`. Clicking it fires `upgrade_cta_clicked` with `placement: 'org_plan_badge'`. ## Changes | File | Change | |---|---| | `apps/studio/components/layouts/AppLayout/OrganizationDropdown.tsx` | Eligibility check and the linked badge. | | `apps/studio/components/layouts/AppLayout/AppLayoutDropdown.tsx` | New optional `trailingContent` slot, rendered as a sibling of the nav `<Link>`. Needed because a clickable badge can't be a `<Link>` nested inside the org `<Link>` (invalid HTML). Non-breaking — `BranchDropdown` is unaffected. | | `packages/common/telemetry-constants.ts` | Adds the `org_plan_badge` placement to `upgrade_cta_clicked`. | | `apps/studio/components/layouts/AppLayout/OrganizationDropdown.test.tsx` | Free org gets the link; partner-managed, billing-partner, and paid orgs keep the plain badge. | ## Who sees the link Orgs on the Free plan, managed by Supabase, with no `billing_partner`. Everyone else keeps the plain, non-clickable badge. The badge also stays plain when billing is disabled (`billing:all`) or plan changes are paused (`disableProjectCreationAndUpdate`), the same two checks `UpgradePlanButton` applies. Partner-managed orgs are excluded because they change plans at the partner (Vercel / AWS Marketplace / Stripe Projects). `PlanUpdateSidePanel` shows a `PartnerManagedResource` notice and disables every paid tier for them, so the badge would land them on a panel with no enabled action. `billing_partner` is checked separately because `getManagedByFromOrganizationPartner` doesn't map every partner — `fly` falls through to `supabase`. Free-plan members without `BILLING_WRITE` still get the link: `PlanUpdateSidePanel` renders `RequestUpgradeToBillingOwners` per plan card for them, so the landing is a real next action, not a dead end. ## Testing `OrganizationDropdown.test.tsx` covers the linked badge for a Free Supabase-managed org and the plain badge for partner-managed, billing-partner, and Pro orgs, plus the billing-disabled and plan-changes-paused cases. Existing partner-icon tests still pass. `tsc --noEmit` and Prettier are clean for the touched files. The Studio lint ratchet passes locally. --------- Co-authored-by: Pamela Chia <pamelachiamayyee@gmail.com>
202 lines
6.3 KiB
TypeScript
202 lines
6.3 KiB
TypeScript
import {
|
|
createMemoryHistory,
|
|
createRootRoute,
|
|
createRouter,
|
|
RouterContextProvider,
|
|
} from '@tanstack/react-router'
|
|
import { screen, within } from '@testing-library/react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { OrganizationDropdown } from './OrganizationDropdown'
|
|
import { MANAGED_BY } from '@/lib/constants/infrastructure'
|
|
import { parseSearch, stringifySearch } from '@/lib/router-search-params'
|
|
import { createMockOrganization, render } from '@/tests/helpers'
|
|
import type { Organization } from '@/types'
|
|
|
|
const {
|
|
mockUseFlag,
|
|
mockUseIsFeatureEnabled,
|
|
mockUseOrganizationsQuery,
|
|
mockUseSelectedOrganizationQuery,
|
|
} = vi.hoisted(() => ({
|
|
mockUseFlag: vi.fn(),
|
|
mockUseIsFeatureEnabled: vi.fn(),
|
|
mockUseOrganizationsQuery: vi.fn(),
|
|
mockUseSelectedOrganizationQuery: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('common', async (importOriginal) => ({
|
|
...(await importOriginal<typeof import('common')>()),
|
|
useFlag: mockUseFlag,
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
|
|
useIsFeatureEnabled: mockUseIsFeatureEnabled,
|
|
}))
|
|
|
|
vi.mock('@/data/organizations/organizations-query', () => ({
|
|
useOrganizationsQuery: mockUseOrganizationsQuery,
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useSelectedOrganization', () => ({
|
|
useSelectedOrganizationQuery: mockUseSelectedOrganizationQuery,
|
|
}))
|
|
|
|
vi.mock('@/components/ui/PartnerIcon', () => ({
|
|
default: ({ organization }: { organization: { managed_by: string } }) =>
|
|
organization.managed_by === MANAGED_BY.SUPABASE ? null : <div data-testid="partner-icon" />,
|
|
}))
|
|
|
|
// The upgrade badge is a native TanStack `Link`, which needs a router in context.
|
|
const renderDropdown = (props: Parameters<typeof OrganizationDropdown>[0] = {}) => {
|
|
const router = createRouter({
|
|
routeTree: createRootRoute(),
|
|
history: createMemoryHistory({ initialEntries: ['/org/org-one'] }),
|
|
parseSearch,
|
|
stringifySearch,
|
|
})
|
|
|
|
return render(
|
|
<RouterContextProvider router={router}>
|
|
<OrganizationDropdown {...props} />
|
|
</RouterContextProvider>
|
|
)
|
|
}
|
|
|
|
const queryUpgradeLink = () => screen.queryByRole('link', { name: /upgrade from the/i })
|
|
|
|
const expectInlinePlanBadge = (planName: string) => {
|
|
const organizationLink = screen.getByRole('link', { name: /org one/i })
|
|
expect(organizationLink).toHaveAttribute('href', '/org/org-one')
|
|
expect(within(organizationLink).getByText(planName)).toBeInTheDocument()
|
|
expect(queryUpgradeLink()).toBeNull()
|
|
}
|
|
|
|
const organizationsWithoutUpgradeLink: Array<{
|
|
description: string
|
|
organization: Partial<Organization>
|
|
planName: string
|
|
}> = [
|
|
{
|
|
description: 'a partner-managed org',
|
|
organization: { managed_by: MANAGED_BY.VERCEL_MARKETPLACE },
|
|
planName: 'Free',
|
|
},
|
|
{
|
|
description: 'an org with a billing partner',
|
|
organization: { billing_partner: 'aws_marketplace' },
|
|
planName: 'Free',
|
|
},
|
|
{
|
|
description: 'an org on a paid plan',
|
|
organization: { plan: { id: 'pro', name: 'Pro' } },
|
|
planName: 'Pro',
|
|
},
|
|
]
|
|
|
|
describe('OrganizationDropdown', () => {
|
|
beforeEach(() => {
|
|
mockUseFlag.mockReturnValue(false)
|
|
mockUseIsFeatureEnabled.mockImplementation((feature: string) => feature === 'billing:all')
|
|
mockUseOrganizationsQuery.mockReturnValue({
|
|
data: [
|
|
createMockOrganization({ slug: 'org-one', name: 'Org One' }),
|
|
createMockOrganization({ slug: 'org-two', name: 'Org Two' }),
|
|
],
|
|
isPending: false,
|
|
isError: false,
|
|
})
|
|
})
|
|
|
|
it('renders partner icon in selected organization area for managed organizations', () => {
|
|
mockUseSelectedOrganizationQuery.mockReturnValue({
|
|
data: createMockOrganization({
|
|
slug: 'org-one',
|
|
name: 'Org One',
|
|
managed_by: MANAGED_BY.AWS_MARKETPLACE,
|
|
}),
|
|
})
|
|
|
|
renderDropdown()
|
|
|
|
const selectedLink = screen.getByRole('link', { name: /org one/i })
|
|
expect(within(selectedLink).getByTestId('partner-icon')).toBeInTheDocument()
|
|
})
|
|
|
|
it('does not render partner icon in selected organization area for Supabase-managed orgs', () => {
|
|
mockUseSelectedOrganizationQuery.mockReturnValue({
|
|
data: createMockOrganization({
|
|
slug: 'org-one',
|
|
name: 'Org One',
|
|
managed_by: MANAGED_BY.SUPABASE,
|
|
}),
|
|
})
|
|
|
|
renderDropdown()
|
|
|
|
const selectedLink = screen.getByRole('link', { name: /org one/i })
|
|
expect(within(selectedLink).queryByTestId('partner-icon')).toBeNull()
|
|
})
|
|
|
|
it('renders the plan badge as an upgrade link for a Free Supabase-managed org', () => {
|
|
mockUseSelectedOrganizationQuery.mockReturnValue({
|
|
data: createMockOrganization({ slug: 'org-one', name: 'Org One' }),
|
|
})
|
|
|
|
renderDropdown()
|
|
|
|
expect(screen.getByRole('link', { name: /upgrade from the free plan/i })).toHaveAttribute(
|
|
'href',
|
|
'/org/org-one/billing?panel=subscriptionPlan&source=org_plan_badge'
|
|
)
|
|
expect(screen.getByRole('link', { name: /org one/i })).toHaveAttribute('href', '/org/org-one')
|
|
})
|
|
|
|
it.each(organizationsWithoutUpgradeLink)(
|
|
'keeps the plan badge inline for $description',
|
|
({ organization, planName }) => {
|
|
mockUseSelectedOrganizationQuery.mockReturnValue({
|
|
data: createMockOrganization({ slug: 'org-one', name: 'Org One', ...organization }),
|
|
})
|
|
|
|
renderDropdown()
|
|
|
|
expectInlinePlanBadge(planName)
|
|
}
|
|
)
|
|
|
|
it('keeps the plan badge inline when billing is disabled', () => {
|
|
mockUseIsFeatureEnabled.mockReturnValue(false)
|
|
mockUseSelectedOrganizationQuery.mockReturnValue({
|
|
data: createMockOrganization({ slug: 'org-one', name: 'Org One' }),
|
|
})
|
|
|
|
renderDropdown()
|
|
|
|
expectInlinePlanBadge('Free')
|
|
})
|
|
|
|
it('keeps the plan badge inline while plan changes are paused', () => {
|
|
mockUseFlag.mockImplementation((flag: string) => flag === 'disableProjectCreationAndUpdate')
|
|
mockUseSelectedOrganizationQuery.mockReturnValue({
|
|
data: createMockOrganization({ slug: 'org-one', name: 'Org One' }),
|
|
})
|
|
|
|
renderDropdown()
|
|
|
|
expectInlinePlanBadge('Free')
|
|
})
|
|
|
|
it('renders organization command items as links', () => {
|
|
mockUseSelectedOrganizationQuery.mockReturnValue({
|
|
data: createMockOrganization({ slug: 'org-one', name: 'Org One' }),
|
|
})
|
|
|
|
renderDropdown({ embedded: true })
|
|
|
|
const organizationLink = screen.getByRole('link', { name: /org two/i })
|
|
expect(within(organizationLink).getByRole('option')).toBeInTheDocument()
|
|
expect(organizationLink).toHaveAttribute('href', '/org/org-two')
|
|
})
|
|
})
|