diff --git a/admin/src/pages/users/UserForm.tsx b/admin/src/pages/users/UserForm.tsx
index dd8ea47..711cb0e 100644
--- a/admin/src/pages/users/UserForm.tsx
+++ b/admin/src/pages/users/UserForm.tsx
@@ -87,10 +87,11 @@ export default function UserForm() {
const gyms: Gym[] = gymsData?.gyms ?? [];
const [form, setForm] = useState({
- email: '',
- password: '',
firstName: '',
lastName: '',
+ password: '',
+ password2: '',
+ email: '',
age: '',
isAdmin: false,
});
@@ -107,10 +108,11 @@ export default function UserForm() {
if (seededRef.current || !user) return;
seededRef.current = true;
setForm({
- email: user.email,
- password: '',
firstName: user.firstName ?? '',
lastName: user.lastName ?? '',
+ password: '',
+ password2: '',
+ email: user.email,
age: user.age?.toString() ?? '',
isAdmin: user.isAdmin,
});
@@ -148,6 +150,8 @@ export default function UserForm() {
if (!isEdit && form.password.length < 8) return 'Hasło musi mieć co najmniej 8 znaków.';
if (isEdit && form.password && form.password.length < 8)
return 'Nowe hasło musi mieć co najmniej 8 znaków.';
+ // w edycji oba pola mogą zostać puste (bez zmiany hasła); w tworzeniu muszą się zgadzać
+ if (form.password !== form.password2) return 'Podane hasła muszą być takie same.';
return '';
};
@@ -271,24 +275,6 @@ export default function UserForm() {
Dane
-
- setForm({ ...form, email: e.target.value })}
- required
- />
-
-
- setForm({ ...form, password: e.target.value })}
- minLength={8}
- required={!isEdit}
- placeholder={isEdit ? '••••••••' : undefined}
- />
-
setForm({ ...form, lastName: e.target.value })}
/>
+
+ setForm({ ...form, password: e.target.value })}
+ minLength={8}
+ required={!isEdit}
+ placeholder={isEdit ? '••••••••' : undefined}
+ />
+
+
+ setForm({ ...form, password2: e.target.value })}
+ minLength={8}
+ required={!isEdit}
+ placeholder={isEdit ? '••••••••' : undefined}
+ />
+
+
+ setForm({ ...form, email: e.target.value })}
+ required
+ />
+
{
await user.type(container.querySelector('input[type="email"]')!, 'nowy3@test.local');
await user.type(container.querySelector('input[type="password"]')!, 'Password123!');
+ await user.type(container.querySelectorAll('input[type="password"]')[1], 'Password123!');
// wybierz siłownię (placeholder „Szukaj siłowni…”) i zaznacz rolę Trener
await user.click(screen.getByRole('button', { name: 'Dodaj pierwszą siłownię' }));
@@ -214,6 +215,7 @@ describe('admin UserForm — kreator tworzenia', () => {
const { container } = renderForm('/users/new');
await user.type(container.querySelector('input[type="email"]')!, 'nowy4@test.local');
await user.type(container.querySelector('input[type="password"]')!, 'Password123!');
+ await user.type(container.querySelectorAll('input[type="password"]')[1], 'Password123!');
await user.click(screen.getByRole('button', { name: 'Dodaj pierwszą siłownię' }));
await user.click(screen.getByRole('checkbox', { name: 'Właściciel — siłownia 1' }));
@@ -236,6 +238,7 @@ describe('admin UserForm — kreator tworzenia', () => {
const { container } = renderForm('/users/new');
await user.type(container.querySelector('input[type="email"]')!, 'nowy5@test.local');
await user.type(container.querySelector('input[type="password"]')!, 'Password123!');
+ await user.type(container.querySelectorAll('input[type="password"]')[1], 'Password123!');
await user.click(screen.getByRole('button', { name: 'Dodaj pierwszą siłownię' }));
await user.click(container.querySelector('input[role="combobox"]')!);
await user.click(await screen.findByRole('option', { name: /Steel Gym/ }));
@@ -248,6 +251,24 @@ describe('admin UserForm — kreator tworzenia', () => {
await user.click(within(dialog).getByRole('button', { name: 'Rozumiem' }));
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});
+
+ it('blokuje zapis, gdy powtórzone hasło różni się od hasła', async () => {
+ const calls = mockRoutes([
+ { match: '/admin/gyms', reply: () => ({ gyms: [GYM_A] }) },
+ { method: 'POST', match: '/admin/users', reply: () => ({ user: CREATED }) },
+ ]);
+ const user = userEvent.setup();
+ const { container } = renderForm('/users/new');
+ const pw = container.querySelectorAll('input[type="password"]');
+ await user.type(container.querySelector('input[type="email"]')!, 'nowy6@test.local');
+ await user.type(pw[0], 'Password123!');
+ await user.type(pw[1], 'InneHaslo123!');
+
+ await submitForm();
+
+ expect(await screen.findByText('Podane hasła muszą być takie same.')).toBeInTheDocument();
+ expect(calls.filter((c) => c.init?.method === 'POST')).toHaveLength(0);
+ });
});
describe('admin UserForm — kreator edycji', () => {
diff --git a/admin/test/e2e/admin.spec.ts b/admin/test/e2e/admin.spec.ts
index edad05f..5673a0b 100644
--- a/admin/test/e2e/admin.spec.ts
+++ b/admin/test/e2e/admin.spec.ts
@@ -242,7 +242,8 @@ test('menu kontekstowe formularza „Nowy użytkownik” ma Zapisz, który wysy
});
await page.locator('input[type="email"]').fill('nowy@fitos.pl');
- await page.locator('input[type="password"]').fill('Password123!');
+ await page.locator('input[type="password"]').first().fill('Password123!');
+ await page.locator('input[type="password"]').nth(1).fill('Password123!');
const postPromise = page.waitForRequest(
(req) => req.method() === 'POST' && req.url().endsWith('/admin/users'),
@@ -261,7 +262,8 @@ test('kreator blokuje zapis niekompletnego członkostwa — modal „Nie można
await page.getByRole('link', { name: 'Użytkownicy' }).click();
await page.getByRole('button', { name: 'Nowy użytkownik' }).click();
await page.locator('input[type="email"]').fill('rola@fitos.pl');
- await page.locator('input[type="password"]').fill('Password123!');
+ await page.locator('input[type="password"]').first().fill('Password123!');
+ await page.locator('input[type="password"]').nth(1).fill('Password123!');
// rola bez wybranej siłowni → zapis wzbroniony
await page.getByRole('button', { name: 'Dodaj pierwszą siłownię' }).click();