Files
fast-next-template/frontend/tests/app/providers.test.tsx
Felipe Cardoso 7c98ceb5b9 Refactor E2E tests to use ID selectors and enhance mock auth injection
- Updated E2E selectors for input fields to use stable IDs instead of `name` attributes, improving reliability and alignment with form field guarantees.
- Refined mock auth state injection in Playwright to establish test store state prior to page load.
- Optimized test clarity and consistency by consolidating selector logic and introducing stabilization steps where necessary.
- Removed redundant `AuthInitializer` mocks and refactored related tests to align with the updated `AuthContext` pattern.
- Enhanced readability and maintainability across affected test suites.
2025-11-04 00:32:07 +01:00

66 lines
1.6 KiB
TypeScript

/**
* Tests for Providers Component
* Verifies React Query and Theme providers are configured correctly
*/
import { render, screen } from '@testing-library/react';
import { Providers } from '@/app/providers';
// Mock components
jest.mock('@/components/theme', () => ({
ThemeProvider: ({ children }: { children: React.ReactNode }) => (
<div data-testid="theme-provider">{children}</div>
),
}));
// Mock TanStack Query
jest.mock('@tanstack/react-query', () => ({
QueryClient: jest.fn().mockImplementation(() => ({})),
QueryClientProvider: ({ children }: { children: React.ReactNode }) => (
<div data-testid="query-provider">{children}</div>
),
}));
describe('Providers', () => {
it('renders without crashing', () => {
render(
<Providers>
<div>Test Content</div>
</Providers>
);
expect(screen.getByText('Test Content')).toBeInTheDocument();
});
it('wraps children with ThemeProvider', () => {
render(
<Providers>
<div>Test Content</div>
</Providers>
);
expect(screen.getByTestId('theme-provider')).toBeInTheDocument();
});
it('wraps children with QueryClientProvider', () => {
render(
<Providers>
<div>Test Content</div>
</Providers>
);
expect(screen.getByTestId('query-provider')).toBeInTheDocument();
});
it('renders children', () => {
render(
<Providers>
<div data-testid="test-child">Child Component</div>
</Providers>
);
expect(screen.getByTestId('test-child')).toBeInTheDocument();
expect(screen.getByText('Child Component')).toBeInTheDocument();
});
});