|
| 1 | +const { expect } = require('@playwright/test'); |
| 2 | +const { test } = require('../fixtures/base'); |
| 3 | +const { TEST_IDS } = require('../fixtures/test-ids'); |
| 4 | +const { MailgunHelper } = require('../helpers/mailgun'); |
| 5 | +const { TEST_RESET_EMAIL } = require('e2e/fixtures/users'); |
| 6 | +require('../msw-setup.js'); |
| 7 | + |
| 8 | +// Test email for password reset |
| 9 | +const TEST_EMAIL = TEST_RESET_EMAIL; |
| 10 | + |
| 11 | +test.describe('Password reset flow', () => { |
| 12 | + let mailgun; |
| 13 | + |
| 14 | + test.beforeAll(async () => { |
| 15 | + mailgun = new MailgunHelper(); |
| 16 | + }); |
| 17 | + |
| 18 | + test('should complete password reset flow', async ({ page }) => { |
| 19 | + // Step 1: Go to request password reset page |
| 20 | + await page.goto('/request-reset-password'); |
| 21 | + await page.waitForLoadState('networkidle'); |
| 22 | + |
| 23 | + // Step 2: Fill out reset request form |
| 24 | + await page.fill(`input[data-test="${TEST_IDS.email_input}"]`, TEST_EMAIL); |
| 25 | + |
| 26 | + // Step 3: Submit form |
| 27 | + await page.click(`[data-test="${TEST_IDS.form_submit}"]`); |
| 28 | + |
| 29 | + // Step 4: Verify we're on the success page |
| 30 | + // await expect(page.locator('h1')).toContainText( |
| 31 | + // 'Request a link to reset your password' |
| 32 | + // ); |
| 33 | + await expect( |
| 34 | + page.locator(`[data-test="${TEST_IDS.success_subheading}"]`) |
| 35 | + ).toContainText('We sent you an email with a link to reset your password'); |
| 36 | + |
| 37 | + // Step 5: Wait for and retrieve password reset email |
| 38 | + console.log('Waiting for password reset email...'); |
| 39 | + const email = await mailgun.getLatestEmailFor(TEST_EMAIL); |
| 40 | + |
| 41 | + // Step 6: Extract reset URL from email |
| 42 | + const resetUrl = mailgun.extractPasswordResetUrl( |
| 43 | + email.body.html || email.body.text |
| 44 | + ); |
| 45 | + console.log(`Reset URL: ${resetUrl}`); |
| 46 | + |
| 47 | + // Step 7: Navigate to reset URL |
| 48 | + await page.goto(resetUrl); |
| 49 | + await page.waitForLoadState('networkidle'); |
| 50 | + |
| 51 | + // Step 8: Fill out new password form |
| 52 | + await page.fill( |
| 53 | + `input[data-test="${TEST_IDS.password_input}"]`, |
| 54 | + 'NewPassword123!' |
| 55 | + ); |
| 56 | + await page.fill( |
| 57 | + `input[data-test="${TEST_IDS.confirm_password_input}"]`, |
| 58 | + 'NewPassword123!' |
| 59 | + ); |
| 60 | + |
| 61 | + // Step 9: Submit new password |
| 62 | + await page.click(`[data-test="${TEST_IDS.form_submit}"]`); |
| 63 | + |
| 64 | + // Step 10: Verify password was reset successfully |
| 65 | + await expect(page).toHaveURL(/\/profile/); |
| 66 | + }); |
| 67 | +}); |
0 commit comments