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 { 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', () => ({
|
||||
|
||||
Reference in New Issue
Block a user