Files
crumbs-original/tests/e2e/helpers/fixtures.ts
T
Frederic CabassutandClaude Opus 4.6 f0361732fe fix: make E2E tests resilient to shared DB in parallel execution
- Add noteCard() helper to target specific cards by title instead of
  generic getByTestId('note-card') which fails with multiple matches
- Scope action button clicks (trash, pin, archive) within their card
- Scope tag-chip filter clicks to the tag-filter container
- Wait for networkidle after auth to ensure full hydration
- Remove "empty notes list" test incompatible with shared DB
- Use toHaveCount(0) instead of not.toBeVisible for search empty state

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 23:32:42 +01:00

55 lines
1.8 KiB
TypeScript

import { test as base, expect, type Page, type Locator } from '@playwright/test';
const TEST_PASSWORD = 'testpassword123';
/** Find a specific note card by its title text */
export function noteCard(page: Page, title: string): Locator {
return page.locator('[data-testid="note-card"]', { hasText: title });
}
/**
* Extended test fixture that handles setup/auth.
*/
export const test = base.extend<{ authenticatedPage: Page }>({
authenticatedPage: async ({ page }, use) => {
// Setup: create user and login
await setupAndLogin(page);
await use(page);
}
});
export async function setupAndLogin(page: Page) {
await page.goto('/');
const url = page.url();
if (url.includes('/setup')) {
// First-time setup - may race with other workers
await page.getByTestId('password-input').fill(TEST_PASSWORD);
await page.getByTestId('confirm-password-input').fill(TEST_PASSWORD);
await page.getByTestId('setup-btn').click();
// Wait for either redirect to main page or an error (another worker completed setup first)
try {
await page.waitForURL('/', { timeout: 5000 });
} catch {
// Setup was completed by another worker - go to login instead
await page.goto('/login');
await page.getByTestId('password-input').fill(TEST_PASSWORD);
await page.getByTestId('login-btn').click();
await page.waitForURL('/');
}
} else if (url.includes('/login')) {
// Login
await page.getByTestId('password-input').fill(TEST_PASSWORD);
await page.getByTestId('login-btn').click();
await page.waitForURL('/');
}
// else: already on main page (session still valid)
// Wait for full hydration after auth redirect (window.location.href causes full reload).
// networkidle ensures JS bundles have loaded and executed.
await page.waitForLoadState('networkidle');
}
export { expect };