Files
supabase/apps/studio/components/interfaces/Organization/Usage/Usage.test.tsx
Saxon Fletcher ddc1f4175f HA continued surface coverage (#48425)
- Updates connection pooling settings to be read-only when a high
availability project with ip4 admonition removed
- Updates organization usage to be disabled until supported
- Updates database publications to be disabled until supported

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added High Availability handling for database publications, usage, and
connection pooling.
* Publications and usage now display dedicated “unavailable” empty
states and hide gated content when High Availability is enabled.
* Connection pooling switches to managed/read-only mode on High
Availability, disabling edits and form submission and disabling related
data fetching.
  * Pooling mode controls are hidden on High Availability.
* **Refactor**
* Refactored database publications pages by extracting main rendering
logic into internal components.
* **Tests**
* Added Vitest + React Testing Library coverage for High Availability
behavior across publications availability, usage, connection pooling,
and pooling modes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-07-30 16:37:45 +08:00

91 lines
2.7 KiB
TypeScript

import { screen } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { Usage } from './Usage'
import { customRender } from '@/tests/lib/custom-render'
const {
mockUseAsyncCheckPermissions,
mockUseOrgDailyStatsQuery,
mockUseOrgSubscriptionQuery,
mockUseProjectDetailQuery,
} = vi.hoisted(() => ({
mockUseAsyncCheckPermissions: vi.fn(),
mockUseOrgDailyStatsQuery: vi.fn(),
mockUseOrgSubscriptionQuery: vi.fn(),
mockUseProjectDetailQuery: vi.fn(),
}))
vi.mock('common', async (importOriginal) => ({
...(await importOriginal<typeof import('common')>()),
useParams: () => ({ slug: 'test-org' }),
}))
vi.mock('@/hooks/misc/useCheckPermissions', () => ({
useAsyncCheckPermissions: mockUseAsyncCheckPermissions,
}))
vi.mock('@/data/analytics/org-daily-stats-query', async (importOriginal) => ({
...(await importOriginal<typeof import('@/data/analytics/org-daily-stats-query')>()),
useOrgDailyStatsQuery: mockUseOrgDailyStatsQuery,
}))
vi.mock('@/data/projects/project-detail-query', () => ({
useProjectDetailQuery: mockUseProjectDetailQuery,
}))
vi.mock('@/data/subscriptions/org-subscription-query', () => ({
useOrgSubscriptionQuery: mockUseOrgSubscriptionQuery,
}))
describe('Usage', () => {
beforeEach(() => {
vi.clearAllMocks()
mockUseAsyncCheckPermissions.mockReturnValue({ can: true, isLoading: false })
mockUseProjectDetailQuery.mockReturnValue({
data: {
ref: 'ha-project',
name: 'HA project',
high_availability: true,
},
isPending: false,
})
mockUseOrgSubscriptionQuery.mockReturnValue({
data: undefined,
error: undefined,
isPending: false,
isError: false,
isSuccess: false,
})
mockUseOrgDailyStatsQuery.mockReturnValue({
data: undefined,
error: undefined,
isPending: false,
isError: false,
})
})
it('shows a coming-soon empty state for a High Availability project', () => {
customRender(<Usage />, {
nuqs: { searchParams: { projectRef: 'ha-project' } },
})
expect(screen.getByText('Usage unavailable on High Availability projects')).toBeInTheDocument()
expect(
screen.getByText('Usage insights for High Availability projects are coming soon.')
).toBeInTheDocument()
expect(screen.queryByText('Usage filtered by project')).not.toBeInTheDocument()
expect(mockUseProjectDetailQuery).toHaveBeenCalledWith({ ref: 'ha-project' })
expect(mockUseOrgSubscriptionQuery).toHaveBeenCalledWith(
{ orgSlug: 'test-org' },
{ enabled: false }
)
expect(mockUseOrgDailyStatsQuery).toHaveBeenCalledWith(
expect.objectContaining({ orgSlug: 'test-org', projectRef: 'ha-project' }),
{ enabled: false }
)
})
})