Files
slp-modular-cms/frontend/src/test/RouteGuard.test.tsx
T
2026-06-20 17:04:17 +02:00

29 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { screen } from '@testing-library/react';
import { renderApp, mockAuthenticated, mockGuest } from '@/test/utils';
describe('Route guards (BR-U1-05, BR-U1-06)', () => {
it('redirects an unauthenticated user from a protected route to /login', async () => {
mockGuest();
renderApp('/dashboard');
expect(await screen.findByTestId('login-form-submit-button')).toBeInTheDocument();
expect(screen.queryByTestId('dashboard-title')).not.toBeInTheDocument();
});
it('allows an authenticated user to reach a protected route', async () => {
mockAuthenticated();
renderApp('/dashboard');
expect(await screen.findByTestId('dashboard-title')).toBeInTheDocument();
});
it('redirects an authenticated user away from /login to the dashboard', async () => {
mockAuthenticated();
renderApp('/login');
expect(await screen.findByTestId('dashboard-title')).toBeInTheDocument();
expect(screen.queryByTestId('login-form-submit-button')).not.toBeInTheDocument();
});
});