Files
Convivo/e2e/tests/tooltip-containment.spec.ts
T
Lago 184449adb6 fix(admin): clamp tooltips into the viewport
The portal kept cards out of table overflow but nothing kept them on screen:
centred on a fixed-width card, any trigger near an edge lost text -- reported
on Sessions' right-aligned Generate button. The shared Tooltip now measures the
card, clamps it to the viewport, flips below when there is no room above, and
keeps the arrow aimed at the trigger. No more CSS centreing transform, JS owns
the coordinates.

New tooltip-containment.spec.ts (4 tests) asserts the measured rectangle, no
document widening and arrow alignment at wide/narrow/short viewports; verified
it catches the bug by reverting the fix (3 of 4 fail). Full serial e2e: 211
passed, 0 failed.
2026-10-19 21:19:30 +02:00

146 lines
8.9 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: {} };
/**
* Tooltips are portal-rendered, which stops a table's `overflow` from clipping
* them — but nothing kept them inside the VIEWPORT. The card was centred on its
* trigger with a fixed width, so every tooltip attached to a right-aligned
* control (Sessions' "Generate AI Feedback Summary", Registrations' points
* explanation) ran off the right edge and its text was unreachable.
*
* These tests assert the measured rectangle of the rendered card, because
* "fully inside the viewport" is the whole requirement and only geometry can
* prove it.
*/
const sessionsEvent = {
id: eventId, name: 'Tooltip Conf', 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: 1, num_checked_in_registrations: 0,
num_sessions: 1, num_speakers: 1, avg_feedback: null, created_at: 'x',
};
const slot = { id: 's1', event_id: eventId, date: '2026-11-01', start_time: '10:15:00', end_time: '11:00:00', type: 'talk', title: null };
const session = { id: 't1', event_id: eventId, slot_id: 's1', title: 'A Talk With A Very Long Title Indeed', description: 'desc', room: 'Main Stage', level: '300', area: 'Power Apps', session_material: null, is_service_session: false, external_id: 'x' };
const speakerContact = { email: '[email protected]', full_name: 'Ann Speaker', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' };
async function openAdmin(page: Page, view: 'Sessions' | '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' };
const contacts = [
{ email: user.email, full_name: 'Admin User', linkedin_url: null, show_email: true, show_linkedin: true, is_admin: true, created_at: 'x' },
speakerContact,
];
// `maybeSingle()` in the auth path expects an OBJECT for the ?email=eq.… lookup;
// answering that with an array makes the admin check fail and the app falls back
// to the login screen, which looks like a broken tooltip rather than a bad mock.
const contactsFor = (u: URL) => (u.searchParams.has('email')
? contacts.find((c) => c.email === decodeURIComponent((u.searchParams.get('email') || '').replace(/^eq./, ''))) ?? null
: contacts);
const registrations = [
{ 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: 'staff', qr_token: 'CV-B', external_id: null, import_source: null, checked_in: false, points: 0, created_at: 'x' },
];
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();
if (t === 'contacts') return route.fulfill({ json: contactsFor(u) });
if (t === 'events') return route.fulfill({ json: new URL(route.request().url()).searchParams.has('is_active') ? sessionsEvent : [sessionsEvent] });
if (t === 'slots') return route.fulfill({ json: [slot] });
if (t === 'sessions') return route.fulfill({ json: [session] });
if (t === 'session_speakers') return route.fulfill({ json: [{ session_id: 't1', contact_email: '[email protected]' }] });
if (t === 'checkins') return route.fulfill({ json: [] });
if (t === 'feedback') return route.fulfill({ json: [{ session_id: 't1', rating: 5, comment: 'great', created_at: 'x' }] });
if (t === 'feedback_summaries') return route.fulfill({ json: [] });
if (t === 'registrations') return route.fulfill({ json: registrations });
if (t === 'badge_layouts') return route.fulfill({ json: [] });
return route.fulfill({ json: [] });
});
await page.route('**/sidecar/llm-settings', (r) => r.fulfill({ json: { endpoint: 'https://x.test', model: 'M', has_api_key: true } }));
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();
}
/** The card must be wholly inside the viewport, with its arrow over the trigger. */
async function expectCardInsideViewport(page: Page, trigger: ReturnType<Page['locator']>) {
const card = page.locator('.tip-card');
await expect(card).toBeVisible();
const box = await card.boundingBox();
const vp = page.viewportSize()!;
expect(box, 'the tooltip card rendered').not.toBeNull();
const b = box!;
expect(b.x, 'card left edge is on screen').toBeGreaterThanOrEqual(0);
expect(b.y, 'card top edge is on screen').toBeGreaterThanOrEqual(0);
expect(b.x + b.width, 'card right edge is on screen').toBeLessThanOrEqual(vp.width);
expect(b.y + b.height, 'card bottom edge is on screen').toBeLessThanOrEqual(vp.height);
// No horizontal page overflow caused by the card.
const doc = await page.evaluate(() => ({ sw: document.documentElement.scrollWidth, cw: document.documentElement.clientWidth }));
expect(doc.sw, 'the card must not widen the document').toBeLessThanOrEqual(doc.cw);
// The arrow must still sit over the card (it tracks the trigger, which may be
// far from the card's centre once the card is pushed sideways).
const arrow = await card.locator('.tip-arrow').boundingBox();
expect(arrow).not.toBeNull();
expect(arrow!.x, 'arrow stays inside the card').toBeGreaterThanOrEqual(b.x);
expect(arrow!.x + arrow!.width, 'arrow stays inside the card').toBeLessThanOrEqual(b.x + b.width);
// And it must not have drifted away from the control it explains.
const tb = await trigger.boundingBox();
const triggerCentre = tb!.x + tb!.width / 2;
expect(Math.abs(arrow!.x + arrow!.width / 2 - triggerCentre), 'arrow points at the trigger').toBeLessThanOrEqual(Math.max(tb!.width / 2, 24));
}
test.describe('Tooltip viewport containment', () => {
test('a right-aligned trigger keeps its tooltip fully on screen', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 800 });
await openAdmin(page, 'Sessions');
const btn = page.getByTestId('generate-all-summaries');
await expect(btn).toBeVisible();
const box = await btn.boundingBox();
// Precondition that makes this test meaningful: the control really is against
// the right edge, which is what used to push the card off screen.
expect(box!.x + box!.width).toBeGreaterThan(1280 - 250);
await btn.hover();
await expectCardInsideViewport(page, btn);
// The point of a tooltip: the explanation is readable.
await expect(page.locator('.tip-card')).toContainText(/one per session that has feedback/i);
});
test('a narrow viewport does not clip it either', async ({ page }) => {
await page.setViewportSize({ width: 700, height: 800 });
await openAdmin(page, 'Sessions');
const btn = page.getByTestId('generate-all-summaries');
await btn.hover();
await expectCardInsideViewport(page, btn);
});
test('a trigger near the top flips the card below instead of off the top', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 260 });
await openAdmin(page, 'Sessions');
const btn = page.getByTestId('generate-all-summaries');
await expect(btn).toBeVisible();
const tb = await btn.boundingBox();
// Short viewport: there is genuinely not room for the card above the button.
expect(tb!.y).toBeLessThan(200);
await btn.hover();
await expectCardInsideViewport(page, btn);
const after = await btn.boundingBox();
const card = await page.locator('.tip-card').boundingBox();
expect(card!.y, 'card sits below the trigger').toBeGreaterThanOrEqual(after!.y + after!.height - 1);
});
test('the Registrations points tooltip is contained too', async ({ page }) => {
await page.setViewportSize({ width: 1100, height: 800 });
await openAdmin(page, 'Registrations');
const mark = page.getByTestId('points-exempt-r2');
await expect(mark).toBeVisible();
await mark.hover();
await expectCardInsideViewport(page, mark);
await expect(page.locator('.tip-card')).toContainText(/not eligible|staff/i);
});
});