Files
gridpilot.gg/apps/website/app/500/ServerErrorPageClient.test.tsx
2026-01-17 15:46:55 +01:00

51 lines
1.5 KiB
TypeScript

import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { ServerErrorPageClient } from './ServerErrorPageClient';
import { useRouter } from 'next/navigation';
vi.mock('next/navigation', () => ({
useRouter: vi.fn(),
}));
describe('ServerErrorPageClient', () => {
it('renders the server error page with correct content', () => {
const push = vi.fn();
(useRouter as any).mockReturnValue({ push });
render(<ServerErrorPageClient />);
expect(screen.getByText('CRITICAL_SYSTEM_FAILURE')).toBeDefined();
expect(screen.getByText(/The application engine encountered an unrecoverable state/)).toBeDefined();
expect(screen.getByText(/Internal Server Error/)).toBeDefined();
});
it('handles home navigation', () => {
const push = vi.fn();
(useRouter as any).mockReturnValue({ push });
render(<ServerErrorPageClient />);
const homeButton = screen.getByText('Return to Pits');
fireEvent.click(homeButton);
expect(push).toHaveBeenCalledWith('/');
});
it('handles retry via page reload', () => {
const push = vi.fn();
(useRouter as any).mockReturnValue({ push });
const reloadFn = vi.fn();
vi.stubGlobal('location', { reload: reloadFn });
render(<ServerErrorPageClient />);
const retryButton = screen.getByText('Retry Session');
fireEvent.click(retryButton);
expect(reloadFn).toHaveBeenCalled();
vi.unstubAllGlobals();
});
});