Files
fast-next-template/frontend/tests/app/forbidden/page.test.tsx
Felipe Cardoso 9c72fe87f9 Add admin UX improvements, constants refactor, and comprehensive tests
- Introduced constants for admin hooks: `STATS_FETCH_LIMIT`, `DEFAULT_PAGE_LIMIT`, and `STATS_REFETCH_INTERVAL` to enhance readability and maintainability.
- Updated query guards to ensure data fetching is restricted to superusers.
- Enhanced accessibility across admin components by adding `aria-hidden` attributes and improving focus-visible styles.
- Simplified `useAdminStats`, `useAdminUsers`, and `useAdminOrganizations` with shared constants.
- Added 403 Forbidden page with proper structure, styling, and tests.
- Implemented new tests for admin hooks, DashboardStats, AdminLayout, and ForbiddenPage for better coverage.
2025-11-06 10:08:43 +01:00

67 lines
1.8 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/forbidden/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');
});
});