Files
supabase/apps/studio/lib/navigation.test.ts
Danny White 2e435986c9 feat(studio): polish the Replication pipelines list (#50252)
## What kind of change does this PR introduce?

Studio UI and interaction polish. This is the second PR in the Pipelines
review stack and depends on #50251.

## What is the current behaviour?

Pipeline rows require a separate view action, cannot be sorted, and
present lifecycle, lag, and destination terminology inconsistently.

## What is the new behaviour?

Makes rows navigable with link-like mouse and keyboard behaviour, adds
Name and Status sorting, reuses cached status queries, and moves row
actions into the overflow menu. It also clarifies pipeline terminology,
adds Docs and feedback actions, and standardises state, error, lag, and
loading presentation with accessible announcements.

| Before | After |
| --- | --- |
| <img width="1280" height="1323" alt="Replication Database ETL BigTable
ETL Team Supabase"
src="https://github.com/user-attachments/assets/53a62283-0e58-4408-8409-2b87a38af159"
/> | <img width="1280" height="1323" alt="Replication Database Agua
Basket Supabase"
src="https://github.com/user-attachments/assets/ba4de1e0-4a84-43b4-8975-ca05a3056bcf"
/> |

## To test

1. Open `/project/<ref>/database/replication`.
2. Sort by Name and Status, then confirm failed and stopped pipelines
surface first when Status is ascending.
3. Click a row, use Enter or Space, and modifier-click or middle-click
to verify link behaviour.
4. Open the row overflow menu and confirm it does not navigate.
5. Check loading, initial sync, caught up, numeric lag, unavailable lag,
and table-error states where available.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added sortable pipeline lists with clearer loading, empty, and error
states.
- Pipeline rows now support direct navigation, detail viewing, status
indicators, lag progress, and table error summaries.
- Added initial-sync progress indicators and accessible status
announcements.
  - Added documentation and feedback links.
  - Improved pipeline version update and enable/disable dialogs.

- **Bug Fixes**
  - Prevented right-clicks from triggering navigation.
  - Improved unavailable lag and initial-sync handling.

- **Style**
- Standardized replication terminology and confirmation messaging around
pipelines.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-15 10:07:49 +10:00

231 lines
7.0 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createNavigationHandler } from './navigation'
describe('createNavigationHandler', () => {
let mockRouter: any
let mockWindowOpen: any
beforeEach(() => {
// Mock router with push method
mockRouter = {
push: vi.fn(),
}
// Mock window.open
mockWindowOpen = vi.fn()
global.window.open = mockWindowOpen
})
describe('keyboard navigation', () => {
it('should call router.push when Enter key is pressed without modifiers', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
key: 'Enter',
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.KeyboardEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockRouter.push).toHaveBeenCalledWith('/test-url')
expect(mockWindowOpen).not.toHaveBeenCalled()
})
it('should call router.push when Space key is pressed without modifiers', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
key: ' ',
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.KeyboardEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockRouter.push).toHaveBeenCalledWith('/test-url')
expect(mockWindowOpen).not.toHaveBeenCalled()
})
it('should open new tab when Enter key is pressed with metaKey', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
key: 'Enter',
metaKey: true,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.KeyboardEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockWindowOpen).toHaveBeenCalledWith('/test-url', '_blank')
expect(mockRouter.push).not.toHaveBeenCalled()
})
it('should open new tab when Enter key is pressed with ctrlKey', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
key: 'Enter',
metaKey: false,
ctrlKey: true,
preventDefault: vi.fn(),
} as unknown as React.KeyboardEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockWindowOpen).toHaveBeenCalledWith('/test-url', '_blank')
expect(mockRouter.push).not.toHaveBeenCalled()
})
it('should open new tab when Space key is pressed with metaKey', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
key: ' ',
metaKey: true,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.KeyboardEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockWindowOpen).toHaveBeenCalledWith('/test-url', '_blank')
expect(mockRouter.push).not.toHaveBeenCalled()
})
it('should do nothing when other keys are pressed', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
key: 'a',
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.KeyboardEvent
handler(event)
expect(event.preventDefault).not.toHaveBeenCalled()
expect(mockRouter.push).not.toHaveBeenCalled()
expect(mockWindowOpen).not.toHaveBeenCalled()
})
})
describe('mouse navigation', () => {
it('should call router.push on regular left click', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
button: 0,
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.MouseEvent
handler(event)
expect(mockRouter.push).toHaveBeenCalledWith('/test-url')
expect(mockWindowOpen).not.toHaveBeenCalled()
})
it('should open new tab on middle mouse button click', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
button: 1, // Middle button
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.MouseEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockWindowOpen).toHaveBeenCalledWith('/test-url', '_blank')
expect(mockRouter.push).not.toHaveBeenCalled()
})
it('should open new tab on Cmd + left click', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
button: 0,
metaKey: true,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.MouseEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockWindowOpen).toHaveBeenCalledWith('/test-url', '_blank')
expect(mockRouter.push).not.toHaveBeenCalled()
})
it('should open new tab on Ctrl + left click', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
button: 0,
metaKey: false,
ctrlKey: true,
preventDefault: vi.fn(),
} as unknown as React.MouseEvent
handler(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(mockWindowOpen).toHaveBeenCalledWith('/test-url', '_blank')
expect(mockRouter.push).not.toHaveBeenCalled()
})
it('should handle right click without navigation', () => {
const handler = createNavigationHandler('/test-url', mockRouter)
const event = {
button: 2, // Right button
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.MouseEvent
handler(event)
// Right click opens the context menu, so it must not navigate.
expect(mockRouter.push).not.toHaveBeenCalled()
expect(mockWindowOpen).not.toHaveBeenCalled()
})
})
describe('URL handling', () => {
it('should handle URLs with BASE_PATH correctly', () => {
const handler = createNavigationHandler('/project/123/settings', mockRouter)
const event = {
button: 1, // Middle button to open in new tab
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.MouseEvent
handler(event)
// Should prepend BASE_PATH when opening new tab
expect(mockWindowOpen).toHaveBeenCalledWith('/project/123/settings', '_blank')
})
it('should pass URL directly to router.push without BASE_PATH', () => {
const handler = createNavigationHandler('/project/123/settings', mockRouter)
const event = {
button: 0,
metaKey: false,
ctrlKey: false,
preventDefault: vi.fn(),
} as unknown as React.MouseEvent
handler(event)
// router.push should receive URL without BASE_PATH
expect(mockRouter.push).toHaveBeenCalledWith('/project/123/settings')
})
})
})