import { expect, test } from '@playwright/test'; import { userByEmail } from '../../support/db'; import { randomEmail, randomPassword } from '../../support/gotrue'; import { fillRegistration, open, t, textOf } from '../../support/web'; /** Zaehlt Signup-Aufrufe der Seite (Krit. 2: „kein Aufruf“). */ function countSignups(page: import('@playwright/test').Page) { const calls: string[] = []; page.on('request', (r) => { if (r.method() === 'POST' && r.url().includes('/auth/v1/signup')) calls.push(r.url()); }); return calls; } test.describe('KTO-01 Kriterien 2, 3, 10 (web): Formularvalidierung', () => { test('KTO-01 Kriterium 2: ohne Altersbestaetigung erscheint der Fehlertext, es gibt keinen Signup-Aufruf', async ({ page }) => { const email = randomEmail(); const calls = countSignups(page); await open(page, '/register'); await fillRegistration(page, { email, password: randomPassword(), age: false }); await page.getByRole('button', { name: 'Create account' }).click(); await expect(textOf(page, t.ageNotConfirmed)).toBeVisible(); await expect(page).toHaveURL(/\/register$/); expect(calls).toEqual([]); expect(await userByEmail(email)).toBeUndefined(); }); test('QUE-04 Kriterium 1: ohne Zustimmung erscheint der Fehlertext, es gibt keinen Signup-Aufruf', async ({ page }) => { const calls = countSignups(page); await open(page, '/register'); await fillRegistration(page, { email: randomEmail(), password: randomPassword(), terms: false }); await page.getByRole('button', { name: 'Create account' }).click(); await expect(textOf(page, t.termsNotAccepted)).toBeVisible(); expect(calls).toEqual([]); }); test('KTO-01 Kriterium 3: zu kurzes Passwort zeigt am Feld, wie viele Zeichen fehlen, und sendet nichts', async ({ page }) => { const calls = countSignups(page); await open(page, '/register'); await fillRegistration(page, { email: randomEmail(), password: 'kurz12345' }); await page.getByRole('button', { name: 'Create account' }).click(); // 9 von 10 Zeichen: noch 1 fehlt (AUTH-CFG-05). await expect(textOf(page, /1 more character needed/)).toBeVisible(); expect(calls).toEqual([]); }); test('KTO-01 Kriterium 3: sehr verbreitetes Passwort wird am Feld abgelehnt', async ({ page }) => { const calls = countSignups(page); await open(page, '/register'); await fillRegistration(page, { email: randomEmail(), password: 'password123' }); await page.getByRole('button', { name: 'Create account' }).click(); await expect(textOf(page, /very common and easy to guess/)).toBeVisible(); expect(calls).toEqual([]); }); test('KTO-01 Kriterium 10: leerer Anzeigename zeigt den Fehler am Feld', async ({ page }) => { const calls = countSignups(page); await open(page, '/register'); await fillRegistration(page, { email: randomEmail(), password: randomPassword(), displayName: ' ' }); await page.getByRole('button', { name: 'Create account' }).click(); await expect(textOf(page, 'Enter a display name.')).toBeVisible(); expect(calls).toEqual([]); }); });