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
This commit is contained in:
36
tests/e2e/test-utils.ts
Normal file
36
tests/e2e/test-utils.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// 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")');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user