- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { NotFoundPage, ServerErrorPage } from '../ErrorPages';
|
|
|
|
const mockPush = vi.fn();
|
|
vi.mock('next/navigation', () => ({
|
|
useRouter: () => ({
|
|
push: mockPush,
|
|
replace: vi.fn(),
|
|
prefetch: vi.fn(),
|
|
back: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
describe('ErrorPages Components', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('NotFoundPage (404)', () => {
|
|
it('renders 404 code, error title, and description message in Persian', () => {
|
|
render(<NotFoundPage />);
|
|
|
|
expect(screen.getByText('۴۰۴')).toBeInTheDocument();
|
|
expect(screen.getByText('صفحه پیدا نشد!')).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText(/متأسفانه صفحهای که به دنبال آن هستید وجود ندارد یا جابجا شده است/)
|
|
).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: /بازگشت به خانه/ })).toBeInTheDocument();
|
|
});
|
|
|
|
it('navigates to home ("/") when clicking back to home button', () => {
|
|
render(<NotFoundPage />);
|
|
|
|
const homeButton = screen.getByRole('button', { name: /بازگشت به خانه/ });
|
|
fireEvent.click(homeButton);
|
|
|
|
expect(mockPush).toHaveBeenCalledTimes(1);
|
|
expect(mockPush).toHaveBeenCalledWith('/');
|
|
});
|
|
});
|
|
|
|
describe('ServerErrorPage (500)', () => {
|
|
it('renders 500 error heading and explanation text', () => {
|
|
const mockOnRetry = vi.fn();
|
|
render(<ServerErrorPage onRetry={mockOnRetry} />);
|
|
|
|
expect(screen.getByText('خطای داخلی سیستم')).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText(/ارتباط با دیتابیس کنینا با مشکل مواجه شده است/)
|
|
).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: /تلاش مجدد/ })).toBeInTheDocument();
|
|
});
|
|
|
|
it('calls onRetry callback when clicking retry button', () => {
|
|
const mockOnRetry = vi.fn();
|
|
render(<ServerErrorPage onRetry={mockOnRetry} />);
|
|
|
|
const retryButton = screen.getByRole('button', { name: /تلاش مجدد/ });
|
|
fireEvent.click(retryButton);
|
|
|
|
expect(mockOnRetry).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
});
|