feat(admin): per-row badge preview with unconfigured tooltip, Excel-style column filters and search in Contacts/Registrations

- New shared BadgeRender module (resolveText/resolveQr/BadgeElementBody/BadgePagePreview/fitScale) reused by the badge editor and the new read-only preview modal
- Registrations: Badge button on every row opens a live preview of that attendee's badge; grayed out with a Uiverse-style APPE-red tooltip when the event has no badge configured
- Contacts + Registrations: per-column multi-select filters (LinkedIn/Visibility/Admin; Type/Ticket/Checked in) with Excel-style live counts, plus general search (contacts: first/last/email; registrations: +type)
- New Tooltip and ColumnFilter primitives in ui.tsx (portal-based, escape/outside-click close)
- e2e: registration-badge-preview.spec.ts (13) + table-filters.spec.ts (13), all green; docs synced
This commit is contained in:
Lago committed 2026-10-16 08:53:46 +02:00
1 parent 6b277a2a67
commit 3d4dc207ff
10 files changed
+988 -121

No files matched your search

@@ -0,0 +1,214 @@
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: '[email protected]', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} };
const jane = { id: '11111111-1111-4111-8111-111111111111', event_id: eventId, contact_email: '[email protected]', type: 'attendee', qr_token: 'CV-JANE-01', external_id: null, import_source: null, checked_in: false, points: 0 };
const sam = { id: '22222222-2222-4222-8222-222222222222', event_id: eventId, contact_email: '[email protected]', type: 'speaker', qr_token: 'CV-SAM-02', external_id: null, import_source: null, checked_in: true, points: 12 };
function layout(name: string, isDefault: boolean, elements: Record<string, unknown>[]) {
return {
id: `l-${name.toLowerCase()}`, event_id: eventId, name, is_default: isDefault,
page_width_mm: 100, page_height_mm: 70, created_at: '2026-10-23T10:00:00Z', updated_at: '2026-10-23T10:00:00Z', elements,
};
}
const textEl = (id: string, content: string, extra: Record<string, unknown> = {}) => ({
id, type: 'text', x: 8, y: 8, width: 60, height: 12, rotation: 0, content, text: 'fallback',
font: 'Open Sans', font_size: 14, line_height: 1.2, color: '#000000', bold: false, italic: false,
align_h: 'left', align_v: 'middle', transform: 'none', ...extra,
});
const qrEl = (id: string, value: string) => ({ id, type: 'qr', x: 70, y: 40, width: 24, height: 24, rotation: 0, value, static_value: '' });
interface Options { layouts?: Record<string, unknown>[]; failLayouts?: boolean; }
async function openRegistrations(page: Page, options: Options = {}) {
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: 'mock-refresh-token', expires_in: 3600, token_type: 'bearer' };
const event = { id: eventId, name: 'Badge Conference', company: 'Austrian Power Platform Enthusiasts', is_active: true, start_date: '2026-10-23', end_date: '2026-10-23', num_registrations: 2, num_checked_in_registrations: 1, num_sessions: 0, num_speakers: 1 };
const contacts = [
{ email: user.email, full_name: 'Admin', is_admin: true },
{ email: '[email protected]', full_name: 'Jane Attendee', is_admin: false },
{ email: '[email protected]', full_name: 'Sam Speaker', is_admin: false },
];
const layouts = options.layouts ?? [
layout('Default', true, [textEl('t-name', 'attendee_name'), textEl('t-type', 'ticket_type', { y: 24 }), textEl('t-company', 'company', { y: 40 }), qrEl('q1', 'qr_token')]),
layout('Compact', false, [textEl('c-name', 'full_name'), qrEl('cq', 'checkin_url')]),
];
let layoutRequests = 0;
await page.route('**/auth/v1/**', (route) => route.fulfill({ json: new URL(route.request().url()).pathname.endsWith('/user') ? user : session }));
await page.route('**/rest/v1/**', (route) => {
const url = new URL(route.request().url());
const table = url.pathname.split('/').pop();
if (table === 'badge_layouts') {
layoutRequests += 1;
if (options.failLayouts) return route.fulfill({ status: 500, json: { message: 'layouts unavailable' } });
return route.fulfill({ json: layouts });
}
if (table === 'registrations') return route.fulfill({ json: [jane, sam] });
if (table === 'contacts') return route.fulfill({ json: url.searchParams.has('email') ? contacts[0] : contacts });
if (table === 'events') return route.fulfill({ json: url.searchParams.has('is_active') ? event : [event] });
return route.fulfill({ json: [] });
});
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
// The nav only renders once auth resolves; "Sign out" is hidden on mobile widths.
const registrationsNav = page.locator('.nav').getByRole('button', { name: /Registrations/ });
await expect(registrationsNav).toBeVisible();
await registrationsNav.click();
await expect(page.getByRole('row').filter({ hasText: '[email protected]' })).toBeVisible();
return { layoutRequestCount: () => layoutRequests };
}
const row = (page: Page, email: string) => page.getByRole('row').filter({ hasText: email });
test('every registration row offers a Badge preview button', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page);
await expect(row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true })).toBeVisible();
await expect(row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true })).toBeVisible();
});
test('the badge preview renders the attendee data on the default layout', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page);
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
const dialog = page.getByRole('dialog', { name: 'Badge — Jane Attendee' });
await expect(dialog).toBeVisible();
const stage = dialog.locator('.badge-preview-stage');
await expect(stage).toBeVisible();
// Bound fields resolve against THIS attendee, not the editor's demo sample.
await expect(stage).toContainText('Jane Attendee');
await expect(stage).toContainText('attendee');
await expect(stage).toContainText('Austrian Power Platform Enthusiasts');
// The QR element renders an actual SVG code.
await expect(stage.locator('.badge-qr-body svg')).toHaveCount(1);
await expect(dialog.getByText('Default · 100 × 70 mm')).toBeVisible();
await page.screenshot({ path: testInfo.outputPath('badge-preview-jane.png'), fullPage: true });
});
test('the preview is per-attendee: a different row shows different data', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page);
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
const stage = page.getByRole('dialog', { name: 'Badge — Sam Speaker' }).locator('.badge-preview-stage');
await expect(stage).toContainText('Sam Speaker');
await expect(stage).toContainText('speaker');
await expect(stage).not.toContainText('Jane Attendee');
});
test('layouts can be switched inside the preview', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page);
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
const dialog = page.getByRole('dialog', { name: 'Badge — Jane Attendee' });
await expect(dialog.getByLabel('Layout')).toHaveValue('Default');
await dialog.getByLabel('Layout').selectOption('Compact');
await expect(dialog.getByText('Compact · 100 × 70 mm')).toBeVisible();
// Compact has no company element, so the organizer text disappears.
await expect(dialog.locator('.badge-preview-stage')).not.toContainText('Austrian Power Platform Enthusiasts');
});
test('a single layout hides the layout picker', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page, { layouts: [layout('Default', true, [textEl('t-name', 'attendee_name')])] });
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
const dialog = page.getByRole('dialog', { name: 'Badge — Jane Attendee' });
await expect(dialog.locator('.badge-preview-stage')).toContainText('Jane Attendee');
await expect(dialog.getByLabel('Layout')).toHaveCount(0);
});
test('with no layout configured, the Badge button is shown but disabled', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page, { layouts: [] });
const badge = row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true });
await expect(badge).toBeVisible();
await expect(badge).toBeDisabled();
// Clicking the disabled button opens nothing.
await badge.click({ force: true });
await expect(page.getByRole('dialog', { name: 'Badge — Jane Attendee' })).toHaveCount(0);
});
test('an empty layout (blank white badge) also disables the Badge button', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page, { layouts: [layout('Default', true, [])] });
const badge = row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true });
await expect(badge).toBeVisible();
await expect(badge).toBeDisabled();
});
test('hovering a disabled Badge button reveals the configure-first tooltip', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page, { layouts: [] });
const badge = row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true });
await expect(badge).toBeDisabled();
// The card is not in the DOM until hover (it is portalled to <body>).
await expect(page.getByRole('tooltip')).toHaveCount(0);
// The wrapper carries the hover, since the disabled button is hit-test-transparent.
await badge.locator('xpath=ancestor::span[contains(@class,"tip-anchor")]').hover();
const tip = page.getByRole('tooltip');
await expect(tip).toBeVisible();
await expect(tip).toContainText('No badge yet');
await expect(tip).toContainText('A badge needs to be configured for this event first. Design one in the Badges view.');
// It renders on document.body, so the table's overflow never clips it.
await expect(tip.locator('xpath=ancestor::body')).toHaveCount(1);
await page.mouse.move(5, 5);
await expect(page.getByRole('tooltip')).toHaveCount(0);
});
test('a configured Badge button has no tooltip and stays clickable', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page);
const badge = row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true });
await expect(badge).toBeEnabled();
await badge.hover();
await expect(page.getByRole('tooltip')).toHaveCount(0);
});
test('a failed layout load leaves the buttons disabled without breaking the list', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page, { failLayouts: true });
// The registrations table still renders normally.
await expect(row(page, '[email protected]')).toBeVisible();
await expect(row(page, '[email protected]')).toBeVisible();
await expect(row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true })).toBeDisabled();
});
test('layouts load once for the list, not per preview', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
const state = await openRegistrations(page);
// StrictMode double-invokes effects in dev, so the list load may fetch twice.
const afterLoad = state.layoutRequestCount();
expect(afterLoad).toBeGreaterThanOrEqual(1);
expect(afterLoad).toBeLessThanOrEqual(2);
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
await expect(page.getByRole('dialog', { name: 'Badge — Jane Attendee' })).toBeVisible();
// Opening the modal reuses the already-loaded layouts — no extra request.
expect(state.layoutRequestCount()).toBe(afterLoad);
});
test('the preview closes via Done and the backdrop', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 });
await openRegistrations(page);
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
const dialog = page.getByRole('dialog', { name: 'Badge — Jane Attendee' });
await dialog.getByRole('button', { name: 'Done' }).click();
await expect(dialog).toHaveCount(0);
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
await expect(page.getByRole('dialog', { name: 'Badge — Sam Speaker' })).toBeVisible();
await page.mouse.click(10, 10); // backdrop
await expect(page.getByRole('dialog', { name: 'Badge — Sam Speaker' })).toHaveCount(0);
});
test('the badge preview fits a mobile viewport', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await openRegistrations(page);
await row(page, '[email protected]').getByRole('button', { name: 'Badge', exact: true }).click();
const dialog = page.getByRole('dialog', { name: 'Badge — Jane Attendee' });
await expect(dialog.locator('.badge-preview-stage')).toContainText('Jane Attendee');
const box = await dialog.locator('.badge-page').boundingBox();
expect(box).not.toBeNull();
expect(box!.width).toBeLessThanOrEqual(390);
});
+175
View File
@@ -0,0 +1,175 @@
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: '[email protected]', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} };
const contacts = [
{ email: '[email protected]', full_name: 'Admin User', linkedin_url: null, show_email: true, show_linkedin: true, is_admin: true, created_at: 'x' },
{ email: '[email protected]', full_name: 'Jane Doe', linkedin_url: 'https://linkedin.com/in/janedoe', show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
{ email: '[email protected]', full_name: 'John Doe', linkedin_url: null, show_email: false, show_linkedin: false, is_admin: false, created_at: 'x' },
{ email: '[email protected]', full_name: 'Amy Doe', linkedin_url: 'https://linkedin.com/in/amydoe', show_email: true, show_linkedin: true, is_admin: false, created_at: 'x' },
{ email: '[email protected]', 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: '[email protected]', 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: '[email protected]', 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: '[email protected]', type: 'attendee', qr_token: null, external_id: null, import_source: 'sessionize', checked_in: false, points: 0 },
{ id: 'r4', event_id: eventId, contact_email: '[email protected]', 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: '[email protected]' })).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: '[email protected]' })).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('[email protected]');
});
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('[email protected]');
await expect(body).toContainText('[email protected]');
});
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);
});
});