mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Part 4 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 | Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime | | **4** | **#54307 ← this PR** | **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/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/` off `next/link`. **Changed:** - Replaced `next/link` across all 72 files in Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, and Compute interfaces - Updated legacy permanent-redirect hrefs (`/settings/database` → `/database/settings`, `/settings/vault/secrets` → `/integrations/vault/secrets`, `/reports/database#database-size-report` → `/observability/database#database-size-report`) to canonical routes - Flattened legacy nested `<Link><a>...</a></Link>` markup in `DatabaseReadOnlyAlert.tsx` and dropped `passHref` in `Integrations/Queues/QueueTab.tsx` - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` + `DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links in `DatabaseReadOnlyAlert.tsx` per review feedback - Removed `vi.mock('next/link', ...)` from `Settings/General/Project.test.tsx` and `MobileIssuesNavigation.platform.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across Integrations (marketplace, cron, queues, wrappers, Vercel/GitHub), Settings (database, infrastructure, read replicas, logs), Observability, Issues, and Compute pages - [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL queries in search params - [ ] Verify billing and database-size links preserve query parameters and hash fragments --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
138 lines
4.6 KiB
TypeScript
138 lines
4.6 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import type { ReactNode } from 'react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { Project } from './Project'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
|
|
const { mockUseIsFeatureEnabled, mockUseProjectPauseStatusQuery, mockUseSelectedProjectQuery } =
|
|
vi.hoisted(() => ({
|
|
mockUseIsFeatureEnabled: vi.fn(),
|
|
mockUseProjectPauseStatusQuery: vi.fn(),
|
|
mockUseSelectedProjectQuery: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('ui-patterns/PageSection', () => ({
|
|
PageSection: ({ children, id }: { children: ReactNode; id?: string }) => (
|
|
<section id={id}>{children}</section>
|
|
),
|
|
PageSectionContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
PageSectionDescription: ({ children }: { children: ReactNode }) => <p>{children}</p>,
|
|
PageSectionMeta: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
PageSectionSummary: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
PageSectionTitle: ({ children }: { children: ReactNode }) => <h2>{children}</h2>,
|
|
}))
|
|
|
|
vi.mock('@/components/interfaces/Project/ResumeProjectButton', () => ({
|
|
ResumeProjectButton: () => <div>ResumeProjectButton</div>,
|
|
}))
|
|
|
|
vi.mock('./Infrastructure/PauseProjectButton', () => ({
|
|
PauseProjectButton: () => <div>PauseProjectButton</div>,
|
|
}))
|
|
|
|
vi.mock('./Infrastructure/RestartServerButton', () => ({
|
|
RestartServerButton: () => <div>RestartServerButton</div>,
|
|
}))
|
|
|
|
vi.mock('@/data/projects/project-pause-status-query', () => ({
|
|
useProjectPauseStatusQuery: mockUseProjectPauseStatusQuery,
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
|
|
useIsFeatureEnabled: mockUseIsFeatureEnabled,
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useSelectedProject', () => ({
|
|
useSelectedProjectQuery: mockUseSelectedProjectQuery,
|
|
}))
|
|
|
|
describe('Project settings availability', () => {
|
|
beforeEach(() => {
|
|
mockUseIsFeatureEnabled.mockReturnValue({
|
|
projectSettingsRestartProject: true,
|
|
})
|
|
|
|
mockUseProjectPauseStatusQuery.mockReturnValue({
|
|
data: undefined,
|
|
isError: false,
|
|
isSuccess: false,
|
|
})
|
|
})
|
|
|
|
it('shows the restart action for active projects', () => {
|
|
mockUseSelectedProjectQuery.mockReturnValue({
|
|
data: {
|
|
parent_project_ref: null,
|
|
ref: 'active-project',
|
|
status: 'ACTIVE_HEALTHY',
|
|
},
|
|
})
|
|
|
|
customRender(<Project />)
|
|
|
|
expect(screen.getByText('Restart project')).toBeInTheDocument()
|
|
expect(screen.getByText('RestartServerButton')).toBeInTheDocument()
|
|
expect(screen.getByText('Pause project')).toBeInTheDocument()
|
|
expect(screen.getByText('PauseProjectButton')).toBeInTheDocument()
|
|
expect(screen.queryByText('ResumeProjectButton')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('shows the shared resume action for paused projects that can still be restored', () => {
|
|
mockUseSelectedProjectQuery.mockReturnValue({
|
|
data: {
|
|
parent_project_ref: null,
|
|
ref: 'paused-project',
|
|
status: 'INACTIVE',
|
|
},
|
|
})
|
|
|
|
mockUseProjectPauseStatusQuery.mockReturnValue({
|
|
data: { can_restore: true },
|
|
isError: false,
|
|
isSuccess: true,
|
|
})
|
|
|
|
customRender(<Project />)
|
|
|
|
expect(screen.getByText('Resume project')).toBeInTheDocument()
|
|
expect(screen.getByText('Bring your paused project back online.')).toBeInTheDocument()
|
|
expect(screen.getByText('ResumeProjectButton')).toBeInTheDocument()
|
|
expect(screen.queryByText('Pause project')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('PauseProjectButton')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('RestartServerButton')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('links back to the dashboard when the paused project can no longer be restored', () => {
|
|
mockUseSelectedProjectQuery.mockReturnValue({
|
|
data: {
|
|
parent_project_ref: null,
|
|
ref: 'paused-project',
|
|
status: 'INACTIVE',
|
|
},
|
|
})
|
|
|
|
mockUseProjectPauseStatusQuery.mockReturnValue({
|
|
data: { can_restore: false },
|
|
isError: false,
|
|
isSuccess: true,
|
|
})
|
|
|
|
customRender(<Project />)
|
|
|
|
expect(screen.getAllByText('View project dashboard')).toHaveLength(2)
|
|
expect(
|
|
screen.getByText(
|
|
'This project can no longer be resumed here. Open the dashboard to download backups and view recovery options.'
|
|
)
|
|
).toBeInTheDocument()
|
|
expect(screen.getByRole('link', { name: 'View project dashboard' })).toHaveAttribute(
|
|
'href',
|
|
'/project/paused-project'
|
|
)
|
|
expect(screen.queryByText('Pause project')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('PauseProjectButton')).not.toBeInTheDocument()
|
|
expect(screen.queryByText('ResumeProjectButton')).not.toBeInTheDocument()
|
|
})
|
|
})
|