- Create code-first route tree in src/app/routing/routeTree.tsx - Replace ProtectedRoute with beforeLoad auth guards - Add useSearchParamsCompat for URLSearchParams access - Update App.tsx, layouts, and all page/widget imports - Add frontend tooling: biome, prettier, env config - Update all tests for TanStack Router compatibility - Remove react-router-dom dependency, @tanstack/router-plugin - Consolidate biome config at root level
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { renderHook, waitFor } from '@testing-library/react'
|
|
import type { ReactNode } from 'react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { getBrokerOperations } from '../api/brokerOperationApi'
|
|
import { useBrokerOperations } from '../model/useBrokerOperations'
|
|
|
|
vi.mock('../api/brokerOperationApi', () => ({
|
|
getBrokerOperations: vi.fn(),
|
|
}))
|
|
|
|
function createWrapper(queryClient?: QueryClient) {
|
|
const client = queryClient ?? new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
|
|
return function Wrapper({ children }: { children: ReactNode }) {
|
|
return <QueryClientProvider client={client}>{children}</QueryClientProvider>
|
|
}
|
|
}
|
|
|
|
describe('useBrokerOperations', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('returns operations page data from API', async () => {
|
|
vi.mocked(getBrokerOperations).mockResolvedValue({
|
|
data: {
|
|
accountId: 'acc-1',
|
|
items: [],
|
|
nextCursor: null,
|
|
hasNext: false,
|
|
asOf: '2026-06-19T00:00:00.000Z',
|
|
},
|
|
meta: { fromCache: false, cachedAt: null },
|
|
})
|
|
|
|
const { result } = renderHook(() => useBrokerOperations('acc-1', { limit: 5 }), {
|
|
wrapper: createWrapper(),
|
|
})
|
|
|
|
await waitFor(() => expect(result.current.isSuccess).toBe(true))
|
|
expect(result.current.data?.accountId).toBe('acc-1')
|
|
expect(getBrokerOperations).toHaveBeenCalledWith('acc-1', { limit: 5 })
|
|
})
|
|
|
|
it('reuses the broker operations cache key across the account overview and full history pages', async () => {
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
const cachedPage = {
|
|
accountId: 'acc-1',
|
|
items: [],
|
|
nextCursor: null,
|
|
hasNext: false,
|
|
asOf: '2026-06-19T00:00:00.000Z',
|
|
}
|
|
|
|
queryClient.setQueryData(['broker', 'operations', 'acc-1', { limit: 5 }], cachedPage)
|
|
|
|
const { result } = renderHook(() => useBrokerOperations('acc-1', { limit: 5 }), {
|
|
wrapper: createWrapper(queryClient),
|
|
})
|
|
|
|
await waitFor(() => expect(result.current.data).toBe(cachedPage))
|
|
expect(getBrokerOperations).not.toHaveBeenCalled()
|
|
})
|
|
})
|