forked from cardosofelipe/fast-next-template
- Updated test components (`PasswordResetConfirmForm`, `PasswordChangeForm`) to use i18n keys directly, ensuring accurate validation messages. - Refined translations in `it.json` to standardize format and content. - Replaced text-based labels with localized strings in `PasswordResetRequestForm` and `RegisterForm`. - Introduced `generateLocalizedMetadata` utility and updated layout metadata generation for locale-aware SEO. - Enhanced e2e tests with locale-prefixed routes and updated assertions for consistency. - Added comprehensive i18n documentation (`I18N.md`) for usage, architecture, and testing.
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
/**
|
|
* Tests for 403 Forbidden Page
|
|
* Verifies rendering of access forbidden message and navigation
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import ForbiddenPage from '@/app/[locale]/forbidden/page';
|
|
|
|
// Mock next-intl/server to avoid ESM import issues in Jest
|
|
jest.mock('next-intl/server', () => ({
|
|
getTranslations: jest.fn(async () => ({
|
|
unauthorized: 'Unauthorized',
|
|
unauthorizedDescription: "You don't have permission to access this page.",
|
|
})),
|
|
}));
|
|
|
|
describe('ForbiddenPage', () => {
|
|
it('renders page heading', () => {
|
|
render(<ForbiddenPage />);
|
|
|
|
expect(screen.getByRole('heading', { name: /403 - Access Forbidden/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders permission denied message', () => {
|
|
render(<ForbiddenPage />);
|
|
|
|
expect(
|
|
screen.getByText(/You don't have permission to access this resource/)
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders admin privileges message', () => {
|
|
render(<ForbiddenPage />);
|
|
|
|
expect(screen.getByText(/This page requires administrator privileges/)).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders link to dashboard', () => {
|
|
render(<ForbiddenPage />);
|
|
|
|
const dashboardLink = screen.getByRole('link', {
|
|
name: /Go to Dashboard/i,
|
|
});
|
|
expect(dashboardLink).toBeInTheDocument();
|
|
expect(dashboardLink).toHaveAttribute('href', '/dashboard');
|
|
});
|
|
|
|
it('renders link to home', () => {
|
|
render(<ForbiddenPage />);
|
|
|
|
const homeLink = screen.getByRole('link', { name: /Go to Home/i });
|
|
expect(homeLink).toBeInTheDocument();
|
|
expect(homeLink).toHaveAttribute('href', '/');
|
|
});
|
|
|
|
it('renders shield alert icon with aria-hidden', () => {
|
|
const { container } = render(<ForbiddenPage />);
|
|
|
|
const icon = container.querySelector('[aria-hidden="true"]');
|
|
expect(icon).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders with proper container structure', () => {
|
|
const { container } = render(<ForbiddenPage />);
|
|
|
|
const containerDiv = container.querySelector('.container');
|
|
expect(containerDiv).toBeInTheDocument();
|
|
expect(containerDiv).toHaveClass('mx-auto', 'px-6', 'py-16');
|
|
});
|
|
});
|