Files
supabase/apps/studio/tests/lib/custom-render.tsx
Ali Waseem e8df67d5d5 chore: migrate shortcuts to new hooks API (#44955)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Cleanup shortcuts with new hooks

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

* **Refactor**
* Centralized keyboard shortcut system for consistent shortcut behavior
across the app and moved preference toggles to a unified registry.

* **New Features**
* Added explicit shortcuts for Command Menu, AI Assistant, Inline
Editor, and result copy/download actions.
* Hotkey preferences UI now renders dynamically from the centralized
shortcut list.

* **Tests**
* Test helpers updated to include the command menu provider for accurate
shortcut behavior in tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-17 10:02:56 -06:00

82 lines
2.1 KiB
TypeScript

import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, renderHook, type RenderOptions } from '@testing-library/react'
import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
import { TooltipProvider } from 'ui'
import { CommandProvider } from 'ui-patterns/CommandMenu'
// End of third-party imports
import { ProfileContext, type ProfileContextType } from '@/lib/profile'
type AdapterProps = Partial<Parameters<typeof NuqsTestingAdapter>[0]>
const CustomWrapper = ({
children,
queryClient,
nuqs,
profileContext,
}: {
children: React.ReactNode
queryClient?: QueryClient
nuqs?: AdapterProps
profileContext?: ProfileContextType
}) => {
const _queryClient =
queryClient ??
new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
})
const content = (
<QueryClientProvider client={_queryClient}>
<NuqsTestingAdapter {...nuqs}>
<TooltipProvider>
<CommandProvider openKey="">{children}</CommandProvider>
</TooltipProvider>
</NuqsTestingAdapter>
</QueryClientProvider>
)
return profileContext ? (
<ProfileContext.Provider value={profileContext}>{content}</ProfileContext.Provider>
) : (
content
)
}
type CustomRenderOpts = RenderOptions & {
queryClient?: QueryClient
nuqs?: AdapterProps
profileContext?: ProfileContextType
}
export const customRender = (component: React.ReactElement, renderOptions?: CustomRenderOpts) => {
return render(component, {
wrapper: ({ children }) =>
CustomWrapper({
queryClient: renderOptions?.queryClient,
nuqs: renderOptions?.nuqs,
profileContext: renderOptions?.profileContext,
children,
}),
...renderOptions,
})
}
export const customRenderHook = (hook: () => any, renderOptions?: CustomRenderOpts) => {
return renderHook(hook, {
wrapper: ({ children }) =>
CustomWrapper({
children,
queryClient: renderOptions?.queryClient,
nuqs: renderOptions?.nuqs,
profileContext: renderOptions?.profileContext,
}),
...renderOptions,
})
}