Files
supabase/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineLayout.test.tsx
Danny WhiteandJoshen Lim 229d04d65c feat(studio): give pipeline pages a standard detail header (#50253)
## What kind of change does this PR introduce?

Studio page-layout polish. This follows the merged destination-brand and
pipelines-list work in #50251 and #50252, and now targets `master`
directly.

## What is the current behaviour?

Pipeline child pages use a bespoke heading, provide limited destination
context, and shift substantially while pipeline and destination data
load.

## What is the new behaviour?

Adds standard breadcrumbs and page-header composition, destination
identity, the primary-database-to-destination path, lifecycle actions,
and child-route integration. Layout-matched loading placeholders keep
the header geometry stable until the resolved pipeline data is
available.

Removes the legacy Overview header and actions now owned by the shared
page shell, and restores standard content gutters around the existing
metrics and tables. Pipeline action errors are handled once by the
layout, avoiding duplicate notifications from the underlying mutations.
Pipeline actions are also temporarily disabled while a table reset is
running to prevent conflicting requests.

| Before | After |
| --- | --- |
| <img width="1131" height="801" alt="Replication Database ETL BigTable
ETL Team Supabase"
src="https://github.com/user-attachments/assets/3f0ebab0-7244-4aa1-81ac-8847f5f86d4a"
/> | <img width="1131" height="801" alt="Replication Database Agua
Basket Supabase"
src="https://github.com/user-attachments/assets/bcbbd150-2a3d-468d-9cb9-652a6de2040b"
/> |

## To test

1. Open a pipeline at
`/project/<ref>/database/replication/<pipeline-id>`.
2. Confirm there is one page header with one set of actions, followed by
a consistently padded Overview body.
3. Confirm the breadcrumbs, destination logo and name, status,
source-to-destination path, primary lifecycle action, and overflow
actions.
4. Start, stop, or restart the pipeline and confirm its status and
available actions update appropriately.
5. Reset a replicated table and confirm the pipeline lifecycle, update,
and overflow actions remain disabled until the reset finishes.
6. Throttle the initial pipeline and destination requests and confirm
the header retains its final geometry without showing fallback data.
7. Check the page at desktop and phone widths.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-16 11:51:49 +10:00

309 lines
11 KiB
TypeScript

import { screen, waitFor } 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 { ReactNode, type AnchorHTMLAttributes } from 'react'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import { ReplicationPipelineLayout } from './ReplicationPipelineLayout'
import { ReplicationPipelineStatus } from './ReplicationPipelineStatus/ReplicationPipelineStatus'
import {
PipelineRequestStatusProvider,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
import { customRender } from '@/tests/lib/custom-render'
import { addAPIMock } from '@/tests/lib/msw'
mockAnimationsApi()
// The global setup pins useParams to { ref: 'default' }; this layout also needs a pipeline id
vi.mock('common', async (importOriginal) => ({
...(await importOriginal<typeof import('common')>()),
useParams: () => ({ ref: 'default', pipelineId: '42' }),
}))
vi.mock('next/router', () => ({
useRouter: () => ({ push: vi.fn() }),
}))
vi.mock('next/link', () => ({
default: ({
href,
children,
...props
}: AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }) => (
<a href={href} {...props}>
{children}
</a>
),
}))
const renderLayout = (children?: ReactNode) =>
customRender(
<PipelineRequestStatusProvider>
<ReplicationPipelineLayout>{children}</ReplicationPipelineLayout>
</PipelineRequestStatusProvider>
)
const TableResetFixture = () => {
const { setTableResetting } = usePipelineRequestStatus()
return (
<>
<button tabIndex={0} onClick={() => setTableResetting(42, true)}>
Begin table reset
</button>
<button tabIndex={0} onClick={() => setTableResetting(42, false)}>
Finish table reset
</button>
</>
)
}
type PipelineResponse = components['schemas']['PipelineResponse_Output']
type PipelineStatusResponse = components['schemas']['PipelineStatusResponse_Output']
type PipelineReplicationStatusResponse =
components['schemas']['PipelineReplicationStatusResponse_Output']
type PipelineVersionResponse = components['schemas']['PipelineVersionResponse_Output']
type DestinationResponse = components['schemas']['DestinationResponse_Output']
type DestinationsResponse = components['schemas']['DestinationsResponse_Output']
type PipelinesResponse = components['schemas']['PipelinesResponse_Output']
type SourcesResponse = components['schemas']['SourcesResponse_Output']
const PIPELINE: PipelineResponse = {
id: 42,
config: { publication_name: 'analytics_publication' },
destination_id: 7,
destination_name: 'Analytics warehouse',
replicator_id: 1,
source_id: 2,
source_name: 'main-db',
tenant_id: 'default',
}
const DESTINATION: DestinationResponse = {
id: 7,
name: 'Analytics warehouse',
tenant_id: 'default',
config: {
big_query: {
connection_pool_size: 8,
dataset_id: 'analytics',
project_id: 'acme-analytics',
},
},
}
const mockPipeline = () => {
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/pipelines/:pipeline_id',
response: () => HttpResponse.json<PipelineResponse>(PIPELINE),
})
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/destinations/:destination_id',
response: () => HttpResponse.json<DestinationResponse>(DESTINATION),
})
// The header renders DestinationPanel so Edit destination can open in place
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/destinations',
response: () => HttpResponse.json<DestinationsResponse>({ destinations: [DESTINATION] }),
})
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/pipelines',
response: () => HttpResponse.json<PipelinesResponse>({ pipelines: [PIPELINE] }),
})
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/sources',
response: () =>
HttpResponse.json<SourcesResponse>({
sources: [
{
tenant_id: 'default',
id: 2,
name: 'default',
config: { host: 'db.internal', port: 5432, name: 'main-db', username: 'etl_user' },
},
],
}),
})
}
const mockStatus = (name: PipelineStatusResponse['status']['name']) =>
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/pipelines/:pipeline_id/status',
response: () =>
HttpResponse.json<PipelineStatusResponse>({ pipeline_id: 42, status: { name } }),
})
const mockVersion = (hasUpdate: boolean) =>
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/pipelines/:pipeline_id/version',
response: () =>
HttpResponse.json<PipelineVersionResponse>({
pipeline_id: 42,
version: { id: 1, name: 'v0.2.0' },
...(hasUpdate ? { new_version: { id: 2, name: 'v0.3.0' } } : {}),
}),
})
const mockReplicationStatus = () =>
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/pipelines/:pipeline_id/replication-status',
response: () =>
HttpResponse.json<PipelineReplicationStatusResponse>({
pipeline_id: 42,
table_statuses: [],
}),
})
describe('ReplicationPipelineLayout', () => {
beforeEach(() => {
mockPipeline()
mockVersion(false)
})
test('renders pipeline identity, chrome actions and the lifecycle action', async () => {
mockStatus('started')
renderLayout(<div>Overview content</div>)
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).toBeVisible()
expect(screen.getByRole('link', { name: 'Replication' })).toHaveAttribute(
'href',
'/project/default/database/replication'
)
expect(screen.getByRole('link', { name: 'View logs' }).getAttribute('href')).toContain(
'pipeline_id'
)
expect(screen.getByText('Running')).toBeVisible()
expect(screen.getByText('Primary database')).toBeVisible()
expect(await screen.findByText('BigQuery')).toBeVisible()
expect(await screen.findByRole('button', { name: 'Stop' })).toBeVisible()
expect(screen.getByText('Overview content')).toBeVisible()
})
test('keeps the pipeline identity structure in place while it loads', async () => {
let resolvePipeline: (pipeline: PipelineResponse) => void = () => {}
const pipelineResponse = new Promise<PipelineResponse>((resolve) => {
resolvePipeline = resolve
})
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/pipelines/:pipeline_id',
response: async () => HttpResponse.json<PipelineResponse>(await pipelineResponse),
})
mockStatus('started')
renderLayout()
expect(screen.getByText('Primary database')).toBeVisible()
expect(screen.getByText('Loading destination')).toBeInTheDocument()
expect(screen.getAllByText('Loading pipeline')).toHaveLength(2)
expect(screen.queryByText('Running')).not.toBeInTheDocument()
resolvePipeline(PIPELINE)
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).toBeVisible()
expect(await screen.findByText('BigQuery')).toBeVisible()
expect(await screen.findByText('Running')).toBeVisible()
})
test('composes the legacy overview without duplicating the detail header', async () => {
mockStatus('stopped')
mockReplicationStatus()
renderLayout(<ReplicationPipelineStatus />)
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).toBeVisible()
expect(screen.getAllByRole('link', { name: 'View logs' })).toHaveLength(1)
expect(screen.getAllByRole('button', { name: 'Start' })).toHaveLength(1)
expect(await screen.findByRole('heading', { name: 'Pipeline stopped' })).toBeVisible()
})
test('explains the state in a tooltip when the dot is hovered', async () => {
// The dotted underline promises a tooltip; this guards the asChild ref binding that makes it work
mockStatus('failed')
renderLayout()
await userEvent.hover(await screen.findByText('Failed'))
expect(await screen.findByRole('tooltip')).toHaveTextContent(
'Replication has encountered an error. Check the logs for more information.'
)
expect(screen.queryByRole('link', { name: 'logs' })).not.toBeInTheDocument()
})
test('offers the pipeline actions the primary button does not', async () => {
mockStatus('started')
renderLayout()
await screen.findByRole('heading', { name: 'Analytics warehouse' })
await userEvent.click(screen.getByRole('button', { name: 'Pipeline options' }))
// Primary button is Stop while running, so the menu carries Restart instead
expect(await screen.findByRole('menuitem', { name: 'Restart pipeline' })).toBeVisible()
expect(screen.queryByRole('menuitem', { name: 'Stop pipeline' })).not.toBeInTheDocument()
expect(screen.getByRole('menuitem', { name: 'Edit pipeline' })).toBeVisible()
expect(screen.getByRole('menuitem', { name: 'Delete pipeline' })).toBeVisible()
})
test('blocks pipeline actions while a table reset is running', async () => {
mockStatus('started')
mockVersion(true)
renderLayout(<TableResetFixture />)
const lifecycleAction = await screen.findByRole('button', { name: 'Stop' })
const options = screen.getByRole('button', { name: 'Pipeline options' })
const update = await screen.findByRole('button', { name: 'Update available' })
expect(lifecycleAction).toBeEnabled()
expect(options).toBeEnabled()
expect(update).toBeEnabled()
await userEvent.click(screen.getByRole('button', { name: 'Begin table reset' }))
expect(lifecycleAction).toBeDisabled()
expect(options).toBeDisabled()
expect(update).toBeDisabled()
await userEvent.click(screen.getByRole('button', { name: 'Finish table reset' }))
expect(lifecycleAction).toBeEnabled()
expect(options).toBeEnabled()
expect(update).toBeEnabled()
})
test('offers Stop from the menu when the primary button is Restart', async () => {
mockStatus('failed')
renderLayout()
await screen.findByRole('heading', { name: 'Analytics warehouse' })
await waitFor(() => expect(screen.getByRole('button', { name: 'Restart' })).toBeEnabled())
await userEvent.click(screen.getByRole('button', { name: 'Pipeline options' }))
expect(await screen.findByRole('menuitem', { name: 'Stop pipeline' })).toBeVisible()
expect(screen.queryByRole('menuitem', { name: 'Restart pipeline' })).not.toBeInTheDocument()
})
test('keeps an available update visible and opens its modal', async () => {
mockStatus('started')
mockVersion(true)
renderLayout()
const updateButton = await screen.findByRole('button', { name: 'Update available' })
expect(updateButton).toHaveClass('bg-brand-400')
await userEvent.click(updateButton)
// The trigger button shares this name, so match the dialog's heading specifically
expect(await screen.findByRole('heading', { name: 'Update available' })).toBeVisible()
})
})