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

@@ -7,7 +7,7 @@ import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { AdminSidebar } from '@/components/admin/AdminSidebar';
import { useAuth } from '@/lib/auth/AuthContext';
import { usePathname } from 'next/navigation';
import { mockUsePathname } from 'next-intl/navigation';
import type { User } from '@/lib/stores/authStore';
// Mock dependencies
@@ -16,10 +16,6 @@ jest.mock('@/lib/auth/AuthContext', () => ({
AuthProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
jest.mock('next/navigation', () => ({
usePathname: jest.fn(),
}));
// Helper to create mock user
function createMockUser(overrides: Partial<User> = {}): User {
return {
@@ -39,7 +35,7 @@ function createMockUser(overrides: Partial<User> = {}): User {
describe('AdminSidebar', () => {
beforeEach(() => {
jest.clearAllMocks();
(usePathname as jest.Mock).mockReturnValue('/admin');
mockUsePathname.mockReturnValue('/admin');
(useAuth as unknown as jest.Mock).mockReturnValue({
user: createMockUser(),
});
@@ -97,7 +93,7 @@ describe('AdminSidebar', () => {
describe('Active State Highlighting', () => {
it('highlights dashboard link when on /admin', () => {
(usePathname as jest.Mock).mockReturnValue('/admin');
mockUsePathname.mockReturnValue('/admin');
render(<AdminSidebar />);
@@ -106,7 +102,7 @@ describe('AdminSidebar', () => {
});
it('highlights users link when on /admin/users', () => {
(usePathname as jest.Mock).mockReturnValue('/admin/users');
mockUsePathname.mockReturnValue('/admin/users');
render(<AdminSidebar />);
@@ -115,7 +111,7 @@ describe('AdminSidebar', () => {
});
it('highlights users link when on /admin/users/123', () => {
(usePathname as jest.Mock).mockReturnValue('/admin/users/123');
mockUsePathname.mockReturnValue('/admin/users/123');
render(<AdminSidebar />);
@@ -124,7 +120,7 @@ describe('AdminSidebar', () => {
});
it('highlights organizations link when on /admin/organizations', () => {
(usePathname as jest.Mock).mockReturnValue('/admin/organizations');
mockUsePathname.mockReturnValue('/admin/organizations');
render(<AdminSidebar />);
@@ -133,7 +129,7 @@ describe('AdminSidebar', () => {
});
it('highlights settings link when on /admin/settings', () => {
(usePathname as jest.Mock).mockReturnValue('/admin/settings');
mockUsePathname.mockReturnValue('/admin/settings');
render(<AdminSidebar />);
@@ -142,7 +138,7 @@ describe('AdminSidebar', () => {
});
it('does not highlight dashboard when on other admin routes', () => {
(usePathname as jest.Mock).mockReturnValue('/admin/users');
mockUsePathname.mockReturnValue('/admin/users');
render(<AdminSidebar />);