import { test, expect } from './helpers/fixtures.js' test.describe('Admin pre-registrants page', () => { test('page loads for admin', async ({ adminPage }) => { await adminPage.goto('/admin/pre-registrants') await expect(adminPage.getByRole('heading', { name: 'Pre-Registrants' })).toBeVisible({ timeout: 15000, }) await expect( adminPage.locator('table').or(adminPage.getByText('No pre-registrants found matching your criteria')), ).toBeVisible({ timeout: 15000 }) }) test('header action buttons render', async ({ adminPage }) => { await adminPage.goto('/admin/pre-registrants') await expect(adminPage.getByRole('heading', { name: 'Pre-Registrants' })).toBeVisible({ timeout: 15000, }) await expect(adminPage.getByRole('button', { name: /^Mark as Selected/ })).toBeVisible() await expect(adminPage.getByRole('button', { name: /^Send Invites/ })).toBeVisible() }) test('search input filters list without crashing', async ({ adminPage }) => { await adminPage.goto('/admin/pre-registrants') await adminPage.waitForLoadState('networkidle') const search = adminPage.getByPlaceholder('Search by name, email, city, role...') await expect(search).toBeVisible({ timeout: 15000 }) await search.fill(`nonexistent-prereg-${Date.now()}`) await expect( adminPage.getByText('No pre-registrants found matching your criteria'), ).toBeVisible({ timeout: 10000 }) }) test('status filter changes selection', async ({ adminPage }) => { await adminPage.goto('/admin/pre-registrants') await adminPage.waitForLoadState('networkidle') const statusFilter = adminPage.getByLabel('Filter by status') await expect(statusFilter).toBeVisible({ timeout: 15000 }) await statusFilter.selectOption('expired') await expect(statusFilter).toHaveValue('expired') await expect( adminPage.locator('table').or(adminPage.getByText('No pre-registrants found matching your criteria')), ).toBeVisible({ timeout: 10000 }) await statusFilter.selectOption('') await expect(statusFilter).toHaveValue('') }) test('Send Invites button is disabled with no selection', async ({ adminPage }) => { await adminPage.goto('/admin/pre-registrants') await expect(adminPage.getByRole('heading', { name: 'Pre-Registrants' })).toBeVisible({ timeout: 15000, }) await expect(adminPage.getByRole('button', { name: 'Send Invites (0)' })).toBeDisabled() await expect(adminPage.getByRole('button', { name: 'Mark as Selected (0)' })).toBeDisabled() }) test('send invite action', async ({ adminPage }) => { await adminPage.goto('/admin/pre-registrants') await adminPage.waitForLoadState('networkidle') await expect(adminPage.getByRole('heading', { name: 'Pre-Registrants' })).toBeVisible({ timeout: 15000, }) // Filter to invitable statuses; pick the first row if available. const statusFilter = adminPage.getByLabel('Filter by status') await statusFilter.selectOption('pending') await adminPage.waitForLoadState('networkidle') const firstRow = adminPage.locator('tbody tr').first() if (await firstRow.count() === 0) { test.skip(true, 'No pending pre-registrants in dev DB to invite') return } await firstRow.locator('.col-name').click() const sendButton = adminPage.getByRole('button', { name: /^Send Invites \(\d+\)/ }) await expect(sendButton).toBeEnabled() await sendButton.click() await expect(adminPage.getByRole('heading', { name: 'Send Invitation Emails' })).toBeVisible() const submitButton = adminPage.getByRole('button', { name: /^Send \d+ invitation/ }) await submitButton.click() // ALLOW_DEV_TEST_ENDPOINTS=true short-circuits the Resend call; result still reports sent. await expect(adminPage.getByText(/^\d+ sent$/)).toBeVisible({ timeout: 15000 }) }) test('non-admin redirect', async ({ browser }) => { const context = await browser.newContext() const page = await context.newPage() await page.goto('/admin/pre-registrants') await page.waitForURL((url) => !url.pathname.startsWith('/admin')) expect(page.url()).not.toContain('/admin/pre-registrants') await context.close() }) })