mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 3 of a 6-PR stack migrating all `next/link` imports in `apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known external URLs) and removing `compat/next/link.tsx`. | Part | PR | Scope | | --- | --- | --- | | 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and `components/ui/**` | | 2 | #54305 | `components/layouts/**` and top-level shell components | | **3** | **#54306 ← this PR** | **Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime** | | 4 | #54307 | Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute | | 5 | #54308 | Remaining `components/interfaces/**` (Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.) | | 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and update basePath tests/docs | Migrates `components/interfaces/{Database,TableGridEditor,Storage,SQLEditor,BranchManagement,Branching,Functions,Realtime}/` off `next/link`. **Changed:** - Replaced `next/link` across all 60 importing files in Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, and Realtime interfaces - Updated legacy permanent-redirect hrefs (`/reports` → `/observability`, `/database/schema` → `/database/schemas`) to their canonical TanStack routes - Dropped legacy `passHref` in `GridHeaderActions.tsx`, removed duplicate `RouterLink` alias in `ChooseFunctionForm.tsx`, and removed `vi.mock('next/link', ...)` in `ReplicationPipelineLayout.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Check Table Editor, SQL Editor, Database (tables, policies, functions, triggers, replication, backups), Storage (files/analytics/vector buckets), Edge Functions, Branching, and Realtime links - [ ] Verify SQL Editor and Table Editor links with query parameters (`schema`, `content`, `search`) do not double-encode values --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
488 lines
18 KiB
TypeScript
488 lines
18 KiB
TypeScript
import { QueryClient, useQueryClient } from '@tanstack/react-query'
|
|
import { act, fireEvent, screen, waitFor, within } 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, useRef } from 'react'
|
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { ReplicationPipelineLayout } from './ReplicationPipelineLayout'
|
|
import { ReplicationPipelineStatus } from './ReplicationPipelineStatus/ReplicationPipelineStatus'
|
|
import type { DestinationWireResponse, PipelineWireResponse } from '@/data/replication/api-types'
|
|
import { replicationKeys } from '@/data/replication/keys'
|
|
import {
|
|
PipelineRequestStatusProvider,
|
|
PipelineStatusRequestStatus,
|
|
usePipelineRequestStatus,
|
|
} from '@/state/replication-pipeline-request-status'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
|
|
|
|
mockAnimationsApi()
|
|
|
|
const routeParams = vi.hoisted(() => ({ ref: 'default', pipelineId: '42' }))
|
|
|
|
// 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: () => routeParams,
|
|
}))
|
|
|
|
const renderLayout = (children?: ReactNode, queryClient?: QueryClient) =>
|
|
customRender(
|
|
<PipelineRequestStatusProvider>
|
|
<ReplicationPipelineLayout>{children}</ReplicationPipelineLayout>
|
|
</PipelineRequestStatusProvider>,
|
|
{ queryClient }
|
|
)
|
|
|
|
const TableResetFixture = () => {
|
|
const queryClient = useQueryClient()
|
|
const { runWithRequestStatus } = usePipelineRequestStatus()
|
|
const finishReset = useRef<() => void>(() => {})
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
tabIndex={0}
|
|
onClick={() =>
|
|
void runWithRequestStatus(
|
|
'42',
|
|
PipelineStatusRequestStatus.StopRequested,
|
|
() =>
|
|
new Promise<void>((resolve) => {
|
|
finishReset.current = resolve
|
|
})
|
|
)
|
|
}
|
|
>
|
|
Begin table reset
|
|
</button>
|
|
<button
|
|
tabIndex={0}
|
|
onClick={async () => {
|
|
finishReset.current()
|
|
await queryClient.invalidateQueries({
|
|
queryKey: replicationKeys.pipelinesStatus('default', '42'),
|
|
})
|
|
}}
|
|
>
|
|
Finish table reset
|
|
</button>
|
|
</>
|
|
)
|
|
}
|
|
|
|
type PipelineResponse = PipelineWireResponse<components['schemas']['PipelineResponse_Output']>
|
|
type PipelineStatusResponse = PipelineWireResponse<
|
|
components['schemas']['PipelineStatusResponse_Output']
|
|
>
|
|
type PipelineReplicationStatusResponse = PipelineWireResponse<
|
|
components['schemas']['PipelineReplicationStatusResponse_Output']
|
|
>
|
|
type PipelineVersionResponse = PipelineWireResponse<
|
|
components['schemas']['PipelineVersionResponse_Output']
|
|
>
|
|
type DestinationResponse = DestinationWireResponse<
|
|
components['schemas']['DestinationResponse_Output']
|
|
>
|
|
type DestinationsResponse = DestinationWireResponse<
|
|
components['schemas']['DestinationsResponse_Output']
|
|
>
|
|
type PipelinesResponse = PipelineWireResponse<components['schemas']['PipelinesResponse_Output']>
|
|
type SourcesResponse = components['schemas']['SourcesResponse_Output']
|
|
|
|
const PIPELINE: PipelineResponse = {
|
|
id: 42,
|
|
cluster_id: 'cluster',
|
|
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 = (id: string | number = 42, destination = DESTINATION) => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id',
|
|
response: () => HttpResponse.json<PipelineResponse>({ ...PIPELINE, id }),
|
|
})
|
|
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, id }] }),
|
|
})
|
|
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'], id: string | number = 42) =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/status',
|
|
response: () =>
|
|
HttpResponse.json<PipelineStatusResponse>({ pipeline_id: id, status: { name } }),
|
|
})
|
|
|
|
const mockVersion = (hasUpdate: boolean, id: string | number = 42) =>
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/version',
|
|
response: () =>
|
|
HttpResponse.json<PipelineVersionResponse>({
|
|
pipeline_id: id,
|
|
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(() => {
|
|
routeParams.pipelineId = '42'
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref',
|
|
response: () => HttpResponse.json<APIErrorBody>({ message: 'Unavailable' }, { status: 404 }),
|
|
})
|
|
mockPipeline()
|
|
mockVersion(false)
|
|
})
|
|
|
|
test.each(['started', 'stopped', 'failed'] as const)(
|
|
'only allows stopping and deletion for an unknown destination when %s',
|
|
async (status) => {
|
|
mockPipeline('42', { ...DESTINATION, config: { unknown: {} } })
|
|
mockStatus(status, '42')
|
|
mockVersion(true, '42')
|
|
|
|
renderLayout(<ReplicationPipelineStatus />)
|
|
|
|
expect(await screen.findByRole('img', { name: 'Unknown destination' })).toBeVisible()
|
|
expect(
|
|
screen.queryByRole('button', { name: /^(Start|Restart|Update available)$/ })
|
|
).not.toBeInTheDocument()
|
|
expect(screen.queryByRole('button', { name: /Reset/ })).not.toBeInTheDocument()
|
|
if (status === 'stopped') {
|
|
expect(screen.queryByRole('button', { name: 'Stop' })).not.toBeInTheDocument()
|
|
} else {
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/stop',
|
|
response: () => {
|
|
mockStatus('stopped', '42')
|
|
return HttpResponse.json<Record<string, never>>({}, { status: 202 })
|
|
},
|
|
})
|
|
await screen.findByText(status === 'started' ? 'Running' : 'Failed')
|
|
expect(screen.getByRole('button', { name: 'Stop' })).toBeEnabled()
|
|
await userEvent.click(screen.getByRole('button', { name: 'Stop' }))
|
|
expect(await screen.findByText('Stopped')).toBeVisible()
|
|
expect(screen.queryByRole('button', { name: 'Start' })).not.toBeInTheDocument()
|
|
}
|
|
await userEvent.click(screen.getByRole('button', { name: 'Pipeline options' }))
|
|
expect(screen.getAllByRole('menuitem').map((item) => item.textContent)).toEqual([
|
|
'Delete pipeline',
|
|
])
|
|
await userEvent.click(screen.getByRole('menuitem', { name: 'Delete pipeline' }))
|
|
expect(await screen.findByPlaceholderText('Type the pipeline name')).toBeVisible()
|
|
}
|
|
)
|
|
|
|
test('blocks direct edit URLs for unknown destinations even with a creation type in the URL', async () => {
|
|
mockPipeline('42', { ...DESTINATION, config: { unknown: {} } })
|
|
mockStatus('stopped', '42')
|
|
mockVersion(false, '42')
|
|
|
|
customRender(
|
|
<PipelineRequestStatusProvider>
|
|
<ReplicationPipelineLayout />
|
|
</PipelineRequestStatusProvider>,
|
|
{ nuqs: { searchParams: '?edit=7&destinationType=BigQuery' } }
|
|
)
|
|
|
|
const dialog = await screen.findByRole('dialog')
|
|
expect(await within(dialog).findByText('Unknown destination')).toBeVisible()
|
|
expect(within(dialog).queryByRole('textbox')).not.toBeInTheDocument()
|
|
})
|
|
|
|
test('keeps stopping available without allowing edits when the destination lookup fails', async () => {
|
|
mockPipeline('42')
|
|
mockStatus('started', '42')
|
|
mockVersion(false, '42')
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/destinations/:destination_id',
|
|
response: () =>
|
|
HttpResponse.json<APIErrorBody>({ message: 'Destination unavailable' }, { status: 500 }),
|
|
})
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/stop',
|
|
response: () => {
|
|
mockStatus('stopped', '42')
|
|
return HttpResponse.json<Record<string, never>>({}, { status: 202 })
|
|
},
|
|
})
|
|
|
|
customRender(
|
|
<PipelineRequestStatusProvider>
|
|
<ReplicationPipelineLayout />
|
|
</PipelineRequestStatusProvider>,
|
|
{ nuqs: { searchParams: '?edit=7&destinationType=BigQuery' } }
|
|
)
|
|
|
|
await waitFor(() =>
|
|
expect(
|
|
within(screen.getByRole('dialog')).getByText('Failed to retrieve destination information')
|
|
).toBeVisible()
|
|
)
|
|
const dialog = screen.getByRole('dialog')
|
|
expect(within(dialog).queryByRole('textbox')).not.toBeInTheDocument()
|
|
await userEvent.keyboard('{Escape}')
|
|
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
|
expect(screen.getByRole('button', { name: 'Stop' })).toBeEnabled()
|
|
await userEvent.click(screen.getByRole('button', { name: 'Stop' }))
|
|
expect(await screen.findByText('Stopped')).toBeVisible()
|
|
})
|
|
|
|
test('deletes an unknown pipeline through the existing shutdown and cleanup flow', async () => {
|
|
mockPipeline('42', { ...DESTINATION, config: { unknown: {} } })
|
|
mockStatus('started', '42')
|
|
mockVersion(false, '42')
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/stop',
|
|
response: () => {
|
|
mockStatus('stopping', '42')
|
|
return HttpResponse.json<Record<string, never>>({}, { status: 202 })
|
|
},
|
|
})
|
|
addAPIMock({
|
|
method: 'delete',
|
|
path: '/platform/replication/:ref/destinations-pipelines/:destination_id/:pipeline_id',
|
|
response: () =>
|
|
HttpResponse.json<
|
|
PipelineWireResponse<components['schemas']['DeleteDestinationPipelineResponse_Output']>
|
|
>({
|
|
destination_deleted: true,
|
|
destination_id: 7,
|
|
pipeline_id: '42',
|
|
}),
|
|
})
|
|
const queryClient = new QueryClient()
|
|
renderLayout(undefined, queryClient)
|
|
await screen.findByRole('img', { name: 'Unknown destination' })
|
|
await userEvent.click(screen.getByRole('button', { name: 'Pipeline options' }))
|
|
await userEvent.click(screen.getByRole('menuitem', { name: 'Delete pipeline' }))
|
|
const dialog = await screen.findByRole('dialog')
|
|
await userEvent.click(within(dialog).getByPlaceholderText('Type the pipeline name'))
|
|
await userEvent.paste('Analytics warehouse')
|
|
await waitFor(() =>
|
|
expect(within(dialog).getByRole('button', { name: 'Delete pipeline' })).toBeEnabled()
|
|
)
|
|
fireEvent.submit(dialog.querySelector('form')!)
|
|
await screen.findByText('Stopping')
|
|
await act(() =>
|
|
queryClient.invalidateQueries({ queryKey: replicationKeys.pipelinesStatus('default', '42') })
|
|
)
|
|
expect(within(dialog).getByRole('button', { name: 'Deleting…' })).toBeDisabled()
|
|
|
|
mockStatus('stopped', '42')
|
|
await act(() =>
|
|
queryClient.invalidateQueries({ queryKey: replicationKeys.pipelinesStatus('default', '42') })
|
|
)
|
|
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
|
})
|
|
|
|
test.each([42, '42', '003l8j9rxqi6c8rd5mcx1w2ya'])(
|
|
'renders pipeline %s and stops it using its original ID',
|
|
async (pipelineId) => {
|
|
routeParams.pipelineId = String(pipelineId)
|
|
mockPipeline(pipelineId)
|
|
mockVersion(false, pipelineId)
|
|
mockStatus('started', pipelineId)
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/replication/:ref/pipelines/:pipeline_id/stop',
|
|
response: ({ params }) => {
|
|
if (params.pipeline_id !== String(pipelineId)) {
|
|
return HttpResponse.json<APIErrorBody>({ message: 'Unknown pipeline' }, { status: 404 })
|
|
}
|
|
mockStatus('stopped', pipelineId)
|
|
return HttpResponse.json<Record<string, never>>({}, { status: 202 })
|
|
},
|
|
})
|
|
|
|
renderLayout()
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).toBeVisible()
|
|
expect(await screen.findByText('Running')).toBeVisible()
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Stop' }))
|
|
expect(await screen.findByRole('button', { name: 'Start' })).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.queryByText('Running')).not.toBeInTheDocument()
|
|
|
|
resolvePipeline(PIPELINE)
|
|
|
|
expect(await screen.findByRole('heading', { name: 'Analytics warehouse' })).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(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')).toBeVisible()
|
|
})
|
|
|
|
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
|
|
const restartAction = await screen.findByRole('menuitem', { name: 'Restart pipeline' })
|
|
expect(restartAction).toBeVisible()
|
|
expect(restartAction).toHaveAccessibleDescription(
|
|
'Resume saved progress. Unfinished initial syncs start over.'
|
|
)
|
|
expect(screen.queryByRole('menuitem', { name: 'Stop pipeline' })).not.toBeInTheDocument()
|
|
})
|
|
|
|
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' })
|
|
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()
|
|
})
|
|
})
|