Restructures frontend to a feature-based folder layout
Continuous Integration / config (pull_request) Successful in 11s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / backend-build (pull_request) Skipped
Continuous Integration / backend-test (pull_request) Skipped
Continuous Integration / vulnerability-scan (pull_request) Skipped
Continuous Integration / frontend-prepare (pull_request) Successful in 1m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m12s
Continuous Integration / frontend-test (pull_request) Successful in 4m42s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 6m51s
Continuous Integration / deploy-test (pull_request) Skipped

Groups auth, setup, invitation, profile, users, cms, availability and
system code (services/hooks, components, schemas, mocks, pages) under
src/features/<name> instead of splitting by technical layer (api/,
components/, lib/schemas/, mocks/, pages/). Renames the old
connection-oriented `api` layer to `services` per feature, and splits
the monolithic api/types.ts into per-feature types.ts files (with
ProblemDetails/ApiResult merged into lib/api-client.ts as shared
infra). Layout-agnostic code (ui primitives, app shell, i18n, test
utils, lib) stays at the top level.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 22:30:37 +02:00
co-authored by Claude Sonnet 5
parent 650cf09cfa
commit 11ec08aac3
83 changed files with 249 additions and 254 deletions
@@ -0,0 +1,120 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { renderApp, mockAuthenticated, mockGuest } from '@/test/utils';
import { server } from '@/mocks/server';
import { API_BASE } from '@/features/auth/mocks/fixtures';
import { _resetSetupStatusCache } from '@/router';
beforeEach(() => {
_resetSetupStatusCache();
});
describe('ProfilePage', () => {
it('renders the page title and profile form', async () => {
mockAuthenticated();
renderApp('/profile');
expect(await screen.findByTestId('profile-title', {}, { timeout: 10000 })).toBeInTheDocument();
expect(screen.getByTestId('profile-name-input')).toBeInTheDocument();
expect(screen.getByTestId('profile-email-input')).toBeInTheDocument();
expect(screen.getByTestId('profile-role-badge')).toBeInTheDocument();
});
it('pre-fills name and email from authenticated user', async () => {
mockAuthenticated();
renderApp('/profile');
const nameInput = await screen.findByTestId<HTMLInputElement>('profile-name-input');
const emailInput = screen.getByTestId<HTMLInputElement>('profile-email-input');
expect(nameInput.value).toBe('Test Owner');
expect(emailInput.value).toBe('owner@example.com');
});
it('save button is disabled when form is pristine', async () => {
mockAuthenticated();
renderApp('/profile');
await screen.findByTestId('profile-name-input');
expect(screen.getByTestId('profile-save-button')).toBeDisabled();
});
it('save button enables after editing a field', async () => {
mockAuthenticated();
renderApp('/profile');
const nameInput = await screen.findByTestId('profile-name-input');
await userEvent.clear(nameInput);
await userEvent.type(nameInput, 'Updated Name');
expect(screen.getByTestId('profile-save-button')).not.toBeDisabled();
});
it('saves profile successfully and shows success toast', async () => {
mockAuthenticated();
renderApp('/profile');
const nameInput = await screen.findByTestId('profile-name-input');
await userEvent.clear(nameInput);
await userEvent.type(nameInput, 'New Name');
await userEvent.click(screen.getByTestId('profile-save-button'));
expect(await screen.findByText(/profile updated/i, {}, { timeout: 10000 })).toBeInTheDocument();
});
it('shows validation error for invalid email', async () => {
mockAuthenticated();
renderApp('/profile');
// Type invalid email — this makes form dirty and triggers validation on submit
const emailInput = await screen.findByTestId('profile-email-input');
await userEvent.tripleClick(emailInput);
await userEvent.type(emailInput, 'not-an-email');
const saveButton = screen.getByTestId('profile-save-button');
expect(saveButton).not.toBeDisabled();
await userEvent.click(saveButton);
expect(await screen.findByTestId('profile-email-error')).toBeInTheDocument();
});
it('opens change password dialog when button is clicked', async () => {
mockAuthenticated();
renderApp('/profile');
await screen.findByTestId('change-password-button');
await userEvent.click(screen.getByTestId('change-password-button'));
expect(await screen.findByTestId('change-password-dialog')).toBeInTheDocument();
});
it('shows error in dialog when current password is wrong', async () => {
server.use(
http.post(`${API_BASE}/api/v1/Auth/change-password`, () =>
HttpResponse.json({ title: 'Bad Request' }, { status: 400 }),
),
);
mockAuthenticated();
renderApp('/profile');
await screen.findByTestId('change-password-button');
await userEvent.click(screen.getByTestId('change-password-button'));
await screen.findByTestId('change-password-dialog');
// PasswordField auto-generates testid as ${id}-input
await userEvent.type(screen.getByTestId('currentPassword-input'), 'WrongPass1!');
await userEvent.type(screen.getByTestId('newPassword-input'), 'NewPassword1!');
await userEvent.type(screen.getByTestId('confirmPassword-input'), 'NewPassword1!');
await userEvent.click(screen.getByTestId('change-password-submit'));
expect(await screen.findByTestId('current-password-error')).toBeInTheDocument();
});
it('redirects unauthenticated users to login', async () => {
mockGuest();
renderApp('/profile');
expect(await screen.findByTestId('login-form-submit-button')).toBeInTheDocument();
});
});
@@ -0,0 +1,287 @@
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { useTranslation } from 'react-i18next';
import { toast } from 'sonner';
import { useAuth } from '@/features/auth/context/auth-context';
import { useUpdateProfile, useChangePassword } from '@/features/profile/services/useProfile';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { RoleBadge } from '@/components/shared/RoleBadge';
import { PasswordField } from '@/components/ui/PasswordField';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { ProblemDetailsError } from '@/lib/api-client';
const profileSchema = z.object({
name: z.string().min(1, 'Name is required'),
email: z.string().email('Enter a valid email address'),
});
const changePasswordSchema = z
.object({
currentPassword: z.string().min(1, 'Required'),
newPassword: z
.string()
.min(8, 'At least 8 characters')
.regex(/[A-Z]/, 'At least 1 uppercase letter')
.regex(/[a-z]/, 'At least 1 lowercase letter')
.regex(/[0-9]/, 'At least 1 digit')
.regex(/[^a-zA-Z0-9]/, 'At least 1 special character'),
confirmPassword: z.string().min(1, 'Required'),
})
.refine((d) => d.newPassword === d.confirmPassword, {
message: 'Passwords do not match',
path: ['confirmPassword'],
});
type ProfileFormData = z.infer<typeof profileSchema>;
type ChangePasswordFormData = z.infer<typeof changePasswordSchema>;
function ChangePasswordDialog({
open,
onClose,
}: {
open: boolean;
onClose: () => void;
}) {
const { t } = useTranslation();
const changePassword = useChangePassword();
const {
register,
handleSubmit,
reset,
setError,
formState: { errors, isSubmitting },
} = useForm<ChangePasswordFormData>({
resolver: zodResolver(changePasswordSchema),
});
const onSubmit = async (data: ChangePasswordFormData) => {
try {
await changePassword.mutateAsync({
currentPassword: data.currentPassword,
newPassword: data.newPassword,
});
toast.success(t('profile.changePasswordDialog.success'));
reset();
onClose();
} catch (err) {
if (err instanceof ProblemDetailsError && err.status === 400) {
setError('currentPassword', {
message: t('profile.changePasswordDialog.errorCurrent'),
});
} else {
setError('root', { message: t('errors.generic') });
}
}
};
const handleClose = () => {
reset();
onClose();
};
return (
<Dialog open={open} onOpenChange={(o) => { if (!o) handleClose(); }}>
<DialogContent data-testid="change-password-dialog">
<DialogHeader>
<DialogTitle>{t('profile.changePasswordDialog.title')}</DialogTitle>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
{errors.root && (
<p className="text-sm text-destructive" data-testid="change-password-error">
{errors.root.message}
</p>
)}
<div className="space-y-1">
<Label htmlFor="currentPassword">
{t('profile.changePasswordDialog.current')}
</Label>
<PasswordField
id="currentPassword"
data-testid="current-password-input"
{...register('currentPassword')}
/>
{errors.currentPassword && (
<p className="text-sm text-destructive" data-testid="current-password-error">
{errors.currentPassword.message}
</p>
)}
</div>
<div className="space-y-1">
<Label htmlFor="newPassword">
{t('profile.changePasswordDialog.new')}
</Label>
<PasswordField
id="newPassword"
data-testid="new-password-input"
{...register('newPassword')}
/>
{errors.newPassword && (
<p className="text-sm text-destructive" data-testid="new-password-error">
{errors.newPassword.message}
</p>
)}
</div>
<div className="space-y-1">
<Label htmlFor="confirmPassword">
{t('profile.changePasswordDialog.confirm')}
</Label>
<PasswordField
id="confirmPassword"
data-testid="confirm-password-input"
{...register('confirmPassword')}
/>
{errors.confirmPassword && (
<p className="text-sm text-destructive" data-testid="confirm-password-error">
{errors.confirmPassword.message}
</p>
)}
</div>
<div className="flex justify-end gap-2 pt-2">
<Button
type="button"
variant="outline"
onClick={handleClose}
data-testid="change-password-cancel"
>
{t('common.cancel')}
</Button>
<Button
type="submit"
disabled={isSubmitting}
data-testid="change-password-submit"
>
{isSubmitting
? t('profile.changePasswordDialog.submitting')
: t('profile.changePasswordDialog.submit')}
</Button>
</div>
</form>
</DialogContent>
</Dialog>
);
}
export function ProfilePage() {
const { t } = useTranslation();
const { user } = useAuth();
const updateProfile = useUpdateProfile();
const [passwordDialogOpen, setPasswordDialogOpen] = useState(false);
const {
register,
handleSubmit,
formState: { errors, isSubmitting, isDirty },
} = useForm<ProfileFormData>({
resolver: zodResolver(profileSchema),
defaultValues: {
name: user?.name ?? '',
email: user?.email ?? '',
},
});
const onSubmit = async (data: ProfileFormData) => {
try {
await updateProfile.mutateAsync(data);
toast.success(t('profile.saveSuccess'));
} catch (err) {
if (err instanceof ProblemDetailsError && err.status === 400) {
toast.error(t('errors.generic'));
} else {
toast.error(t('errors.generic'));
}
}
};
return (
<div className="space-y-6 max-w-lg">
<h1 className="text-2xl font-semibold" data-testid="profile-title">
{t('profile.title')}
</h1>
{/* Profile info card */}
<Card>
<CardHeader>
<CardTitle className="text-base">{t('profile.title')}</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div className="space-y-1">
<Label htmlFor="name">{t('profile.name')}</Label>
<Input
id="name"
data-testid="profile-name-input"
{...register('name')}
/>
{errors.name && (
<p className="text-sm text-destructive" data-testid="profile-name-error">
{errors.name.message}
</p>
)}
</div>
<div className="space-y-1">
<Label htmlFor="email">{t('profile.email')}</Label>
<Input
id="email"
type="email"
data-testid="profile-email-input"
{...register('email')}
/>
{errors.email && (
<p className="text-sm text-destructive" data-testid="profile-email-error">
{errors.email.message}
</p>
)}
</div>
<div className="space-y-1">
<Label>{t('profile.role')}</Label>
<div>
{user?.role
? <RoleBadge role={user.role} data-testid="profile-role-badge" />
: <span data-testid="profile-role-badge">—</span>}
</div>
</div>
<Button
type="submit"
disabled={isSubmitting || !isDirty}
data-testid="profile-save-button"
>
{isSubmitting ? t('profile.saving') : t('profile.save')}
</Button>
</form>
</CardContent>
</Card>
{/* Security card */}
<Card>
<CardHeader>
<CardTitle className="text-base">Security</CardTitle>
</CardHeader>
<CardContent>
<Button
variant="outline"
onClick={() => setPasswordDialogOpen(true)}
data-testid="change-password-button"
>
{t('profile.changePassword')}
</Button>
</CardContent>
</Card>
<ChangePasswordDialog
open={passwordDialogOpen}
onClose={() => setPasswordDialogOpen(false)}
/>
</div>
);
}
@@ -0,0 +1,86 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { createElement } from 'react';
import { http, HttpResponse } from 'msw';
import { describe, expect, it } from 'vitest';
import { server } from '@/mocks/server';
import { API_BASE } from '@/features/auth/mocks/fixtures';
import { useUpdateProfile, useChangePassword } from '@/features/profile/services/useProfile';
import { AuthProvider } from '@/features/auth/context/AuthProvider';
import i18n from '@/i18n/config';
import { I18nextProvider } from 'react-i18next';
import type { ReactNode } from 'react';
function createWrapper() {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
});
return ({ children }: { children: ReactNode }) =>
createElement(
QueryClientProvider,
{ client: queryClient },
createElement(
I18nextProvider,
{ i18n },
createElement(AuthProvider, null, children),
),
);
}
describe('useUpdateProfile', () => {
it('succeeds and returns updated user', async () => {
const { result } = renderHook(() => useUpdateProfile(), { wrapper: createWrapper() });
await act(async () => {
await result.current.mutateAsync({ name: 'New Name', email: 'new@example.com' });
});
await waitFor(() => expect(result.current.isSuccess).toBe(true));
expect(result.current.data?.name).toBe('New Name');
});
it('enters error state on server failure', async () => {
server.use(
http.put(`${API_BASE}/api/v1/Users/me`, () =>
HttpResponse.json({ title: 'Bad Request', status: 400 }, { status: 400 }),
),
);
const { result } = renderHook(() => useUpdateProfile(), { wrapper: createWrapper() });
await act(async () => {
await result.current
.mutateAsync({ name: 'Bad', email: 'bad@example.com' })
.catch(() => {});
});
await waitFor(() => expect(result.current.isError).toBe(true));
});
});
describe('useChangePassword', () => {
it('succeeds with correct current password', async () => {
const { result } = renderHook(() => useChangePassword(), { wrapper: createWrapper() });
await act(async () => {
await result.current.mutateAsync({
currentPassword: 'Password123!',
newPassword: 'NewPassword1!',
});
});
await waitFor(() => expect(result.current.isSuccess).toBe(true));
});
it('enters error state when current password is wrong', async () => {
const { result } = renderHook(() => useChangePassword(), { wrapper: createWrapper() });
await act(async () => {
await result.current
.mutateAsync({ currentPassword: 'WrongPassword!', newPassword: 'NewPassword1!' })
.catch(() => {});
});
await waitFor(() => expect(result.current.isError).toBe(true));
});
});
@@ -0,0 +1,31 @@
import { useMutation } from '@tanstack/react-query';
import { api } from '@/lib/api-client';
import { useAuth } from '@/features/auth/context/auth-context';
import type { UserListItem } from '@/features/users/services/types';
export interface UpdateProfilePayload {
name: string;
email: string;
}
export interface ChangePasswordPayload {
currentPassword: string;
newPassword: string;
}
export function useUpdateProfile() {
const { refresh } = useAuth();
return useMutation<UserListItem, Error, UpdateProfilePayload>({
mutationFn: (data) => api.put<UserListItem>('/api/v1/Users/me', data),
onSuccess: () => {
// Sync AuthContext with updated name/email via token refresh
void refresh();
},
});
}
export function useChangePassword() {
return useMutation<void, Error, ChangePasswordPayload>({
mutationFn: (data) => api.post<void>('/api/v1/Auth/change-password', data),
});
}