/**
* Provider stack shared by the admin-ui tests.
*
* Mirrors app/_layout.tsx minus the native wrappers: trpc + React Query +
* Refresh. StaffAuthProvider is mocked globally in tests/setup.ts, so screens
* that read the session mount without it; real-provider tests render it
* explicitly.
*/
import React from 'react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render } from '@testing-library/react-native'
import { RefreshProvider } from 'common-ui'
import { trpc, trpcClient } from '@/src/trpc-client'
export function createQueryClient() {
return new QueryClient({
defaultOptions: { queries: { retry: false, gcTime: 0 } },
})
}
export interface ProviderOptions {
/** Reuse a specific query client (e.g. to assert refetches). */
queryClient?: QueryClient
}
export function Providers({
children,
queryClient,
}: { children?: React.ReactNode } & ProviderOptions) {
const client = React.useMemo(
() => queryClient ?? createQueryClient(),
[queryClient]
)
return (
{children}
)
}
/** Render a screen/component inside the standard provider stack. */
export function renderWithProviders(
ui: React.ReactElement,
options?: ProviderOptions
) {
return render({ui})
}