Update tests and e2e files to support locale-based routing

- Replaced static paths with dynamic locale subpaths (`/[locale]/*`) in imports, URLs, and assertions across tests.
- Updated `next-intl` mocks for improved compatibility with `locale`-aware components.
- Standardized `page.goto` and navigation tests with `/en` as the base locale for consistency.
This commit is contained in:
Felipe Cardoso
2025-11-18 23:26:10 +01:00
parent d1b47006f4
commit da021d0640
42 changed files with 296 additions and 267 deletions

View File

@@ -8,7 +8,7 @@ import userEvent from '@testing-library/user-event';
import { Header } from '@/components/layout/Header';
import { useAuth } from '@/lib/auth/AuthContext';
import { useLogout } from '@/lib/api/hooks/useAuth';
import { usePathname } from 'next/navigation';
import { mockUsePathname } from 'next-intl/navigation';
import type { User } from '@/lib/stores/authStore';
// Mock dependencies
@@ -21,10 +21,6 @@ jest.mock('@/lib/api/hooks/useAuth', () => ({
useLogout: jest.fn(),
}));
jest.mock('next/navigation', () => ({
usePathname: jest.fn(),
}));
jest.mock('@/components/theme', () => ({
ThemeToggle: () => <div data-testid="theme-toggle">Theme Toggle</div>,
}));
@@ -51,7 +47,7 @@ describe('Header', () => {
beforeEach(() => {
jest.clearAllMocks();
(usePathname as jest.Mock).mockReturnValue('/');
mockUsePathname.mockReturnValue('/');
(useLogout as jest.Mock).mockReturnValue({
mutate: mockLogout,
@@ -156,7 +152,7 @@ describe('Header', () => {
});
it('highlights active navigation link', () => {
(usePathname as jest.Mock).mockReturnValue('/admin');
mockUsePathname.mockReturnValue('/admin');
(useAuth as unknown as jest.Mock).mockReturnValue({
user: createMockUser({ is_superuser: true }),
});