fix(e2e): fix Playwright E2E test suite for CI

- Replace __dirname with fileURLToPath(import.meta.url) for ESM compatibility
- Start SvelteKit dev server on port 3000 with 120s webServer timeout
- Add data-hydrated attribute (set in onMount) so tests wait for hydration
- Fix nav active class assertions: text-brand-navy (not border-brand-navy)
- Fix filter button selector: exact match to avoid matching "Alle Filter löschen"
- Fix date validation test: use pressSequentially('99') to trigger dateInvalid
- Fix person/document search: navigate directly to URL with query param
  (avoids debounced oninput → goto race condition in CI)
- Fix heading selector: level: 1 to avoid strict-mode with h1+h2 on page
- Fix auth redirect: return 401 from handleFetch instead of throwing redirect

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-19 11:08:56 +01:00
parent 9f3f022ec0
commit 56cbd290e3
7 changed files with 47 additions and 27 deletions

View File

@@ -3,6 +3,16 @@ import { paraglideMiddleware } from '$lib/paraglide/server';
import { sequence } from '@sveltejs/kit/hooks';
import { env } from 'process';
const PUBLIC_PATHS = ['/login', '/logout'];
const handleAuth: Handle = async ({ event, resolve }) => {
const isPublic = PUBLIC_PATHS.some((p) => event.url.pathname.startsWith(p));
if (!isPublic && !event.locals.user) {
throw redirect(302, '/login');
}
return resolve(event);
};
const handleParaglide: Handle = ({ event, resolve }) => paraglideMiddleware(event.request, ({ request, locale }) => {
event.request = request;
@@ -43,7 +53,7 @@ export const handleFetch: HandleFetch = async ({ event, request, fetch }) => {
const token = event.cookies.get('auth_token');
if (!token) {
throw redirect(302, '/login');
return new Response('Unauthorized', { status: 401 });
}
// Clone the request first to preserve the body
@@ -63,4 +73,4 @@ export const handleFetch: HandleFetch = async ({ event, request, fetch }) => {
return fetch(request);
};
export const handle = sequence(userGroup, handleParaglide);
export const handle = sequence(userGroup, handleAuth, handleParaglide);

View File

@@ -2,13 +2,19 @@
import './layout.css';
import { enhance } from '$app/forms';
import { page } from '$app/state';
import { onMount } from 'svelte';
let { children } = $props();
const isAdmin = $derived(page.data.user?.groups.some((g: { permissions: string[] }) => g.permissions.includes('ADMIN')));
// Set after client-side hydration completes. Used by E2E tests to know the
// page is interactive (event handlers registered) before they interact with it.
let hydrated = $state(false);
onMount(() => { hydrated = true; });
</script>
<div class="min-h-screen bg-white">
<div class="min-h-screen bg-white" data-hydrated={hydrated || undefined}>
{#if !page.url.pathname.startsWith('/login')}
<header class="bg-white border-b border-gray-100 sticky top-0 z-50">

View File

@@ -93,7 +93,7 @@ let { form } = $props();
type="submit"
class="rounded bg-brand-navy px-6 py-2 text-sm font-bold tracking-widest text-white uppercase transition-colors hover:bg-brand-navy/80"
>
Speichern
Erstellen
</button>
</div>
</form>