Files
supabase/apps/studio/components/interfaces/Settings/General/ServiceVersions/ServiceVersionsSection.test.tsx
Monica Khoury c31c7afb1b fix(studio): add latest-version hint to Postgres version field (#52143)
## Problem

On the General settings page, the Service versions card shows the
versions as disabled inputs. When a project is already up to date,
nothing explains that Postgres updates would show up in this section, or
where to learn more.

Resolves FE-4604:
https://linear.app/supabase/issue/FE-4604/add-hint-regarding-database-versioning

## Solution

Adds a subtle description under the Postgres version field, using the
existing `description` prop on `FormItemLayout`:

> This project is already on the latest version of Postgres that
Supabase supports. Updates will appear here when available. Learn more

"Learn more" links to the upgrading guide. It is tertiary information,
so it is a field description and not an admonition (changed after design
feedback).

It only shows when the project is on the latest version, database
upgrades are enabled, and the project is not on a K8s cloud provider.
The condition is one named boolean, `canShowLatestVersionHint`.
Component tests cover the visible case and the hidden cases.

## How to test

1. Run Studio and open a project's General settings page.
2. On a project already on the latest Postgres version, check that the
description appears under the Postgres version field, next to the
"Latest" badge.
3. Click "Learn more" and check that the upgrading guide opens in a new
tab.
4. On a project with an upgrade available, check that only the upgrade
alert shows and the description does not.
2026-10-26 18:20:05 +02:00

366 lines
12 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import type { InputHTMLAttributes, ReactNode } from 'react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ServiceVersionsSection } from './ServiceVersionsSection'
const {
mockUseFeatures,
mockUseIsOrioleDb,
mockUseProject,
mockUseReadReplicas,
mockUseServiceVersions,
mockUseUpgradeEligibility,
mockIsAwsK8sCloudProvider,
} = vi.hoisted(() => ({
mockUseFeatures: vi.fn(),
mockUseIsOrioleDb: vi.fn(),
mockUseProject: vi.fn(),
mockUseReadReplicas: vi.fn(),
mockUseServiceVersions: vi.fn(),
mockUseUpgradeEligibility: vi.fn(),
mockIsAwsK8sCloudProvider: vi.fn(),
}))
vi.mock('common', () => ({
useParams: () => ({ ref: 'project-ref' }),
}))
vi.mock('ui', () => ({
Badge: ({ children }: { children: ReactNode }) => <span>{children}</span>,
Card: ({ children }: { children: ReactNode }) => <div>{children}</div>,
CardContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
Input: (props: InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
InputGroup: ({ children }: { children: ReactNode }) => <div>{children}</div>,
InputGroupAddon: ({ children }: { children: ReactNode }) => <div>{children}</div>,
InputGroupInput: (props: InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
Tooltip: ({ children }: { children: ReactNode }) => <>{children}</>,
TooltipContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
TooltipTrigger: ({ children }: { children: ReactNode }) => <>{children}</>,
}))
vi.mock('ui-patterns/Admonition', () => ({
Admonition: ({
title,
description,
children,
}: {
title?: ReactNode
description?: ReactNode
children?: ReactNode
}) => (
<div>
<div>{title}</div>
<div>{description}</div>
{children}
</div>
),
}))
vi.mock('ui-patterns/form/FormItemLayout/FormItemLayout', () => ({
FormItemLayout: ({
label,
description,
children,
}: {
label: ReactNode
description?: ReactNode
children: ReactNode
}) => (
<label>
{label}
{children}
{description && <div>{description}</div>}
</label>
),
}))
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('ui-patterns/ShimmeringLoader', () => ({
GenericSkeletonLoader: () => <div>Loading service versions</div>,
}))
vi.mock('../../Infrastructure/UpgradeWarnings', () => ({
ReadReplicasWarning: ({ latestPgVersion }: { latestPgVersion?: string }) => (
<div>Read replicas block upgrade to {latestPgVersion}</div>
),
ValidationErrorsWarning: ({ validationErrors }: { validationErrors?: string[] }) => (
<div>Validation errors: {validationErrors?.join(', ')}</div>
),
ValidationWarningsAdmonition: ({ warnings }: { warnings?: string[] }) => (
<div>Validation warnings: {warnings?.join(', ')}</div>
),
}))
vi.mock('../Infrastructure/ProjectUpgradeAlert', () => ({
ProjectUpgradeAlert: () => <div>Project upgrade available</div>,
}))
vi.mock('@/components/ui/AlertError', () => ({
AlertError: ({ subject }: { subject: string }) => <div>{subject}</div>,
}))
vi.mock('@/components/ui/InlineLink', () => ({
InlineLink: ({ href, children }: { href: string; children: ReactNode }) => (
<a href={href}>{children}</a>
),
}))
vi.mock('@/data/config/project-upgrade-eligibility-query', () => ({
useProjectUpgradeEligibilityQuery: mockUseUpgradeEligibility,
}))
vi.mock('@/data/projects/project-service-versions', () => ({
useProjectServiceVersionsQuery: mockUseServiceVersions,
}))
vi.mock('@/data/read-replicas/replicas-query', () => ({
useReadReplicasQuery: mockUseReadReplicas,
}))
vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
useIsFeatureEnabled: mockUseFeatures,
}))
vi.mock('@/hooks/misc/useSelectedProject', () => ({
useIsOrioleDb: mockUseIsOrioleDb,
useSelectedProjectQuery: mockUseProject,
useIsAwsK8sCloudProvider: mockIsAwsK8sCloudProvider,
}))
const LATEST_VERSION_HINT = 'This project is already on the latest version of Postgres'
const latestVersionEligibility = {
data: {
current_app_version: 'supabase-postgres-17.4.1.060',
latest_app_version: 'supabase-postgres-17.4.1.060',
eligible: false,
validation_errors: [],
warnings: [],
},
error: undefined,
isPending: false,
isError: false,
isSuccess: true,
}
describe('ServiceVersionsSection', () => {
beforeEach(() => {
mockUseFeatures.mockReturnValue({
projectAuthAll: true,
projectSettingsDatabaseUpgrades: true,
})
mockUseIsOrioleDb.mockReturnValue(false)
mockUseProject.mockReturnValue({ data: { status: 'ACTIVE_HEALTHY' } })
mockIsAwsK8sCloudProvider.mockReturnValue(false)
mockUseReadReplicas.mockReturnValue({ data: [{ identifier: 'project-ref' }] })
mockUseUpgradeEligibility.mockReturnValue({
data: {
current_app_version: 'supabase-postgres-15.8.1.060',
current_app_version_release_channel: 'ga',
latest_app_version: 'supabase-postgres-17.4.1.060',
eligible: true,
validation_errors: [],
warnings: [],
},
error: undefined,
isPending: false,
isError: false,
isSuccess: true,
})
mockUseServiceVersions.mockReturnValue({
data: {
gotrue: '2.180.0',
postgrest: '12.2.8',
'supabase-postgres': '15.8.1.060',
},
error: undefined,
isPending: false,
isError: false,
isSuccess: true,
})
})
it('preserves the paused-project state without showing stale version values', () => {
mockUseProject.mockReturnValue({ data: { status: 'INACTIVE' } })
const { container } = render(<ServiceVersionsSection />)
expect(
screen.getByText('Service versions cannot be retrieved while project is paused')
).toBeInTheDocument()
expect(screen.queryByDisplayValue('12.2.8')).not.toBeInTheDocument()
expect(container.querySelector('#service-versions')).toBeInTheDocument()
})
it('renders Auth, PostgREST, and Postgres versions with release metadata', () => {
mockUseIsOrioleDb.mockReturnValue(true)
mockUseUpgradeEligibility.mockReturnValue({
data: {
current_app_version: 'supabase-postgres-17.4.1.060-orioledb',
current_app_version_release_channel: 'beta',
latest_app_version: 'supabase-postgres-17.4.1.060-orioledb',
eligible: true,
validation_errors: [],
warnings: [],
},
error: undefined,
isPending: false,
isError: false,
isSuccess: true,
})
render(<ServiceVersionsSection />)
expect(screen.getByDisplayValue('2.180.0')).toBeInTheDocument()
expect(screen.getByDisplayValue('12.2.8')).toBeInTheDocument()
expect(screen.getByDisplayValue('17.4.1.060')).toBeInTheDocument()
expect(screen.getAllByText('beta').length).toBeGreaterThan(0)
expect(screen.getAllByText('OrioleDB').length).toBeGreaterThan(0)
expect(screen.getAllByText('Latest').length).toBeGreaterThan(0)
expect(screen.getByText('Project upgrade available')).toBeInTheDocument()
})
it('shows the read-replica upgrade block instead of the upgrade action', () => {
mockUseReadReplicas.mockReturnValue({
data: [{ identifier: 'project-ref' }, { identifier: 'replica-1' }],
})
render(<ServiceVersionsSection />)
expect(screen.getByText('Read replicas block upgrade to 17.4.1.060')).toBeInTheDocument()
expect(screen.queryByText('Project upgrade available')).not.toBeInTheDocument()
expect(screen.queryByText(LATEST_VERSION_HINT, { exact: false })).not.toBeInTheDocument()
})
it('renders upgrade validation errors and warnings for an ineligible project', () => {
mockUseUpgradeEligibility.mockReturnValue({
data: {
current_app_version: 'supabase-postgres-15.8.1.060',
latest_app_version: 'supabase-postgres-17.4.1.060',
eligible: false,
validation_errors: ['Remove read replicas'],
warnings: ['Review extension compatibility'],
},
error: undefined,
isPending: false,
isError: false,
isSuccess: true,
})
render(<ServiceVersionsSection />)
expect(screen.getByText('Validation errors: Remove read replicas')).toBeInTheDocument()
expect(
screen.getByText('Validation warnings: Review extension compatibility')
).toBeInTheDocument()
expect(screen.queryByText('Project upgrade available')).not.toBeInTheDocument()
expect(screen.queryByText(LATEST_VERSION_HINT, { exact: false })).not.toBeInTheDocument()
})
it('preserves eligibility and service-version loading and error states', () => {
mockUseUpgradeEligibility
.mockReturnValueOnce({
data: undefined,
error: undefined,
isPending: true,
isError: false,
isSuccess: false,
})
.mockReturnValueOnce({
data: undefined,
error: new Error('eligibility failed'),
isPending: false,
isError: true,
isSuccess: false,
})
const { rerender } = render(<ServiceVersionsSection />)
expect(screen.getByText('Loading service versions')).toBeInTheDocument()
rerender(<ServiceVersionsSection />)
expect(screen.getByText('Failed to retrieve Postgres version')).toBeInTheDocument()
mockUseUpgradeEligibility.mockReturnValue({
data: {
current_app_version: 'supabase-postgres-15.8.1.060',
latest_app_version: 'supabase-postgres-17.4.1.060',
eligible: true,
},
error: undefined,
isPending: false,
isError: false,
isSuccess: true,
})
mockUseServiceVersions.mockReturnValue({
data: undefined,
error: new Error('versions failed'),
isPending: false,
isError: true,
isSuccess: false,
})
rerender(<ServiceVersionsSection />)
expect(screen.getByText('Failed to retrieve versions')).toBeInTheDocument()
})
it('shows the latest-version description with a docs link when on the latest version', () => {
mockUseUpgradeEligibility.mockReturnValue(latestVersionEligibility)
render(<ServiceVersionsSection />)
expect(screen.getByText(LATEST_VERSION_HINT, { exact: false })).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'Learn more' })).toHaveAttribute(
'href',
expect.stringContaining('/guides/platform/upgrading')
)
})
it('hides the latest-version description when database upgrades are disabled', () => {
mockUseFeatures.mockReturnValue({
projectAuthAll: true,
projectSettingsDatabaseUpgrades: false,
})
mockUseUpgradeEligibility.mockReturnValue(latestVersionEligibility)
render(<ServiceVersionsSection />)
expect(screen.queryByText(LATEST_VERSION_HINT, { exact: false })).not.toBeInTheDocument()
})
it.each([
['an eligible upgrade', { eligible: true }],
['a validation error', { validation_errors: ['Remove read replicas'] }],
['a warning', { warnings: ['Review extension compatibility'] }],
])('hides the latest-version description when eligibility reports %s', (_, overrides) => {
mockUseUpgradeEligibility.mockReturnValue({
...latestVersionEligibility,
data: { ...latestVersionEligibility.data, ...overrides },
})
render(<ServiceVersionsSection />)
expect(screen.queryByText(LATEST_VERSION_HINT, { exact: false })).not.toBeInTheDocument()
})
it('does not offer upgrade for v3 projects', () => {
mockIsAwsK8sCloudProvider.mockReturnValue(true)
mockUseUpgradeEligibility.mockReturnValue(latestVersionEligibility)
render(<ServiceVersionsSection />)
expect(screen.queryByText('Project upgrade available')).not.toBeInTheDocument()
expect(screen.queryByText(LATEST_VERSION_HINT, { exact: false })).not.toBeInTheDocument()
})
})