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 Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
30ed4388c0
commit
8e38052f4c
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);
|
||||
});
|
||||
Reference in new issue
Block a user