Files
supabase/apps/studio/components/interfaces/Settings/Infrastructure/UpgradeWarnings.test.tsx
Alaister YoungandAlaister Young b5d9f22f14 fix(studio): handle unknown upgrade warning types (#52775)
Fixes a page crash on Project Settings > General. The upgrade
eligibility API now returns a warning type
(`collation_reindex_required`) that Studio doesn't handle, so
`getWarningLink` returned `undefined` and `<Link href={undefined}>`
threw in `resolveHref`, taking the page down via the global error
boundary.

**Changed:**
- Added `default` cases to the warning title, description, and link
helpers in `UpgradeWarnings.tsx`. Unknown warning types now show generic
copy and link to the specific upgrade notes section of the docs, rather
than being hidden or crashing.

**Added:**
- `UpgradeWarnings.test.tsx`, covering a known warning type and an
unknown one. The unknown case failed with `href` undefined before this
change.

**Not in this PR:**
- Dedicated copy for `collation_reindex_required`. That needs
regenerated `api-types` and an upgrade guide section, which doesn't
exist yet.
- Open tabs on old bundles keep crashing until they reload, since this
fix only reaches new bundles.

## To test

- Open Project Settings > General on a project whose
`/upgrade/eligibility` response includes `collation_reindex_required`.
The page should load and show "Review the upgrade notes before
upgrading".
- Check that "Read upgrade notes" goes to the specific upgrade notes
section of the upgrading guide.
- Check that a known warning type, such as `ltree_reindex_required`,
still shows its own copy and link.

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-04 18:35:03 +08:00

37 lines
1.6 KiB
TypeScript

import { screen } from '@testing-library/react'
import { describe, expect, it } from 'vitest'
import { ValidationWarningsAdmonition } from './UpgradeWarnings'
import { ProjectUpgradeEligibilityWarning } from '@/data/config/project-upgrade-eligibility-query'
import { customRender } from '@/tests/lib/custom-render'
describe('ValidationWarningsAdmonition', () => {
it('renders the specific copy and link for a known warning type', () => {
customRender(<ValidationWarningsAdmonition warnings={[{ type: 'ltree_reindex_required' }]} />)
expect(
screen.getByText('ltree indexes must be reindexed after this upgrade')
).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'Read upgrade notes' })).toHaveAttribute(
'href',
expect.stringContaining('#ltree-indexes-require-reindexing-after-upgrade')
)
})
// The API can ship new warning types before Studio knows about them, and old
// browser tabs keep running old bundles, so an unknown type must not crash the page.
it('renders fallback copy and a link for a warning type Studio does not know about', () => {
const unknownWarning = {
type: 'some_future_warning',
} as unknown as ProjectUpgradeEligibilityWarning
customRender(<ValidationWarningsAdmonition warnings={[unknownWarning]} />)
expect(screen.getByText('Review the upgrade notes before upgrading')).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'Read upgrade notes' })).toHaveAttribute(
'href',
expect.stringContaining('/guides/platform/upgrading#specific-upgrade-notes')
)
})
})