Files
rxminder/tests/e2e/test-utils.ts
William Valentin d5aa37fbfd feat: add reusable E2E test utilities
- Create TestUtils class for common test operations
- Add loginAsAdmin and loginAsUser helper methods
- Include modal management utilities (open/close)
- Reduce code duplication across E2E test files
- Standardize test patterns and improve maintainability
2025-09-08 01:43:45 -07:00

37 lines
1.2 KiB
TypeScript

// Optimized test utilities to reduce duplication
import { Page } from '@playwright/test';
export class TestUtils {
static async loginAsAdmin(page: Page): Promise<void> {
await page.goto('/');
await page.fill('input[type="email"]', 'admin@localhost');
await page.fill('input[type="password"]', 'admin123!');
await page.click('button[type="submit"]');
await page.waitForSelector('h1:has-text("Medication Reminder")');
}
static async loginAsUser(
page: Page,
email: string = 'testuser@example.com',
password: string = 'TestPassword123!'
): Promise<void> {
await page.goto('/');
await page.fill('input[type="email"]', email);
await page.fill('input[type="password"]', password);
await page.click('button[type="submit"]');
await page.waitForSelector('h1:has-text("Medication Reminder")');
}
static async waitForApp(page: Page): Promise<void> {
await page.waitForSelector('h1:has-text("Medication Reminder")');
}
static async openModal(page: Page, buttonText: string): Promise<void> {
await page.click(`button:has-text("${buttonText}")`);
}
static async closeModal(page: Page): Promise<void> {
await page.click('button:has-text("Close")');
}
}