import { test, expect, type Page } from '@playwright/test'; const adminUrl = process.env.CONVIVO_ADMIN_URL || 'http://localhost:3001'; const eventId = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa'; const user = { id: '99999999-9999-4999-8999-999999999999', email: 'admin@appe.at', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} }; const contacts = [ { email: 'admin@appe.at', full_name: 'Admin User', linkedin_url: null, show_email: true, show_linkedin: true, is_admin: true, created_at: 'x' }, { email: 'jane.doe@example.com', full_name: 'Jane Doe', linkedin_url: 'https://linkedin.com/in/janedoe', show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' }, { email: 'john.doe@example.com', full_name: 'John Doe', linkedin_url: null, show_email: false, show_linkedin: false, is_admin: false, created_at: 'x' }, { email: 'amy.doe@example.com', full_name: 'Amy Doe', linkedin_url: 'https://linkedin.com/in/amydoe', show_email: true, show_linkedin: true, is_admin: false, created_at: 'x' }, { email: 'sam.roe@example.com', full_name: 'Sam Roe', linkedin_url: null, show_email: false, show_linkedin: true, is_admin: false, created_at: 'x' }, ]; const registrations = [ { id: 'r1', event_id: eventId, contact_email: 'jane.doe@example.com', type: 'attendee', qr_token: 'CV-JANE-01', external_id: null, import_source: null, checked_in: true, points: 5 }, { id: 'r2', event_id: eventId, contact_email: 'john.doe@example.com', type: 'speaker', qr_token: 'CV-JOHN-02', external_id: null, import_source: null, checked_in: false, points: 12 }, { id: 'r3', event_id: eventId, contact_email: 'amy.doe@example.com', type: 'attendee', qr_token: null, external_id: null, import_source: 'sessionize', checked_in: false, points: 0 }, { id: 'r4', event_id: eventId, contact_email: 'sam.roe@example.com', type: 'staff', qr_token: 'CV-SAM-04', external_id: null, import_source: null, checked_in: true, points: 2 }, ]; const event = { id: eventId, name: 'Filter Conference', company: 'APPE', is_active: true, start_date: '2026-11-01', end_date: '2026-11-01', num_registrations: 4, num_checked_in_registrations: 2, num_sessions: 0, num_speakers: 1 }; const layouts = [{ id: 'l1', event_id: eventId, name: 'Default', is_default: true, page_width_mm: 100, page_height_mm: 70, created_at: 'x', updated_at: 'x', elements: [{ id: 't1', type: 'text', x: 8, y: 8, width: 60, height: 12, rotation: 0, content: 'attendee_name', text: '', font: 'Open Sans', font_size: 14, line_height: 1.2, color: '#000', bold: false, italic: false, align_h: 'left', align_v: 'middle', transform: 'none' }] }]; async function openAdmin(page: Page, view: 'Contacts' | 'Registrations') { const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url'); const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'r', expires_in: 3600, token_type: 'bearer' }; await page.route('**/auth/v1/**', (r) => r.fulfill({ json: new URL(r.request().url()).pathname.endsWith('/user') ? user : session })); await page.route('**/rest/v1/**', (r) => { const u = new URL(r.request().url()); const t = u.pathname.split('/').pop(); if (t === 'contacts') return r.fulfill({ json: u.searchParams.has('email') ? contacts[0] : contacts }); if (t === 'registrations') return r.fulfill({ json: registrations }); if (t === 'badge_layouts') return r.fulfill({ json: layouts }); if (t === 'events') return r.fulfill({ json: u.searchParams.has('is_active') ? event : [event] }); return r.fulfill({ json: [] }); }); await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=r&type=magiclink`); await page.locator('.nav').getByRole('button', { name: new RegExp(view) }).click(); } // Open the portalled filter popover for a column header and pick an option. // (Checkbox names include the live count, e.g. "Yes 2", hence the \b regex.) async function pickFilter(page: Page, column: string, option: string) { await page.getByRole('button', { name: `Filter ${column}` }).click(); await page.getByRole('group', { name: `Filter ${column}` }).getByRole('checkbox', { name: new RegExp(`^${option}\\b`) }).check(); } const closePopover = (page: Page) => page.mouse.click(700, 860); test.describe('contacts column filters + search', () => { test.beforeEach(async ({ page }) => { await page.setViewportSize({ width: 1280, height: 900 }); await openAdmin(page, 'Contacts'); await expect(page.getByRole('row').filter({ hasText: 'jane.doe@example.com' })).toBeVisible(); }); test('search matches first name, last name and email', async ({ page }) => { await expect(page.locator('table.data tbody tr')).toHaveCount(5); await page.getByPlaceholder(/Search first name/).fill('jane'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); await expect(page.locator('table.data tbody tr')).toContainText('Jane Doe'); await page.getByPlaceholder(/Search first name/).fill('doe'); await expect(page.locator('table.data tbody tr')).toHaveCount(3); // Jane, John, Amy await page.getByPlaceholder(/Search first name/).fill('sam.roe@'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); await expect(page.locator('table.data tbody tr')).toContainText('Sam Roe'); }); test('LinkedIn filter narrows to rows with / without a profile', async ({ page }) => { await pickFilter(page, 'LinkedIn', 'Yes'); await expect(page.locator('table.data tbody tr')).toHaveCount(2); // Jane + Amy await page.getByRole('group', { name: 'Filter LinkedIn' }).getByRole('checkbox', { name: /^No\b/ }).check(); await expect(page.locator('table.data tbody tr')).toHaveCount(5); // Yes+No = all await closePopover(page); await page.getByRole('button', { name: 'Filter LinkedIn' }).click(); await page.getByRole('group', { name: 'Filter LinkedIn' }).getByRole('button', { name: 'Clear' }).click(); await closePopover(page); await expect(page.locator('table.data tbody tr')).toHaveCount(5); }); test('Admin filter shows only admins', async ({ page }) => { await pickFilter(page, 'Admin', 'Yes'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); await expect(page.locator('table.data tbody tr')).toContainText('Admin User'); }); test('Visibility filter matches the shown combination', async ({ page }) => { await pickFilter(page, 'Visibility', 'None shown'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); await expect(page.locator('table.data tbody tr')).toContainText('John Doe'); }); test('filters combine with the search bar', async ({ page }) => { await page.getByPlaceholder(/Search first name/).fill('doe'); await pickFilter(page, 'LinkedIn', 'Yes'); await expect(page.locator('table.data tbody tr')).toHaveCount(2); // Jane + Amy (not John) }); test('filter dropdown shows live counts and an active badge on the button', async ({ page }) => { await page.getByRole('button', { name: 'Filter LinkedIn' }).click(); const pop = page.getByRole('group', { name: 'Filter LinkedIn' }); await expect(pop.getByRole('checkbox', { name: /^Yes\b/ })).not.toBeChecked(); await expect(pop.locator('.cnt').first()).toHaveText('2'); await expect(pop.locator('.cnt').nth(1)).toHaveText('3'); await pop.getByRole('checkbox', { name: /^Yes\b/ }).check(); await closePopover(page); await expect(page.getByRole('button', { name: 'Filter LinkedIn' })).toContainText('1'); }); test('the popover escapes the table overflow (portalled to body)', async ({ page }) => { await page.getByRole('button', { name: 'Filter Visibility' }).click(); const pop = page.getByRole('group', { name: 'Filter Visibility' }); await expect(pop).toBeVisible(); await expect(pop.locator('xpath=ancestor::body')).toHaveCount(1); }); }); test.describe('registrations column filters + search', () => { test.beforeEach(async ({ page }) => { await page.setViewportSize({ width: 1280, height: 900 }); await openAdmin(page, 'Registrations'); await expect(page.getByRole('row').filter({ hasText: 'jane.doe@example.com' })).toBeVisible(); }); test('search matches name, email and type', async ({ page }) => { await expect(page.locator('table.data tbody tr')).toHaveCount(4); await page.getByPlaceholder(/Search first name/).fill('speaker'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); await expect(page.locator('table.data tbody tr')).toContainText('John Doe'); await page.getByPlaceholder(/Search first name/).fill('amy'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); }); test('Type filter narrows rows and supports multiple types', async ({ page }) => { await pickFilter(page, 'Type', 'attendee'); await expect(page.locator('table.data tbody tr')).toHaveCount(2); await page.getByRole('group', { name: 'Filter Type' }).getByRole('checkbox', { name: /^staff\b/ }).check(); await expect(page.locator('table.data tbody tr')).toHaveCount(3); }); test('Ticket filter separates rows with and without QR', async ({ page }) => { await pickFilter(page, 'Ticket', 'No'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); await expect(page.locator('table.data tbody tr')).toContainText('amy.doe@example.com'); }); test('Checked-in filter matches the toggle state', async ({ page }) => { await pickFilter(page, 'Checked in', 'Yes'); await expect(page.locator('table.data tbody tr')).toHaveCount(2); const body = page.locator('table.data tbody'); await expect(body).toContainText('jane.doe@example.com'); await expect(body).toContainText('sam.roe@example.com'); }); test('filters combine with each other and the search', async ({ page }) => { await pickFilter(page, 'Type', 'attendee'); await closePopover(page); await pickFilter(page, 'Checked in', 'Yes'); await expect(page.locator('table.data tbody tr')).toHaveCount(1); await expect(page.locator('table.data tbody tr')).toContainText('Jane Doe'); await closePopover(page); await page.getByPlaceholder(/Search first name/).fill('sam'); await expect(page.locator('table.data tbody tr')).toHaveCount(0); await expect(page.getByText('No registrations yet')).toBeVisible(); }); test('type counts reflect the other active filters (Excel-style)', async ({ page }) => { await pickFilter(page, 'Checked in', 'Yes'); await closePopover(page); await page.getByRole('button', { name: 'Filter Type' }).click(); const pop = page.getByRole('group', { name: 'Filter Type' }); // Only checked-in rows count: attendee 1, staff 1, speaker 0 (hidden). await expect(pop.getByRole('checkbox', { name: /^attendee\b/ })).toBeVisible(); await expect(pop.locator('.cnt').first()).toHaveText('1'); await expect(pop.getByRole('checkbox', { name: /^speaker\b/ })).toHaveCount(0); }); });