Shuffle/e2e/tests/web/krit05-sitzung.spec.ts
cschlaefke aa421b12b0
Some checks failed
CI / flutter (pull_request) Successful in 1m15s
CI / web-build (pull_request) Successful in 53s
CI / supabase (pull_request) Successful in 3s
CI / supabase-tests (pull_request) Successful in 30s
CI / e2e (pull_request) Failing after 3m56s
test(auth): address review findings for e2e
Refs #38

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 10:55:27 +01:00

51 lines
2 KiB
TypeScript

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$/);
});
});