Add comprehensive tests for authentication, settings, and password reset pages

- Introduced smoke tests for Login, Register, Password Reset, Password Reset Confirm, and Settings pages.
- Enhanced test coverage for all dynamic imports using mocks and added Jest exclusions for non-testable Next.js files.
- Added component-specific test files for better structure and maintainability.
- Improved test isolation by mocking navigation, providers, and rendering contexts.
This commit is contained in:
2025-11-02 17:33:57 +01:00
parent 77594e478d
commit fded54e61a
23 changed files with 599 additions and 2 deletions

View File

@@ -0,0 +1,79 @@
/**
* 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>
),
}));
jest.mock('@/components/auth', () => ({
AuthInitializer: () => <div data-testid="auth-initializer" />,
}));
// 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 AuthInitializer', () => {
render(
<Providers>
<div>Test Content</div>
</Providers>
);
expect(screen.getByTestId('auth-initializer')).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();
});
});