mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 11:25:06 +03:00
## What kind of change does this PR introduce? Feature. ## What is the current behaviour? Keyboard shortcuts can be discovered piecemeal through command palette entries, tooltips, and preferences, but there is no universal shortcut reference surface. ## What is the new behaviour? Adds a global `Mod+/` shortcut and command palette action to open a keyboard shortcuts reference sheet. The sheet renders registered shortcuts grouped from general dashboard actions through navigation and more specific surfaces. | Preview | | --- | | <img width="820" height="928" alt="CleanShot 2026-04-24 at 11 27 51@2x" src="https://github.com/user-attachments/assets/8ceb4a35-7adc-474b-8702-5c08a4219d25" /> | <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a comprehensive keyboard shortcuts reference sheet that displays all available shortcuts organized into logical categories. * New keyboard shortcut Mod+/ (Cmd+/ on Mac) opens the reference sheet instantly from anywhere within the application. * Shortcuts are displayed with their formatted keyboard combinations, with multi-step sequences clearly separated for easy reference and discovery. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { act, render, screen } from '@testing-library/react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { GlobalShortcuts } from './GlobalShortcuts'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
|
|
const { mockSetCommandMenuOpen, mockUseShortcut } = vi.hoisted(() => ({
|
|
mockSetCommandMenuOpen: vi.fn(),
|
|
mockUseShortcut: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('ui-patterns/CommandMenu', () => ({
|
|
useSetCommandMenuOpen: () => mockSetCommandMenuOpen,
|
|
}))
|
|
|
|
vi.mock('@/state/shortcuts/useShortcut', () => ({
|
|
useShortcut: mockUseShortcut,
|
|
}))
|
|
|
|
vi.mock('./ShortcutsReferenceSheet', () => ({
|
|
ShortcutsReferenceSheet: ({ open }: { open: boolean }) => (
|
|
<div data-testid="shortcuts-reference-sheet" data-open={open} />
|
|
),
|
|
}))
|
|
|
|
describe('GlobalShortcuts', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('registers the shortcuts reference action in the command palette', () => {
|
|
render(<GlobalShortcuts />)
|
|
|
|
expect(mockUseShortcut).toHaveBeenCalledWith(
|
|
SHORTCUT_IDS.SHORTCUTS_OPEN_REFERENCE,
|
|
expect.any(Function),
|
|
{ registerInCommandMenu: true }
|
|
)
|
|
})
|
|
|
|
it('closes the command palette and opens the shortcuts reference sheet', () => {
|
|
render(<GlobalShortcuts />)
|
|
|
|
const openReference = mockUseShortcut.mock.calls[0][1]
|
|
act(() => openReference())
|
|
|
|
expect(mockSetCommandMenuOpen).toHaveBeenCalledWith(false)
|
|
expect(screen.getByTestId('shortcuts-reference-sheet')).toHaveAttribute('data-open', 'true')
|
|
})
|
|
})
|