Files
supabase/apps/studio/components/interfaces/Integrations/Warehouse/WarehouseSetupPanel.test.tsx
Danny WhiteandJoshen Lim 0ce2a96c53 feat(studio): show Warehouse workload on the integration overview (#53575)
## Problem

The Warehouse integration overview shows replication status but gives no
view of query activity.

## Solution

Add last-hour query rate and p95 duration charts, with refresh and a
link to Observability. Metrics failures appear beside the replication
information.

| Before | After |
| --- | --- |
| <img width="1292" height="1288" alt="CleanShot 2026-11-18 at 13 44
48@2x"
src="https://github.com/user-attachments/assets/f06314bb-8322-448b-a86b-6821a3427a52"
/> | <img width="1314" height="1930" alt="CleanShot 2026-11-18 at 13 45
10@2x"
src="https://github.com/user-attachments/assets/0cbaab85-b7bb-445d-8547-3c772010a0d1"
/> |
| _No “Workload” section._ | _A new “Workload” section._ |

Depends on #53574.

## Review instructions

1. Open the [Studio staging
preview](https://studio-staging-git-dnywh-warehouse-overview-workload-supabase.vercel.app)
with a staging project that has Warehouse configured.
2. Go to **Integrations > Warehouse > Overview**. Check the **Workload**
charts below replication status.
3. Refresh the charts, then use **Observability** to open the full
report.
4. Check a period without query activity. The empty message should name
the last 60 minutes.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-11-20 15:46:03 +11:00

241 lines
8.9 KiB
TypeScript

import { QueryClient } from '@tanstack/react-query'
import { fireEvent, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { components } from 'api-types'
import { mockAnimationsApi } from 'jsdom-testing-mocks'
import { HttpResponse } from 'msw'
import { useForm } from 'react-hook-form'
import { Form } from 'ui'
import { describe, expect, test, vi } from 'vitest'
import { WarehouseSetupPanel } from './WarehouseSetupPanel'
import type { DestinationPanelSchemaType } from '@/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema'
import { DuckLakeFields } from '@/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DuckLake/Fields'
import type { ProjectDetail } from '@/data/projects/project-detail-query'
import type { WarehouseMetricsResponse } from '@/data/warehouse/warehouse-metrics-api-types'
import { customRender } from '@/tests/lib/custom-render'
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
type SetupStatus = components['schemas']['WarehouseSetupStatusResponse_Output']
type Destinations = components['schemas']['DestinationsResponse_Output']
mockAnimationsApi()
vi.mock('./WarehouseSchemaTablePicker', () => ({
WarehouseSchemaTablePicker: () => <button tabIndex={0}>Enable Warehouse</button>,
}))
vi.mock('./WarehouseConnectSection', () => ({ WarehouseConnectSection: () => null }))
vi.mock('./WarehouseDisableCard', () => ({
WarehouseDisableCard: () => <button tabIndex={0}>Disable Warehouse</button>,
}))
vi.mock('./WarehouseTableStatusList', () => ({
WarehouseEnablingProgress: () => <p>Warehouse setup in progress</p>,
WarehouseReplicatedTablesSection: () => <p>Replicated tables</p>,
}))
const PROJECT: ProjectDetail = {
cloud_provider: 'AWS',
connectionString: 'postgresql://postgres@localhost:5432/postgres',
db_host: 'db.default.supabase.co',
high_availability: false,
id: 1,
inserted_at: '2026-01-01T00:00:00.000Z',
integration_source: null,
is_branch_enabled: false,
is_hibernating: false,
is_physical_backups_enabled: false,
name: 'Test project',
organization_id: 1,
ref: 'default',
region: 'us-east-1',
restUrl: 'https://default.supabase.co/rest/v1',
status: 'ACTIVE_HEALTHY',
subscription_id: 'subscription-1',
updated_at: '2026-01-01T00:00:00.000Z',
}
const WAREHOUSE_DESTINATION: Destinations['destinations'][number] = {
id: 1,
tenant_id: 'default',
name: 'supabase_warehouse',
config: {
ducklake: {
data_path: 's3://warehouse-default/',
s3_region: 'us-east-1',
s3_endpoint: 'otherproject.storage.supabase.co/storage/v1/s3',
},
},
}
function mockProject(isOrioleDb: boolean) {
addAPIMock({
method: 'get',
path: '/platform/projects/:ref',
response: () =>
HttpResponse.json<ProjectDetail>({
...PROJECT,
dbVersion: isOrioleDb
? 'supabase-postgres-17.11.0.004-orioledb'
: 'supabase-postgres-17.6.1.001',
}),
})
}
function mockWarehouse(
status: SetupStatus['setup_status'] = 'not_started',
destinations: Destinations['destinations'] = []
) {
addAPIMock({
method: 'get',
path: '/platform/warehouse/:ref/setup-status',
response: () =>
HttpResponse.json<SetupStatus>({
setup_status: status,
steps: [],
tables: [],
fdw_status: null,
}),
})
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/destinations',
response: () => HttpResponse.json<Destinations>({ destinations }),
})
addAPIMock({
method: 'get',
path: '/platform/warehouse/:ref/metrics',
response: () => HttpResponse.json<WarehouseMetricsResponse>({ metrics: [] }),
})
}
const DuckLakeForm = () => {
const form = useForm<DestinationPanelSchemaType>({ defaultValues: { ducklakeMode: 'supabase' } })
return (
<Form {...form}>
<DuckLakeFields form={form} editMode={false} />
</Form>
)
}
describe('OrioleDB catalog restrictions', () => {
test.each(['not_started', 'disabled', 'error'] as const)(
'blocks Warehouse setup using the current OrioleDB project when %s',
async (status) => {
mockProject(true)
mockWarehouse(status)
customRender(<WarehouseSetupPanel />)
expect(
await screen.findByText('This project cannot host a Warehouse catalog')
).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Enable Warehouse' })).not.toBeInTheDocument()
}
)
test.each(['not_started', 'disabled', 'error'] as const)(
'allows Warehouse setup on standard Postgres when %s',
async (status) => {
mockProject(false)
mockWarehouse(status)
customRender(<WarehouseSetupPanel />)
expect(await screen.findByRole('button', { name: 'Enable Warehouse' })).toBeInTheDocument()
}
)
test.each(['not_started', 'disabled', 'error'] as const)(
'blocks Warehouse setup with a missing database version until a retry resolves it when %s',
async (status) => {
addAPIMock({
method: 'get',
path: '/platform/projects/:ref',
response: () => HttpResponse.json<ProjectDetail>(PROJECT),
})
mockWarehouse(status)
customRender(<WarehouseSetupPanel />)
expect(await screen.findByText('Failed to check project compatibility')).toBeInTheDocument()
expect(screen.getByText(/The project database version is unavailable/)).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Enable Warehouse' })).not.toBeInTheDocument()
mockProject(false)
fireEvent.click(screen.getByRole('button', { name: 'Retry' }))
expect(await screen.findByRole('button', { name: 'Enable Warehouse' })).toBeInTheDocument()
}
)
test.each([false, true])(
'retries a failed destination lookup and announces only a retained destination (%s)',
async (hasRetainedDestination) => {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, retryDelay: 0 } },
})
mockProject(true)
mockWarehouse('error')
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/destinations',
response: () =>
HttpResponse.json<APIErrorBody>(
{ message: 'Destination lookup failed' },
{ status: 500 }
),
})
customRender(<WarehouseSetupPanel />, { queryClient })
const retryStatus = screen.getByRole('status')
expect(retryStatus).toBeEmptyDOMElement()
expect(await screen.findByText('Failed to load Warehouse destination')).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Enable Warehouse' })).not.toBeInTheDocument()
mockWarehouse('error', hasRetainedDestination ? [WAREHOUSE_DESTINATION] : [])
fireEvent.click(screen.getByRole('button', { name: 'Retry' }))
if (hasRetainedDestination) {
expect(
await screen.findByText('Warehouse destination loaded. You can continue setup.')
).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Enable Warehouse' })).toBeInTheDocument()
expect(retryStatus).toHaveFocus()
} else {
expect(
await screen.findByText('This project cannot host a Warehouse catalog')
).toBeInTheDocument()
expect(retryStatus).toBeEmptyDOMElement()
expect(screen.queryByRole('button', { name: 'Enable Warehouse' })).not.toBeInTheDocument()
}
expect(screen.getByRole('status')).toBe(retryStatus)
expect(screen.queryByText('Failed to load Warehouse destination')).not.toBeInTheDocument()
}
)
test('preserves existing Warehouse management on an OrioleDB source', async () => {
mockProject(true)
mockWarehouse('complete')
customRender(<WarehouseSetupPanel />)
expect(await screen.findByRole('button', { name: 'Disable Warehouse' })).toBeInTheDocument()
expect(
screen.queryByText('This project cannot host a Warehouse catalog')
).not.toBeInTheDocument()
})
test.each(['not_started', 'disabled', 'error'] as const)(
'lets the API validate a retained Warehouse destination when %s',
async (status) => {
mockProject(true)
mockWarehouse(status, [WAREHOUSE_DESTINATION])
customRender(<WarehouseSetupPanel />)
expect(await screen.findByRole('button', { name: 'Enable Warehouse' })).toBeInTheDocument()
}
)
test('disables the managed DuckLake option while allowing custom connection details', async () => {
mockProject(true)
customRender(<DuckLakeForm />)
expect(
await screen.findByText('This project cannot host a DuckLake catalog')
).toBeInTheDocument()
expect(screen.getByRole('radio', { name: /Use this Supabase project/ })).toBeDisabled()
const customOption = screen.getByRole('radio', { name: /Enter connection details/ })
expect(customOption).not.toBeDisabled()
await userEvent.click(customOption)
expect(screen.getByLabelText('Catalog URL')).toBeInTheDocument()
})
})