From d5aa37fbfdc8eed54919d4cd55dbced6a37b49a7 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Mon, 8 Sep 2025 01:43:45 -0700 Subject: [PATCH] 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 --- tests/e2e/test-utils.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/e2e/test-utils.ts diff --git a/tests/e2e/test-utils.ts b/tests/e2e/test-utils.ts new file mode 100644 index 0000000..42559ae --- /dev/null +++ b/tests/e2e/test-utils.ts @@ -0,0 +1,36 @@ +// Optimized test utilities to reduce duplication +import { Page } from '@playwright/test'; + +export class TestUtils { + static async loginAsAdmin(page: Page): Promise { + 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 { + 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 { + await page.waitForSelector('h1:has-text("Medication Reminder")'); + } + + static async openModal(page: Page, buttonText: string): Promise { + await page.click(`button:has-text("${buttonText}")`); + } + + static async closeModal(page: Page): Promise { + await page.click('button:has-text("Close")'); + } +}