mirror of
https://github.com/supabase/supabase.git
synced 2026-09-08 19:08:44 +08:00
## What kind of change does this PR introduce? Feature ## What is the current behavior? The dev toolbar is only discoverable via `window.devToolbar()` in the browser console, or by having your email on the `devToolbarDefaultOn` ConfigCat flag. Once enabled, Studio shows a floating trigger button. ## What is the new behavior? In local and staging Studio, the account/settings dropdown (avatar menu) includes a **Local tools** section above **Theme** with a **Dev toolbar** checkbox toggle. - **On**: shows the floating orb (persists via localStorage, same as `window.devToolbar()`) - **Off**: hides the orb and dismisses the toolbar Open the panel itself via the orb once it is visible. Production builds are unchanged (`isAvailable` is false and the menu item is hidden). | After | | --- | | <img width="226" height="204" alt="CleanShot 2026-08-20 at 12 46 38@2x" src="https://github.com/user-attachments/assets/c846b119-626d-48f5-9a02-aef4d006326c" /> | | <img width="558" height="1024" alt="CleanShot 2026-08-20 at 12 47 04@2x" src="https://github.com/user-attachments/assets/4b3dd22b-537b-4874-821d-c202033c4ad7" /> | ## Manual testing Run `pnpm dev:studio` and open http://localhost:8082. 1. **Find the entry point:** top-right avatar/settings menu → **Local tools** → **Dev toolbar** (above **Theme**). Should not appear in production builds. 2. **Turn it on:** check **Dev toolbar**. A green floating orb should appear (default bottom-right). 3. **Open the panel:** click the orb. The **Dev Toolbar** sheet should open with Events and Flags tabs. 4. **Event count:** navigate around Studio (e.g. open a project, switch pages). The orb badge should increment and stay readable in light and dark mode. 5. **Turn it off:** reopen the avatar menu and uncheck **Dev toolbar**. The orb and panel should disappear. 6. **Close vs hide:** with the toolbar on, open the sheet and use **Close** (X). The orb should remain; only the sheet closes. Optional: confirm `window.devToolbar()` in the browser console still enables the orb. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a Local tools option to enable the development toolbar when available. * Toolbar activation and dismissal preferences now persist between sessions. * Added clearer event-count badges with responsive sizing for larger counts. * **Improvements** * Simplified toolbar controls by removing the separate hide option. * Improved toolbar availability handling across local and production environments. * **Tests** * Expanded coverage for activation, persistence, visibility, and event-count badges. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Danny White <dnywh@users.noreply.github.com> Co-authored-by: Sean Oliver <882952+seanoliver@users.noreply.github.com>
264 lines
7.1 KiB
TypeScript
264 lines
7.1 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import type { MouseEventHandler, ReactElement, ReactNode } from 'react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { LocalDropdown } from './LocalDropdown'
|
|
|
|
const {
|
|
mockRouter,
|
|
mockSetTheme,
|
|
mockSetLastRoute,
|
|
mockToggleFeaturePreviewModal,
|
|
mockEnableToolbar,
|
|
mockDismissDevToolbar,
|
|
mockSetDevToolbarOpen,
|
|
mockUseDevToolbar,
|
|
} = vi.hoisted(() => ({
|
|
mockRouter: {
|
|
pathname: '/project/[ref]/editor',
|
|
asPath: '/project/default/editor',
|
|
},
|
|
mockSetTheme: vi.fn(),
|
|
mockSetLastRoute: vi.fn(),
|
|
mockToggleFeaturePreviewModal: vi.fn(),
|
|
mockEnableToolbar: vi.fn(),
|
|
mockDismissDevToolbar: vi.fn(),
|
|
mockSetDevToolbarOpen: vi.fn(),
|
|
mockUseDevToolbar: vi.fn(() => ({
|
|
isAvailable: false,
|
|
isEnabled: false,
|
|
isOpen: false,
|
|
setIsOpen: mockSetDevToolbarOpen,
|
|
enableToolbar: mockEnableToolbar,
|
|
dismissToolbar: mockDismissDevToolbar,
|
|
events: [],
|
|
setEvents: vi.fn(),
|
|
})),
|
|
}))
|
|
|
|
vi.mock('next/router', () => ({
|
|
useRouter: () => mockRouter,
|
|
}))
|
|
|
|
vi.mock('next/link', () => ({
|
|
default: ({
|
|
href,
|
|
children,
|
|
onClick,
|
|
}: {
|
|
href: string
|
|
children: ReactNode
|
|
onClick?: MouseEventHandler<HTMLAnchorElement>
|
|
}) => (
|
|
<a href={href} onClick={onClick}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}))
|
|
|
|
vi.mock('next-themes', () => ({
|
|
useTheme: () => ({
|
|
theme: 'dark',
|
|
setTheme: mockSetTheme,
|
|
}),
|
|
}))
|
|
|
|
vi.mock('@/state/app-state', () => ({
|
|
useAppStateSnapshot: () => ({
|
|
setLastRouteBeforeVisitingAccountPage: mockSetLastRoute,
|
|
}),
|
|
}))
|
|
|
|
vi.mock('@/components/ui/ProfileImage', () => ({
|
|
ProfileImage: () => <div>Avatar</div>,
|
|
}))
|
|
|
|
vi.mock('./App/FeaturePreview/FeaturePreviewContext', () => ({
|
|
useFeaturePreviewModal: () => ({
|
|
toggleFeaturePreviewModal: mockToggleFeaturePreviewModal,
|
|
}),
|
|
}))
|
|
|
|
vi.mock('@/lib/telemetry/track', () => ({ useTrack: () => vi.fn() }))
|
|
|
|
vi.mock('dev-tools', () => ({
|
|
useDevToolbar: () => mockUseDevToolbar(),
|
|
}))
|
|
|
|
vi.mock('ui', async () => {
|
|
const React = await import('react')
|
|
|
|
return {
|
|
Button: ({
|
|
children,
|
|
...props
|
|
}: React.ButtonHTMLAttributes<HTMLButtonElement> & { children?: ReactNode }) => (
|
|
<button tabIndex={0} {...props}>
|
|
{children}
|
|
</button>
|
|
),
|
|
cn: (...classes: Array<string | false | null | undefined>) => classes.filter(Boolean).join(' '),
|
|
DropdownMenu: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuTrigger: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuGroup: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuItem: ({
|
|
children,
|
|
asChild,
|
|
onClick,
|
|
onSelect,
|
|
}: {
|
|
children: ReactNode
|
|
asChild?: boolean
|
|
onClick?: () => void
|
|
onSelect?: () => void
|
|
}) =>
|
|
asChild ? (
|
|
<div>{children}</div>
|
|
) : (
|
|
<button
|
|
tabIndex={0}
|
|
onClick={() => {
|
|
onClick?.()
|
|
onSelect?.()
|
|
}}
|
|
>
|
|
{children}
|
|
</button>
|
|
),
|
|
DropdownMenuLabel: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuCheckboxItem: ({
|
|
children,
|
|
checked,
|
|
onCheckedChange,
|
|
}: {
|
|
children: ReactNode
|
|
checked?: boolean
|
|
onCheckedChange?: (checked: boolean) => void
|
|
}) => (
|
|
<button tabIndex={0} aria-checked={checked} onClick={() => onCheckedChange?.(!checked)}>
|
|
{children}
|
|
</button>
|
|
),
|
|
DropdownMenuSeparator: () => <hr />,
|
|
DropdownMenuRadioGroup: ({
|
|
children,
|
|
onValueChange,
|
|
}: {
|
|
children: ReactNode
|
|
onValueChange: (value: string) => void
|
|
}) => (
|
|
<div>
|
|
{React.Children.map(children, (child: ReactNode) =>
|
|
React.isValidElement<{ value: string; onClick?: () => void }>(child)
|
|
? React.cloneElement(child, {
|
|
onClick: () => onValueChange(child.props.value),
|
|
})
|
|
: (child as ReactElement)
|
|
)}
|
|
</div>
|
|
),
|
|
DropdownMenuRadioItem: ({
|
|
children,
|
|
onClick,
|
|
}: {
|
|
children: ReactNode
|
|
onClick?: () => void
|
|
}) => (
|
|
<button tabIndex={0} onClick={onClick}>
|
|
{children}
|
|
</button>
|
|
),
|
|
Tooltip: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
TooltipContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
TooltipTrigger: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
singleThemes: [
|
|
{ value: 'dark', name: 'Dark' },
|
|
{ value: 'light', name: 'Light' },
|
|
],
|
|
}
|
|
})
|
|
|
|
describe('LocalDropdown', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockUseDevToolbar.mockReturnValue({
|
|
isAvailable: false,
|
|
isEnabled: false,
|
|
isOpen: false,
|
|
setIsOpen: mockSetDevToolbarOpen,
|
|
enableToolbar: mockEnableToolbar,
|
|
dismissToolbar: mockDismissDevToolbar,
|
|
events: [],
|
|
setEvents: vi.fn(),
|
|
})
|
|
})
|
|
|
|
it('shows Preferences, removes Command menu, and keeps theme controls wired', async () => {
|
|
const user = userEvent.setup()
|
|
|
|
render(<LocalDropdown />)
|
|
|
|
expect(screen.getByText('Preferences')).toBeInTheDocument()
|
|
expect(screen.queryByText('Command menu')).not.toBeInTheDocument()
|
|
expect(screen.getByText('Theme')).toBeInTheDocument()
|
|
expect(screen.queryByText('Dev toolbar')).not.toBeInTheDocument()
|
|
|
|
await user.click(screen.getByText('Preferences'))
|
|
expect(mockSetLastRoute).toHaveBeenCalledWith('/project/default/editor')
|
|
|
|
await user.click(screen.getByText('Feature previews'))
|
|
expect(mockToggleFeaturePreviewModal).toHaveBeenCalledWith(true)
|
|
|
|
await user.click(screen.getByText('Light'))
|
|
expect(mockSetTheme).toHaveBeenCalledWith('light')
|
|
})
|
|
|
|
it('toggles Dev toolbar visibility from the menu', async () => {
|
|
mockUseDevToolbar.mockReturnValue({
|
|
isAvailable: true,
|
|
isEnabled: false,
|
|
isOpen: false,
|
|
setIsOpen: mockSetDevToolbarOpen,
|
|
enableToolbar: mockEnableToolbar,
|
|
dismissToolbar: mockDismissDevToolbar,
|
|
events: [],
|
|
setEvents: vi.fn(),
|
|
})
|
|
|
|
const user = userEvent.setup()
|
|
|
|
render(<LocalDropdown />)
|
|
|
|
expect(screen.getByText('Local tools')).toBeInTheDocument()
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dev toolbar' }))
|
|
|
|
expect(mockEnableToolbar).toHaveBeenCalled()
|
|
expect(mockDismissDevToolbar).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('hides Dev toolbar from the menu when toggled off', async () => {
|
|
mockUseDevToolbar.mockReturnValue({
|
|
isAvailable: true,
|
|
isEnabled: true,
|
|
isOpen: false,
|
|
setIsOpen: mockSetDevToolbarOpen,
|
|
enableToolbar: mockEnableToolbar,
|
|
dismissToolbar: mockDismissDevToolbar,
|
|
events: [],
|
|
setEvents: vi.fn(),
|
|
})
|
|
|
|
const user = userEvent.setup()
|
|
|
|
render(<LocalDropdown />)
|
|
|
|
await user.click(screen.getByRole('button', { name: 'Dev toolbar' }))
|
|
|
|
expect(mockDismissDevToolbar).toHaveBeenCalled()
|
|
expect(mockEnableToolbar).not.toHaveBeenCalled()
|
|
})
|
|
})
|