import { type Page } from '@playwright/test'; export const TEST_EMAIL = 'tipilan@ituk.ee'; export const TEST_PASSWORD = 'gu&u6QTMbJK7nT'; export const TEST_ORG_SLUG = 'root-test'; /** * Navigate to the org dashboard. Auth state is pre-loaded via storageState. * If we land on the org selector, click through to the org. */ export async function login(page: Page) { await page.goto(`/${TEST_ORG_SLUG}`, { timeout: 45000 }); // If we got redirected to org selector instead of the org page if (page.url() === 'http://localhost:5173/' || page.url().endsWith(':5173/')) { await page.getByRole('link', { name: /root-test/i }).first().click(); await page.waitForURL(new RegExp(`/${TEST_ORG_SLUG}`), { timeout: 15000 }); } await waitForHydration(page); } /** * Navigate directly to a sub-page (skips the dashboard hop). * Auth state is pre-loaded via storageState. */ export async function navigateTo(page: Page, path: string) { await page.goto(path, { timeout: 45000 }); await waitForHydration(page); } /** * Wait for Svelte 5 hydration on the current page. * Svelte 5 uses event delegation - handlers only work after hydration. */ export async function waitForHydration(page: Page) { await page.waitForFunction(() => { const els = document.querySelectorAll('button'); return Array.from(els).some((el) => (el as any).__click !== undefined); }, { timeout: 15000 }); }