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")'); + } +}