import { expect, test } from '@playwright/test'; import { GoTrueClient, randomEmail, randomPassword } from '../../support/gotrue'; import { env } from '../../support/auth-config'; import { enableSemantics, expectSignedIn, expectSignedInViaLoginRedirect, login, open, readAuthStorage } from '../../support/web'; const gotrue = new GoTrueClient(); test.describe('KTO-01 Kriterium 5 (web): Sitzung bleibt bestehen', () => { test('KTO-01 Kriterium 5: Login, Reload und neuer Browser-Kontext mit gleichem Storage bleiben angemeldet', async ({ page, browser, }) => { const email = randomEmail(); const password = randomPassword(); await gotrue.createConfirmedUser(email, password); await login(page, email, password); await expectSignedIn(page); const stored = await readAuthStorage(page); expect(Object.keys(stored).length, 'Sitzung liegt im localStorage').toBeGreaterThan(0); // Reload: weiterhin angemeldet (/login leitet auf die Startseite). await page.reload(); await expectSignedInViaLoginRedirect(page); // Neuer Browser-Kontext mit gleichem Storage (z. B. Browser neu gestartet). const state = await page.context().storageState(); const restored = await browser.newContext({ storageState: state, locale: 'en-US', serviceWorkers: 'block', baseURL: env.webUrl, }); try { const other = await restored.newPage(); await other.goto('/login'); await enableSemantics(other); await expect(other).toHaveURL(/\/$/); } finally { await restored.close(); } }); test('KTO-01 Kriterium 5: ohne Sitzung bleibt /login erreichbar (Gegenprobe)', async ({ page }) => { await open(page, '/login'); // Erst nach dem Flutter-Boot pruefen: das Formular ist sichtbar, ein spaeter Redirect waere bis dahin passiert. await expect(page.getByRole('button', { name: 'Sign in', exact: true })).toBeVisible(); await page.waitForTimeout(500); await expect(page).toHaveURL(/\/login$/); }); });