- 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
37 lines
1.2 KiB
TypeScript
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")');
|
|
}
|
|
}
|