import { test, expect } from '@playwright/test'; import { TEST_ORG_SLUG, navigateTo, waitForHydration } from './helpers'; // Unique suffix for this test run const RUN = Date.now(); const EVENT_NAME = `PW Finance ${RUN}`; const DEPT_NAME = `PW Fin Dept ${RUN}`; let eventSlug = ''; let deptId = ''; async function gotoEventPath(page: import('@playwright/test').Page, subPath: string) { await navigateTo(page, `/${TEST_ORG_SLUG}/events/${eventSlug}/${subPath}`); } async function gotoEvent(page: import('@playwright/test').Page) { await navigateTo(page, `/${TEST_ORG_SLUG}/events/${eventSlug}`); } // ─── Serial flow: create event + dept, then test new pages ────────────────── test.describe.serial('Finance Features - New Event Pages', () => { // ════════════════════════════════════════════════════════════════════ // 0. SETUP: Create event + department // ════════════════════════════════════════════════════════════════════ test('should create a test event', async ({ page }) => { test.setTimeout(60000); await navigateTo(page, `/${TEST_ORG_SLUG}/events`); await page.getByRole('button', { name: /New Event/i }).click(); const modal = page.locator('[role="dialog"]'); await expect(modal).toBeVisible({ timeout: 3000 }); await modal.locator('#event-name').fill(EVENT_NAME); const submitBtn = modal.locator('button[type="submit"]'); await expect(submitBtn).toBeEnabled({ timeout: 3000 }); await submitBtn.click(); await page.waitForURL((url) => { const path = url.pathname; return path.includes(`/${TEST_ORG_SLUG}/events/`) && !path.endsWith('/events') && !path.endsWith('/events/'); }, { timeout: 15000 }); await waitForHydration(page); const segments = new URL(page.url()).pathname.split('/'); eventSlug = segments[segments.indexOf('events') + 1]; expect(eventSlug).toBeTruthy(); }); test('should create a test department', async ({ page }) => { test.setTimeout(60000); await gotoEventPath(page, 'team'); await page.getByRole('button', { name: /Add Department/i }).click(); const modal = page.locator('[role="dialog"]'); await expect(modal).toBeVisible({ timeout: 3000 }); await modal.locator('#dept-name').fill(DEPT_NAME); await modal.getByRole('button', { name: /Save/i }).click(); await expect(modal).not.toBeVisible({ timeout: 10000 }); await expect(page.getByText(DEPT_NAME).first()).toBeVisible({ timeout: 5000 }); // Reload the event page so the sidebar picks up the new department await gotoEvent(page); const sidebar = page.locator('aside'); await expect(sidebar.getByText(DEPT_NAME).first()).toBeVisible({ timeout: 10000 }); await sidebar.getByText(DEPT_NAME).first().click(); await page.waitForURL(/\/dept\//, { timeout: 10000 }); const match = page.url().match(/\/dept\/([^/]+)/); if (match) deptId = match[1]; expect(deptId).toBeTruthy(); }); // ════════════════════════════════════════════════════════════════════ // 1. SIDEBAR - new nav items // ════════════════════════════════════════════════════════════════════ test('should show Sponsors, Contacts, and Files in sidebar', async ({ page }) => { await gotoEvent(page); // The event sidebar is the last