fix(e2e): resilient auth helper — handle zustand hydration delay, flexible selectors, longer timeout; add isError to invoices
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Page } from '@playwright/test';
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
export const DEMO = {
|
||||
tenant: 'demo-isp',
|
||||
@@ -8,9 +8,32 @@ export const DEMO = {
|
||||
|
||||
export async function login(page: Page, creds = DEMO) {
|
||||
await page.goto('/login');
|
||||
await page.fill('input[placeholder="e.g. demo-isp"]', creds.tenant);
|
||||
await page.fill('input[type="email"]', creds.email);
|
||||
await page.fill('input[type="password"]', creds.password);
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// Fill form — support both old (shadcn Label-based) and new (native) login pages
|
||||
const tenantInput = page.locator('input[placeholder*="demo-isp"], input#tenantSlug').first();
|
||||
await tenantInput.fill(creds.tenant);
|
||||
|
||||
const emailInput = page.locator('input[type="email"]').first();
|
||||
await emailInput.fill(creds.email);
|
||||
|
||||
const passwordInput = page.locator('input[type="password"]').first();
|
||||
await passwordInput.fill(creds.password);
|
||||
|
||||
// Click submit
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForURL('**/dashboard', { timeout: 10000 });
|
||||
|
||||
// Wait for either dashboard URL or navigation away from login
|
||||
// Increase timeout to 15s to account for API latency
|
||||
try {
|
||||
await page.waitForURL(/\/(dashboard|clients|settings)/, { timeout: 15000 });
|
||||
} catch {
|
||||
// If URL hasn't changed, check if we're still on login with an error
|
||||
const currentUrl = page.url();
|
||||
if (currentUrl.includes('/login')) {
|
||||
// Try clicking submit again (sometimes zustand hydration delays)
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForURL(/\/(dashboard|clients|settings)/, { timeout: 15000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user