forked from cardosofelipe/fast-next-template
- Updated test components (`PasswordResetConfirmForm`, `PasswordChangeForm`) to use i18n keys directly, ensuring accurate validation messages. - Refined translations in `it.json` to standardize format and content. - Replaced text-based labels with localized strings in `PasswordResetRequestForm` and `RegisterForm`. - Introduced `generateLocalizedMetadata` utility and updated layout metadata generation for locale-aware SEO. - Enhanced e2e tests with locale-prefixed routes and updated assertions for consistency. - Added comprehensive i18n documentation (`I18N.md`) for usage, architecture, and testing.
107 lines
2.9 KiB
TypeScript
107 lines
2.9 KiB
TypeScript
/**
|
|
* Tests for Profile Settings Page
|
|
* Smoke tests for page rendering
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import ProfileSettingsPage from '@/app/[locale]/(authenticated)/settings/profile/page';
|
|
import { AuthProvider } from '@/lib/auth/AuthContext';
|
|
|
|
// Mock API hooks
|
|
jest.mock('@/lib/api/hooks/useAuth', () => ({
|
|
useCurrentUser: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('@/lib/api/hooks/useUser', () => ({
|
|
useUpdateProfile: jest.fn(),
|
|
}));
|
|
|
|
// Import mocked hooks
|
|
import { useCurrentUser } from '@/lib/api/hooks/useAuth';
|
|
import { useUpdateProfile } from '@/lib/api/hooks/useUser';
|
|
|
|
// Mock store hook for AuthProvider
|
|
const mockStoreHook = ((selector?: (state: any) => any) => {
|
|
const state = {
|
|
isAuthenticated: true,
|
|
user: {
|
|
id: '1',
|
|
email: 'test@example.com',
|
|
first_name: 'Test',
|
|
last_name: 'User',
|
|
is_active: true,
|
|
is_superuser: false,
|
|
created_at: '2024-01-01T00:00:00Z',
|
|
},
|
|
accessToken: 'token',
|
|
refreshToken: 'refresh',
|
|
isLoading: false,
|
|
tokenExpiresAt: null,
|
|
setAuth: jest.fn(),
|
|
setTokens: jest.fn(),
|
|
setUser: jest.fn(),
|
|
clearAuth: jest.fn(),
|
|
loadAuthFromStorage: jest.fn(),
|
|
isTokenExpired: jest.fn(() => false),
|
|
};
|
|
return selector ? selector(state) : state;
|
|
}) as any;
|
|
|
|
describe('ProfileSettingsPage', () => {
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: { retry: false },
|
|
mutations: { retry: false },
|
|
},
|
|
});
|
|
|
|
const mockUser = {
|
|
id: '1',
|
|
email: 'test@example.com',
|
|
first_name: 'Test',
|
|
last_name: 'User',
|
|
is_active: true,
|
|
is_superuser: false,
|
|
created_at: '2024-01-01T00:00:00Z',
|
|
};
|
|
|
|
const mockUpdateProfile = jest.fn();
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
|
|
// Mock useCurrentUser to return test user
|
|
(useCurrentUser as jest.Mock).mockReturnValue(mockUser);
|
|
|
|
// Mock useUpdateProfile to return mutation handlers
|
|
(useUpdateProfile as jest.Mock).mockReturnValue({
|
|
mutateAsync: mockUpdateProfile,
|
|
isPending: false,
|
|
});
|
|
});
|
|
|
|
const renderWithProvider = (component: React.ReactElement) => {
|
|
return render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<AuthProvider store={mockStoreHook}>{component}</AuthProvider>
|
|
</QueryClientProvider>
|
|
);
|
|
};
|
|
|
|
it('renders without crashing', () => {
|
|
renderWithProvider(<ProfileSettingsPage />);
|
|
expect(screen.getAllByText('Profile Settings').length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('renders heading', () => {
|
|
renderWithProvider(<ProfileSettingsPage />);
|
|
expect(screen.getByRole('heading', { name: /profile settings/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows description text', () => {
|
|
renderWithProvider(<ProfileSettingsPage />);
|
|
expect(screen.getByText(/manage your profile information/i)).toBeInTheDocument();
|
|
});
|
|
});
|