feat(unit-4): Dashboard — availability widget with TanStack Query
- Add @tanstack/react-query 5.101.0; wrap app with QueryClientProvider - Add AvailabilityStatus type and AvailabilityResponse to api/types.ts - Implement useAvailabilityStatus (staleTime 30s, stale-on-error preserved) - Add AvailabilityStatusBadge with green/amber/red states and stale indicator - Replace DashboardPage placeholder card with live availability widget - Add MSW availability handler; update test/utils with QueryClientProvider - 55/55 tests pass (FR-05) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { useState, type ReactElement } from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { createMemoryHistory, createRouter, RouterProvider } from '@tanstack/react-router';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { I18nextProvider } from 'react-i18next';
|
||||
import { AuthProvider } from '@/contexts/AuthProvider';
|
||||
import { useAuth } from '@/contexts/auth-context';
|
||||
@@ -11,6 +12,12 @@ import { server } from '@/mocks/server';
|
||||
import { API_BASE, makeAuthResponse } from '@/mocks/auth/fixtures';
|
||||
import i18n from '@/i18n/config';
|
||||
|
||||
function createTestQueryClient() {
|
||||
return new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
});
|
||||
}
|
||||
|
||||
/** Force the silent-refresh-on-mount to fail, leaving the app in guest state. */
|
||||
export function mockGuest(): void {
|
||||
server.use(
|
||||
@@ -27,12 +34,14 @@ export function mockAuthenticated(): void {
|
||||
);
|
||||
}
|
||||
|
||||
/** Render an arbitrary element wrapped in the i18n + auth providers. */
|
||||
/** Render an arbitrary element wrapped in i18n + auth + query providers. */
|
||||
export function renderWithProviders(ui: ReactElement) {
|
||||
return render(
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<AuthProvider>{ui}</AuthProvider>
|
||||
</I18nextProvider>,
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<AuthProvider>{ui}</AuthProvider>
|
||||
</I18nextProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,10 +64,12 @@ function AppHarness({ initialPath }: { initialPath: string }) {
|
||||
/** Render the full application router at a given path, inside all providers. */
|
||||
export function renderApp(initialPath = '/') {
|
||||
return render(
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<AuthProvider>
|
||||
<AppHarness initialPath={initialPath} />
|
||||
</AuthProvider>
|
||||
</I18nextProvider>,
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<AuthProvider>
|
||||
<AppHarness initialPath={initialPath} />
|
||||
</AuthProvider>
|
||||
</I18nextProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user