import { test, expect, Page } from './fixtures'; const PASSWORD = 'supersecret123'; const uniqueEmail = () => `resend-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}@example.com`; // The generous wait matches the other account specs: registration is a bcrypt // round-trip rather than a render, and runs past Playwright's 5s default when // the suite's workers all register at once. async function registerCustomer(page: Page): Promise { const email = uniqueEmail(); await page.goto('/register'); await page.getByRole('textbox', { name: 'Email' }).fill(email); await page.getByRole('textbox', { name: 'First name' }).fill('Test'); await page.getByRole('textbox', { name: 'Last name' }).fill('Customer'); await page.getByLabel('Password').fill(PASSWORD); await page.getByRole('button', { name: 'Create account' }).click(); await expect(page.getByRole('button', { name: 'My Account' })).toBeVisible({ timeout: 20000 }); return email; } const accountModal = (page: Page) => page.getByRole('dialog', { name: 'My Account' }); test.describe('Resending your verification email', () => { test('the account page offers it while the address is unverified', async ({ page }) => { await registerCustomer(page); await page.goto('/account'); const modal = accountModal(page); await expect(modal.getByText('Email not verified')).toBeVisible(); await expect(modal.getByRole('button', { name: 'Send it again' })).toBeVisible(); }); test('confirms when it has sent', async ({ page }) => { await registerCustomer(page); await page.goto('/account'); await accountModal(page).getByRole('button', { name: 'Send it again' }).click(); await expect(page.getByText('Check your inbox, and your spam folder.')).toBeVisible(); }); // The message the customer gets on the fourth attempt is the point of the // limiter's copy: it says the mail probably did send and where to look, // rather than only that a limit exists. test('says something useful once the allowance runs out', async ({ page }) => { await registerCustomer(page); await page.goto('/account'); const resend = accountModal(page).getByRole('button', { name: 'Send it again' }); for (let i = 0; i < 3; i++) { await resend.click(); await expect(resend).toBeEnabled(); } await resend.click(); // Matched on the phrase unique to the refusal. "spam folder" appears in the // success message too, and the three stacked success toasts from the loop // above are still on screen, so the looser match finds them instead. await expect(page.getByText(/already sent several/)).toBeVisible(); }); });