Registrations table felt buggy because both row actions did setBusy(true) -> write -> reloadRegistrations() -> setBusy(false): the list is sorted by points, so a reload made the row you just touched jump (or vanish under a Checked-in filter), and the single `busy` flag disabled every control in the table for the whole request. The fix is per-row in-flight state (busyIds + withRowBusy) and no reload at all: the toggle patches its own row's checked_in plus the points delta the RPC returns, the type change patches `type`; a rejected write rolls both back. Only the touched row is disabled, shows a "Saving…" pulse, and two rows can save at once. Toggle hit area is now 40x41 px with a focus-visible ring. Front-desk gate: checkin_attendee reads registrations.checked_in and raises "This attendee needs to be checked in at the front desk first." when it is not true, and no longer sets checked_in as a side effect. checkins has no INSERT policy, so the RPC is the only write path and the gate cannot be bypassed. The scanner shows a dedicated "Not checked in yet" sheet instead of a toast. Badge copies: events.badge_copies (1..4, default 1). welcome_checkin sends that many pgmq jobs in one transaction (the Pi prints one label per job, so N jobs = N labels; no worker change) and clamps the value again itself. preview_welcome_checkin gained a `copies` column (drop + recreate) so the popup states the real count. Manual reprint still prints exactly one. Set from Settings -> Badge printing (active event) and the Events form, always as a single-column update; the Settings badge section now renders even when the LLM settings call fails. Tests: badge_print 113 (+6), leaderboard 47 (+1), new registration-checkin-toggle (6), front-desk-gate (3), welcome-badge-copies (3); the stale registrations-PATCH mock in registration-ticket-merge now targets set_registration_checked_in, the ambiguous Save button is "Save copies", and the print-copy assertion tolerates the typographic apostrophe. Docs updated (rpcs, schema, printing, tests, admin-app, screens) with a release record; NOT deployed - see docs/releases/2026-10-19.md. 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]>
211 lines
12 KiB
TypeScript
211 lines
12 KiB
TypeScript
import { test, expect, type Page, type Route } 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: {} };
|
||
|
||
/**
|
||
* The check-in toggle must feel instant and stay put. The regression this
|
||
* guards: the handler used to set a GLOBAL busy flag and reload the whole
|
||
* registration list after every toggle. Because the table is sorted by points,
|
||
* the reload moved the row you had just touched somewhere else, a column filter
|
||
* could make it vanish, and every control in the table went dead mid-request.
|
||
*/
|
||
|
||
type Reg = {
|
||
id: string; event_id: string; contact_email: string; type: string; qr_token: string | null;
|
||
external_id: null; import_source: null; checked_in: boolean; points: number; created_at: string;
|
||
};
|
||
|
||
const mkRegs = (): Reg[] => [
|
||
{ id: 'r1', event_id: eventId, contact_email: '[email protected]', type: 'attendee', qr_token: 'CV-A', external_id: null, import_source: null, checked_in: false, points: 40, created_at: 'x' },
|
||
{ id: 'r2', event_id: eventId, contact_email: '[email protected]', type: 'attendee', qr_token: 'CV-B', external_id: null, import_source: null, checked_in: false, points: 30, created_at: 'x' },
|
||
{ id: 'r3', event_id: eventId, contact_email: '[email protected]', type: 'speaker', qr_token: 'CV-C', external_id: null, import_source: null, checked_in: false, points: 20, created_at: 'x' },
|
||
{ id: 'r4', event_id: eventId, contact_email: '[email protected]', type: 'staff', qr_token: 'CV-D', external_id: null, import_source: null, checked_in: false, points: 10, created_at: 'x' },
|
||
];
|
||
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: 'Ann A', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||
{ email: '[email protected]', full_name: 'Bob B', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||
{ email: '[email protected]', full_name: 'Cid C', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||
{ email: '[email protected]', full_name: 'Dee D', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||
];
|
||
const event = {
|
||
id: eventId, name: 'Toggle Conference', company: 'APPE', is_active: true, location: null,
|
||
start_date: '2026-11-01', end_date: '2026-11-01', use_realtime_clock: false, sessionize_endpoint: null,
|
||
pretix_organizer: null, pretix_event_slug: null, pretix_api_key: null, last_synced_at: null,
|
||
talk_networking_bonus: 2, badge_copies: 1, num_registrations: 4, num_checked_in_registrations: 0,
|
||
num_sessions: 0, num_speakers: 1, avg_feedback: null, created_at: 'x',
|
||
};
|
||
|
||
/** Mutable per-test fixtures so a handler can observe its own writes. */
|
||
type Harness = { regs: Reg[]; registrationFetches: number; setCheckedInDelayMs: number };
|
||
|
||
async function openAdmin(page: Page, view: 'Registrations' | 'Settings', h: Harness) {
|
||
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/**', async (route: Route) => {
|
||
const u = new URL(route.request().url());
|
||
const t = u.pathname.split('/').pop();
|
||
const method = route.request().method();
|
||
if (t === 'contacts') return route.fulfill({ json: u.searchParams.has('email') ? contacts[0] : contacts });
|
||
if (t === 'registrations' && method === 'GET') { h.registrationFetches++; return route.fulfill({ json: h.regs }); }
|
||
if (t === 'badge_layouts') return route.fulfill({ json: [] });
|
||
if (t === 'events') {
|
||
if (method === 'PATCH') {
|
||
const patch = JSON.parse(route.request().postData() || '{}') as Record<string, unknown>;
|
||
Object.assign(event, patch);
|
||
return route.fulfill({ status: 204, json: {} });
|
||
}
|
||
return route.fulfill({ json: u.searchParams.has('is_active') ? event : [event] });
|
||
}
|
||
if (t === 'rpc' || u.pathname.includes('/rpc/')) return route.fulfill({ json: [] });
|
||
return route.fulfill({ json: [] });
|
||
});
|
||
// PostgREST RPC urls end with the function name, so the check-in write is
|
||
// matched here (registered after, so it wins over the catch-all above).
|
||
await page.route('**/rpc/set_registration_checked_in*', async (route: Route) => {
|
||
if (h.setCheckedInDelayMs) await new Promise((r) => setTimeout(r, h.setCheckedInDelayMs));
|
||
const body = JSON.parse(route.request().postData() || '{}') as { p_registration_id: string; p_checked_in: boolean };
|
||
const row = h.regs.find((x) => x.id === body.p_registration_id);
|
||
const removed = row && !body.p_checked_in ? row.points : 0;
|
||
if (row) { row.checked_in = body.p_checked_in; if (!body.p_checked_in) row.points = 0; }
|
||
return route.fulfill({ json: [{ registration_id: body.p_registration_id, checked_in: body.p_checked_in, points_removed: removed }] });
|
||
});
|
||
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=r&type=magiclink`);
|
||
await expect(page.locator('.nav')).toBeVisible();
|
||
await page.locator('.nav').getByRole('button', { name: new RegExp(view) }).click();
|
||
}
|
||
|
||
const rows = (page: Page) => page.locator('table.data tbody tr');
|
||
const order = (page: Page) => rows(page).locator('.cell-person .n').allTextContents();
|
||
const rowToggle = (page: Page, rowText: string) =>
|
||
rows(page).filter({ hasText: rowText }).first().locator('.toggle .track');
|
||
|
||
test.describe('Registrations check-in toggle', () => {
|
||
test.beforeEach(async ({ page }) => {
|
||
await page.setViewportSize({ width: 1280, height: 900 });
|
||
});
|
||
|
||
test('toggling does not refetch the list, so rows keep their order', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||
await openAdmin(page, 'Registrations', h);
|
||
await expect(rows(page)).toHaveCount(4);
|
||
const before = await order(page);
|
||
const fetchesAfterLoad = h.registrationFetches;
|
||
|
||
await rowToggle(page, 'Ann A').click();
|
||
await expect(page.getByText(/Ann A: checked in/)).toBeVisible();
|
||
|
||
// The whole point: no list reload, therefore no re-sort and no jumping row.
|
||
expect(h.registrationFetches, 'the toggle must not refetch registrations').toBe(fetchesAfterLoad);
|
||
expect(await order(page)).toEqual(before);
|
||
// The row still shows the new state.
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
|
||
});
|
||
|
||
test('only the toggled row is busy; the rest of the table stays usable', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 1500 };
|
||
await openAdmin(page, 'Registrations', h);
|
||
await expect(rows(page)).toHaveCount(4);
|
||
|
||
await rowToggle(page, 'Ann A').click();
|
||
|
||
// In flight: the touched row says so and its controls pause.
|
||
const busyRow = rows(page).filter({ hasText: 'Ann A' }).first();
|
||
await expect(busyRow.getByTestId('saving-r1')).toBeVisible();
|
||
await expect(busyRow.locator('input[type=checkbox]')).toBeDisabled();
|
||
// Optimistic value is already shown, so the click feels instant.
|
||
await expect(busyRow.locator('input[type=checkbox]')).toBeChecked();
|
||
|
||
// Other rows are untouched — not disabled, no busy marker.
|
||
const otherRow = rows(page).filter({ hasText: 'Bob B' }).first();
|
||
await expect(otherRow.locator('input[type=checkbox]')).toBeEnabled();
|
||
await expect(otherRow.locator('.row-saving')).toHaveCount(0);
|
||
await expect(otherRow.locator('select')).toBeEnabled();
|
||
// The event selector is not frozen either.
|
||
await expect(page.locator('select.input').first()).toBeEnabled();
|
||
|
||
// And a second row can be toggled while the first one is still saving.
|
||
await rowToggle(page, 'Cid C').click();
|
||
await expect(rows(page).filter({ hasText: 'Cid C' }).getByTestId('saving-r3')).toBeVisible();
|
||
|
||
await expect(page.locator('.row-saving')).toHaveCount(0, { timeout: 10_000 });
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
|
||
await expect(rows(page).filter({ hasText: 'Cid C' }).locator('input[type=checkbox]')).toBeChecked();
|
||
});
|
||
|
||
test('un-checking removes the check-in points on that row', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||
h.regs[1].checked_in = true; // Bob already checked in with 30 pts
|
||
await openAdmin(page, 'Registrations', h);
|
||
await expect(rows(page).filter({ hasText: 'Bob B' })).toContainText('30');
|
||
|
||
await rowToggle(page, 'Bob B').click();
|
||
await expect(page.getByText(/un-checked in, −30/)).toBeVisible();
|
||
await expect(rows(page).filter({ hasText: 'Bob B' })).toContainText('0');
|
||
await expect(rows(page).filter({ hasText: 'Bob B' }).locator('input[type=checkbox]')).not.toBeChecked();
|
||
});
|
||
|
||
test('a rejected toggle rolls the checkbox back', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||
await openAdmin(page, 'Registrations', h);
|
||
// Make the backend refuse the write.
|
||
await page.unroute('**/rpc/set_registration_checked_in*');
|
||
await page.route('**/rpc/set_registration_checked_in*', (route) =>
|
||
route.fulfill({ status: 400, json: { message: 'This attendee needs to be checked in at the front desk first.' } }));
|
||
|
||
await rowToggle(page, 'Ann A').click();
|
||
await expect(page.getByText(/front desk/)).toBeVisible();
|
||
// The optimistic flip must not survive a failed write.
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).not.toBeChecked();
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('.row-saving')).toHaveCount(0);
|
||
});
|
||
|
||
test('changing the pass type does not refetch or reorder the table', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||
await openAdmin(page, 'Registrations', h);
|
||
await page.route('**/rpc/set_registration_type*', (route) =>
|
||
route.fulfill({ json: { ...h.regs[0], type: 'sponsor' } }));
|
||
await expect(rows(page)).toHaveCount(4);
|
||
const before = await order(page);
|
||
const fetches = h.registrationFetches;
|
||
|
||
await rows(page).filter({ hasText: 'Ann A' }).first().locator('select').selectOption('staff');
|
||
await expect(page.getByText(/Ann A → staff/)).toBeVisible();
|
||
|
||
expect(h.registrationFetches).toBe(fetches);
|
||
expect(await order(page)).toEqual(before);
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).first().locator('select')).toHaveValue('staff');
|
||
});
|
||
});
|
||
|
||
test.describe('Settings — badge copies', () => {
|
||
test.beforeEach(async ({ page }) => {
|
||
await page.setViewportSize({ width: 1280, height: 900 });
|
||
});
|
||
|
||
test('the active event controls how many labels a welcome check-in prints', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||
await openAdmin(page, 'Settings', h);
|
||
const section = page.getByTestId('settings-badge-printing');
|
||
await expect(section).toBeVisible();
|
||
const picker = section.getByTestId('badge-copies');
|
||
|
||
// Default 1, and exactly four choices (1..4) — no free-text to mistype.
|
||
await expect(picker.getByRole('button')).toHaveCount(4);
|
||
await expect(picker.locator('button.active')).toHaveText('1');
|
||
|
||
await picker.getByRole('button', { name: '3', exact: true }).click();
|
||
await expect(section.getByTestId('badge-copies-save')).toBeEnabled();
|
||
await section.getByTestId('badge-copies-save').click();
|
||
await expect(section.getByTestId('badge-copies-save')).toHaveText('Copies saved');
|
||
// Persisted on the event.
|
||
expect(event.badge_copies).toBe(3);
|
||
|
||
// Save is disabled when there is nothing to save.
|
||
await expect(section.getByTestId('badge-copies-save')).toBeDisabled();
|
||
});
|
||
});
|