forked from cardosofelipe/fast-next-template
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:
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import LoginPage from '@/app/(auth)/login/page';
|
||||
import LoginPage from '@/app/[locale]/(auth)/login/page';
|
||||
|
||||
// Mock dynamic import
|
||||
jest.mock('next/dynamic', () => ({
|
||||
|
||||
@@ -4,20 +4,20 @@
|
||||
*/
|
||||
|
||||
import { render, screen, act } from '@testing-library/react';
|
||||
import { useSearchParams, useRouter } from 'next/navigation';
|
||||
import PasswordResetConfirmContent from '@/app/(auth)/password-reset/confirm/PasswordResetConfirmContent';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useRouter } from '@/lib/i18n/routing';
|
||||
import PasswordResetConfirmContent from '@/app/[locale]/(auth)/password-reset/confirm/PasswordResetConfirmContent';
|
||||
|
||||
// Mock Next.js navigation
|
||||
jest.mock('next/navigation', () => ({
|
||||
useSearchParams: jest.fn(),
|
||||
useRouter: jest.fn(),
|
||||
default: jest.fn(),
|
||||
}));
|
||||
|
||||
// Mock Next.js Link
|
||||
jest.mock('next/link', () => ({
|
||||
__esModule: true,
|
||||
default: ({ children, href }: { children: React.ReactNode; href: string }) => (
|
||||
// Mock i18n routing
|
||||
jest.mock('@/lib/i18n/routing', () => ({
|
||||
useRouter: jest.fn(),
|
||||
Link: ({ children, href }: { children: React.ReactNode; href: string }) => (
|
||||
<a href={href}>{children}</a>
|
||||
),
|
||||
}));
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import PasswordResetConfirmPage from '@/app/(auth)/password-reset/confirm/page';
|
||||
import PasswordResetConfirmPage from '@/app/[locale]/(auth)/password-reset/confirm/page';
|
||||
|
||||
// Mock the content component
|
||||
jest.mock('@/app/(auth)/password-reset/confirm/PasswordResetConfirmContent', () => ({
|
||||
jest.mock('@/app/[locale]/(auth)/password-reset/confirm/PasswordResetConfirmContent', () => ({
|
||||
__esModule: true,
|
||||
default: () => <div data-testid="password-reset-confirm-content">Content</div>,
|
||||
}));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import PasswordResetPage from '@/app/(auth)/password-reset/page';
|
||||
import PasswordResetPage from '@/app/[locale]/(auth)/password-reset/page';
|
||||
|
||||
// Mock dynamic import
|
||||
jest.mock('next/dynamic', () => ({
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import RegisterPage from '@/app/(auth)/register/page';
|
||||
import RegisterPage from '@/app/[locale]/(auth)/register/page';
|
||||
|
||||
// Mock dynamic import
|
||||
jest.mock('next/dynamic', () => ({
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
import SettingsPage from '@/app/(authenticated)/settings/page';
|
||||
import SettingsPage from '@/app/[locale]/(authenticated)/settings/page';
|
||||
|
||||
// Mock Next.js navigation - redirect throws to interrupt execution
|
||||
jest.mock('next/navigation', () => ({
|
||||
@@ -18,8 +18,9 @@ describe('SettingsPage', () => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('redirects to /settings/profile', () => {
|
||||
expect(() => SettingsPage()).toThrow('NEXT_REDIRECT');
|
||||
expect(redirect).toHaveBeenCalledWith('/settings/profile');
|
||||
it('redirects to /settings/profile with locale prefix', async () => {
|
||||
const params = Promise.resolve({ locale: 'en' });
|
||||
await expect(SettingsPage({ params })).rejects.toThrow('NEXT_REDIRECT');
|
||||
expect(redirect).toHaveBeenCalledWith('/en/settings/profile');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import PasswordSettingsPage from '@/app/(authenticated)/settings/password/page';
|
||||
import PasswordSettingsPage from '@/app/[locale]/(authenticated)/settings/password/page';
|
||||
|
||||
describe('PasswordSettingsPage', () => {
|
||||
const queryClient = new QueryClient({
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import PreferencesPage from '@/app/(authenticated)/settings/preferences/page';
|
||||
import PreferencesPage from '@/app/[locale]/(authenticated)/settings/preferences/page';
|
||||
|
||||
describe('PreferencesPage', () => {
|
||||
it('renders page title', () => {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import ProfileSettingsPage from '@/app/(authenticated)/settings/profile/page';
|
||||
import ProfileSettingsPage from '@/app/[locale]/(authenticated)/settings/profile/page';
|
||||
import { AuthProvider } from '@/lib/auth/AuthContext';
|
||||
|
||||
// Mock API hooks
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import SessionsPage from '@/app/(authenticated)/settings/sessions/page';
|
||||
import SessionsPage from '@/app/[locale]/(authenticated)/settings/sessions/page';
|
||||
|
||||
// Mock the API client
|
||||
jest.mock('@/lib/api/client', () => ({
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import AdminLayout from '@/app/admin/layout';
|
||||
import AdminLayout from '@/app/[locale]/admin/layout';
|
||||
import { useAuth } from '@/lib/auth/AuthContext';
|
||||
|
||||
// Mock dependencies
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import OrganizationMembersPage from '@/app/admin/organizations/[id]/members/page';
|
||||
import OrganizationMembersPage from '@/app/[locale]/admin/organizations/[id]/members/page';
|
||||
|
||||
// Mock Next.js Link
|
||||
jest.mock('next/link', () => ({
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import AdminOrganizationsPage from '@/app/admin/organizations/page';
|
||||
import AdminOrganizationsPage from '@/app/[locale]/admin/organizations/page';
|
||||
|
||||
// Mock the entire OrganizationManagementContent component
|
||||
jest.mock('@/components/admin/organizations/OrganizationManagementContent', () => ({
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import AdminPage from '@/app/admin/page';
|
||||
import AdminPage from '@/app/[locale]/admin/page';
|
||||
import { useAdminStats } from '@/lib/api/hooks/useAdmin';
|
||||
|
||||
// Mock the useAdminStats hook
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import AdminSettingsPage from '@/app/admin/settings/page';
|
||||
import AdminSettingsPage from '@/app/[locale]/admin/settings/page';
|
||||
|
||||
describe('AdminSettingsPage', () => {
|
||||
it('renders page title', () => {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import AdminUsersPage from '@/app/admin/users/page';
|
||||
import AdminUsersPage from '@/app/[locale]/admin/users/page';
|
||||
import { useAuth } from '@/lib/auth/AuthContext';
|
||||
import { useAdminUsers } from '@/lib/api/hooks/useAdmin';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen, within } from '@testing-library/react';
|
||||
import DemoTourPage from '@/app/demos/page';
|
||||
import DemoTourPage from '@/app/[locale]/demos/page';
|
||||
|
||||
// Mock Next.js Link
|
||||
jest.mock('next/link', () => ({
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import ForbiddenPage, { metadata } from '@/app/forbidden/page';
|
||||
import ForbiddenPage, { metadata } from '@/app/[locale]/forbidden/page';
|
||||
|
||||
describe('ForbiddenPage', () => {
|
||||
it('has correct metadata', () => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { render, screen, within, fireEvent } from '@testing-library/react';
|
||||
import Home from '@/app/page';
|
||||
import Home from '@/app/[locale]/page';
|
||||
|
||||
// Mock Next.js components
|
||||
jest.mock('next/image', () => ({
|
||||
|
||||
Reference in New Issue
Block a user