Files
Danny White 6f6badae51 fix(eslint): promote require-explicit-tabindex to error (#48170)
## What kind of change does this PR introduce?

Accessibility / lint hardening (Safari keyboard focus).

## What is the current behavior?

`supabase/require-explicit-tabindex` is `'warn'`. Studio’s ratchet was
at 0 but the rule was still ratcheted; www / docs / design-system still
had raw `<button>` / `role="button"` call sites without an explicit
`tabIndex`.

[DEPR-627](https://linear.app/supabase/issue/DEPR-627) · follow-up to
#47984 / #48040

## What is the new behavior?

- Shared config: `'supabase/require-explicit-tabindex': 'error'`
- Swept www / docs / design-system (+ Studio test fixtures the ratchet
skipped)
- Removed the rule from the Studio ratchet + baselines

## To test

Prefer **Safari**. This PR only adds explicit `tabIndex` to raw
`<button>` / `role="button"` call sites — not links, and not controls
that already go through `Button` from `ui`.

### Marketing (`www`) ([staging
link](https://zone-www-dot-com-git-danny-depr-627-promote-req-7ae43c-supabase.vercel.app/))

- [x] Homepage frameworks / dashboard feature tabs — Tab through each
tab button
- [x] Product pages (e.g. `/auth`, `/database`) — section tab switchers
- [x] Narrow viewport — open the hamburger; Tab through menu buttons
- [x] `/partners/catalog` — filter / view controls
- [x] Blog view toggle (list ↔ grid)

### Docs ([staging
link](https://docs-git-danny-depr-627-promote-require-explici-25e46d-supabase.vercel.app/))

- [x] **Desktop (≥ lg):** top-right **⋯ menu** (hamburger icon) — opens
a dropdown that includes Theme. Not a separate theme button.
- [x] **Mobile (< lg):** top-right **hamburger** opens the sheet; close
(X) is the raw button we tagged. Theme inside the sheet uses
`ThemeToggle` / `DropdownMenuTrigger` from `ui` (already supposed to set
`tabIndex`).
- [x] **Code blocks** — copy / language controls
- [x] **Is this helpful?** — X / check are `Button` from `ui` (should
already Tab). After voting **while signed in**, the follow-up “What went
well?” / “How can we improve?” text button is the raw one we tagged.
- [x] **AI Tools → Copy as Markdown** (right rail on a guide) — this is
the only GuidesSidebar control this PR changed. “On this page” TOC items
are **links**, not covered by this lint.
- [x] **Reference docs** (e.g. JS client reference) — section headers
that expand/collapse in the left nav (`Collapsible.Trigger`)
- [x] **Troubleshooting index** — type in the search field, then Tab to
the **clear (X)** control

### Dashboard (`studio`)

No production UI changes in this PR (tests + lint config only). Quick
Safari smoke that prior tabindex work still holds:

- [x] Project sidebar — Tab through primary nav links
- [x] Settings → General — Tab through inputs / buttons
- [x] Storage → Files — Tab a bucket row / file actions
2026-07-23 05:21:15 +10:00

167 lines
5.2 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import type { ReactNode } from 'react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { Project } from './Project'
const { mockUseIsFeatureEnabled, mockUseProjectPauseStatusQuery, mockUseSelectedProjectQuery } =
vi.hoisted(() => ({
mockUseIsFeatureEnabled: vi.fn(),
mockUseProjectPauseStatusQuery: vi.fn(),
mockUseSelectedProjectQuery: vi.fn(),
}))
vi.mock('next/link', () => ({
default: ({ href, children }: { href: string; children: ReactNode }) => (
<a href={href}>{children}</a>
),
}))
vi.mock('ui', () => ({
Button: ({
children,
asChild,
type: _type,
...props
}: {
children: ReactNode
asChild?: boolean
type?: string
}) =>
asChild ? (
<>{children}</>
) : (
<button tabIndex={0} {...props}>
{children}
</button>
),
Card: ({ children }: { children: ReactNode }) => <div>{children}</div>,
CardContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
}))
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(() => {
vi.clearAllMocks()
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',
},
})
render(<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,
})
render(<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,
})
render(<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()
})
})