Files
Convivo/e2e/tests/sessions-view.spec.ts
T
45ab567355 feat(admin): material column + inline material manager in the Sessions view
- Sessions table gains a Material column (uploaded pill with the clean
  filename in its tooltip, dash when none)
- Expanded session row: shared MaterialPanel (open / download / delete
  with confirm) plus immediate upload/replace via MaterialUploadRow
- Schedule session modal refactored onto the same MaterialPanel; its
  upload keeps the uploads-on-Save behavior
- sessions-view e2e: new test pins the pill, panel buttons, clean
  filename, unlock hint and replace control

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]>
2026-10-21 21:30:31 +02:00

275 lines
17 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 Sessions view: per-session speakers and attendance, an attendee filter
* that answers "which sessions did this person go to?", and one button that
* summarises every session with feedback — blocking the page until all the
* requests have settled, then storing each result.
*/
type Summary = {
scope: string; target_id: string; event_id: string; session_id: string | null; summary: string;
response_count: number; source_fingerprint: string; model: string; generated_at: string;
};
type Harness = {
/** session ids that have at least one feedback row */
feedbackSessions: string[];
/** session ids that already have a stored summary */
stored: string[];
/** per-request artificial latency, so the overlay can be observed mid-run */
summaryDelayMs: number;
failFor: string[];
/** filled in by the route as requests arrive */
summaryRequests: string[];
};
const mkSessions = () => [
{ id: 's1', event_id: eventId, slot_id: 1, title: 'Opening Keynote', description: 'Why we are here.', room: 'Hall A', capacity: 200, level: 'all', area: 'keynote', average_feedback: null, ai_generated_feedback: null, material_path: 'sessions/s1/1730000000000-keynote.pdf', created_at: 'x' },
{ id: 's2', event_id: eventId, slot_id: 1, title: 'Power Apps Deep Dive', description: null, room: 'Room 2', capacity: 40, level: '200', area: 'power apps', average_feedback: null, ai_generated_feedback: null, material_path: null, created_at: 'x' },
{ id: 's3', event_id: eventId, slot_id: 2, title: 'Copilot Workshop', description: null, room: 'Room 3', capacity: null, level: null, area: null, average_feedback: null, ai_generated_feedback: null, material_path: null, created_at: 'x' },
];
const slots = [
{ id: 1, event_id: eventId, type: 'session', name: 'Morning', slot_date: '2026-11-01', start_time: '09:00:00', end_time: '10:00:00' },
{ id: 2, event_id: eventId, type: 'session', name: 'Afternoon', slot_date: '2026-11-01', start_time: '13:00:00', end_time: '14:00:00' },
];
const contacts = [
{ email: '[email protected]', full_name: 'Admin User', is_admin: true },
{ email: '[email protected]', full_name: 'Ann Example', is_admin: false },
{ email: '[email protected]', full_name: 'Bob Other', is_admin: false },
{ email: '[email protected]', full_name: 'Ann Speaker', is_admin: false },
];
/** session_speakers is returned for the embedded-filter shape the view uses. */
const speakers = [
{ session_id: 's1', contact_email: '[email protected]' },
{ session_id: 's2', contact_email: '[email protected]' },
];
const checkins = [
{ id: 'c1', event_id: eventId, session_id: 's1', contact_email: '[email protected]', staff_email: '[email protected]', created_at: '2026-11-01T09:01:00Z' },
{ id: 'c2', event_id: eventId, session_id: 's1', contact_email: '[email protected]', staff_email: '[email protected]', created_at: '2026-11-01T09:02:00Z' },
{ id: 'c3', event_id: eventId, session_id: 's2', contact_email: '[email protected]', staff_email: '[email protected]', created_at: '2026-11-01T09:31:00Z' },
];
async function openAdmin(page: Page, h: Harness, opts: { configured?: boolean } = {}) {
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 event = { id: eventId, name: 'Session Conference', is_active: true, start_date: '2026-11-01', end_date: '2026-11-01', badge_copies: 1 };
const settings = { endpoint: opts.configured === false ? '' : 'https://llm.example/v1/chat/completions', model: opts.configured === false ? '' : 'test-model', has_api_key: true, updated_at: null };
const summaries: Summary[] = h.stored.map((id) => ({
scope: 'session', target_id: id, event_id: eventId, session_id: id, summary: `Stored summary for ${id}`,
response_count: 1, source_fingerprint: 'old', model: 'old-model', generated_at: '2026-11-01T18:00:00Z',
}));
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: u.searchParams.has('email') ? contacts[0] : contacts });
if (t === 'events') return route.fulfill({ json: u.searchParams.has('is_active') ? event : [event] });
if (t === 'sessions') return route.fulfill({ json: mkSessions() });
if (t === 'slots') return route.fulfill({ json: slots });
if (t === 'session_speakers') return route.fulfill({ json: speakers.map((s) => ({ ...s, sessions: { event_id: eventId } })) });
if (t === 'checkins') return route.fulfill({ json: checkins });
if (t === 'feedback') {
const rows = h.feedbackSessions.flatMap((id) => [
{ id: `f-${id}-1`, event_id: eventId, session_id: id, contact_email: '[email protected]', rating: 5, comment: 'Great.', created_at: '2026-11-01T17:00:00Z' },
{ id: `f-${id}-2`, event_id: eventId, session_id: id, contact_email: '[email protected]', rating: 4, comment: 'Good.', created_at: '2026-11-01T17:05:00Z' },
]);
return route.fulfill({ json: rows });
}
if (t === 'event_feedback' || t === 'points_log' || t === 'registrations' || t === 'leaderboard') return route.fulfill({ json: [] });
if (t === 'feedback_summaries') return route.fulfill({ json: summaries });
return route.fulfill({ json: [] });
});
await page.route('**/sidecar/llm-settings', (route) => route.fulfill({ json: settings }));
await page.route('**/sidecar/feedback-summary', async (route: Route) => {
expect(route.request().headers().authorization).toBe(`Bearer ${session.access_token}`);
const body = route.request().postDataJSON() as { scope: string; session_id?: string };
const id = body.session_id ?? '';
h.summaryRequests.push(id);
if (h.summaryDelayMs) await new Promise((r) => setTimeout(r, h.summaryDelayMs));
if (h.failFor.includes(id)) return route.fulfill({ status: 502, json: { error: 'LLM endpoint returned HTTP 503' } });
const summary: Summary = {
scope: 'session', target_id: id, event_id: eventId, session_id: id,
summary: `Generated summary for ${id}`, response_count: 2, source_fingerprint: 'new', model: 'test-model',
generated_at: '2026-11-01T18:30:00Z',
};
const i = summaries.findIndex((s) => s.target_id === id);
if (i >= 0) summaries.splice(i, 1);
summaries.push(summary);
return route.fulfill({ json: summary });
});
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: /Sessions/ }).click();
return { summaries };
}
const sessionRows = (page: Page) => page.locator('table.data tbody tr:not(.row-detail)');
test.describe('Sessions view', () => {
test.beforeEach(async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
});
test('sits between Schedule and Activity and lists sessions with speakers and check-ins', async ({ page }, testInfo) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
// The nav renders an emoji icon inside .ico, so the accessible name is
// "🎤 Sessions"; compare the label text with the icon stripped.
const clean = await page.locator('.nav').locator('.nav-item').evaluateAll((els) =>
els.map((el) => {
const ico = el.querySelector('.ico')?.textContent ?? '';
return (el.textContent ?? '').replace(ico, '').trim();
}),
);
expect(clean.indexOf('Sessions')).toBeGreaterThan(-1);
expect(clean.indexOf('Sessions')).toBe(clean.indexOf('Schedule') + 1);
expect(clean.indexOf('Activity')).toBe(clean.indexOf('Sessions') + 1);
await expect(sessionRows(page)).toHaveCount(3);
// Speakers come from session_speakers via the embedded event filter. The chip
// also holds the avatar initials, so match the chip rather than raw text.
const keynote = sessionRows(page).filter({ hasText: 'Opening Keynote' }).first();
const deepDive = sessionRows(page).filter({ hasText: 'Power Apps Deep Dive' }).first();
await expect(keynote.locator('.speaker-chip')).toHaveText(/Ann Speaker/);
await expect(deepDive.locator('.speaker-chip')).toHaveText(/Bob Other/);
await expect(sessionRows(page).filter({ hasText: 'Copilot Workshop' }).first().locator('.speaker-chip')).toHaveCount(0);
// Check-in counts per session.
await expect(page.getByTestId('generate-all-summaries')).toBeEnabled();
await expect(keynote.locator('.att-count')).toHaveText('2');
await expect(keynote.locator('.pill.amber')).toContainText('4.5★ · 2');
// s3 has no feedback at all.
const workshop = sessionRows(page).filter({ hasText: 'Copilot Workshop' }).first();
await expect(workshop).toContainText('no feedback');
await expect(workshop.locator('.att-count')).toHaveCount(0);
// Expanding a row shows the roster of who scanned in.
await keynote.click();
const detail = page.locator('tr.row-detail');
await expect(detail).toContainText('Checked in (2)');
await expect(detail.getByTestId('detail-checkin-c1')).toBeVisible();
await expect(detail.getByTestId('detail-checkin-c2')).toBeVisible();
await expect(detail.getByText('Ann Example', { exact: true })).toBeVisible();
await page.screenshot({ path: testInfo.outputPath('sessions-desktop.png'), fullPage: true });
});
test('shows a Material column and lets staff manage the file from the expanded row', async ({ page }) => {
const h: Harness = { feedbackSessions: [], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
const keynote = sessionRows(page).filter({ hasText: 'Opening Keynote' }).first();
const workshop = sessionRows(page).filter({ hasText: 'Copilot Workshop' }).first();
await expect(keynote.getByTestId('material-yes-s1')).toHaveText('uploaded');
await expect(workshop.getByTestId('material-none-s3')).toBeVisible();
await keynote.click();
const detail = page.locator('tr.row-detail');
await expect(detail.getByRole('heading', { name: 'Material' })).toBeVisible();
// The clean filename is shown (storage timestamp prefix stripped).
await expect(detail.getByTestId('material-panel-s1')).toContainText('keynote.pdf');
await expect(detail.getByRole('button', { name: 'Open' })).toBeVisible();
await expect(detail.getByRole('button', { name: '⬇ Download' })).toBeVisible();
await expect(detail.getByRole('button', { name: 'Delete' })).toBeVisible();
await expect(detail.getByText('Attendees can download it once the session ends (Nov 01, 10:00).')).toBeVisible();
await expect(detail.getByText('Replace file…')).toBeVisible();
});
test('the attendee filter narrows to the sessions that person checked into', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
await page.getByTestId('attendee-filter').selectOption('[email protected]');
await expect(sessionRows(page)).toHaveCount(2);
await expect(page.locator('.cell-session', { hasText: 'Opening Keynote' })).toBeVisible();
await expect(page.locator('.cell-session', { hasText: 'Power Apps Deep Dive' })).toBeVisible();
await expect(page.locator('.cell-session', { hasText: 'Copilot Workshop' })).toHaveCount(0);
await expect(page.getByTestId('attendee-summary')).toContainText('Ann Example attended 2 sessions');
// The expanded roster highlights exactly that person.
await sessionRows(page).filter({ hasText: 'Opening Keynote' }).first().click();
await expect(page.locator('tr.row-detail mark')).toHaveText('Ann Example');
await page.getByTestId('attendee-filter').selectOption('[email protected]');
await expect(sessionRows(page)).toHaveCount(1);
await expect(page.locator('.cell-session', { hasText: 'Opening Keynote' })).toBeVisible();
});
test('one click summarises every session with feedback, blocking the page until all finish', async ({ page }, testInfo) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 600, failFor: [], summaryRequests: [] };
const { summaries } = await openAdmin(page, h);
expect(summaries).toHaveLength(0);
await page.getByTestId('generate-all-summaries').click();
// UI is blocked while the run is in flight.
await expect(page.getByTestId('summary-overlay')).toBeVisible();
await expect(page.getByTestId('generate-all-summaries')).toBeDisabled();
await expect(page.getByTestId('summary-progress')).toContainText('of 2');
// Nothing else is reachable behind the overlay.
await expect(page.getByTestId('attendee-filter')).toBeDisabled();
await expect(page.getByTestId('summary-overlay')).toHaveCount(0, { timeout: 15_000 });
// Exactly one request per session that has feedback — none for s3.
expect([...h.summaryRequests].sort()).toEqual(['s1', 's2']);
await expect(page.getByTestId('summary-run-result')).toContainText('2 session summaries stored');
await expect(page.getByTestId('summary-done-s1')).toBeVisible();
await expect(page.getByTestId('summary-done-s2')).toBeVisible();
// Stored summaries are readable in the expanded row.
await sessionRows(page).filter({ hasText: 'Opening Keynote' }).first().click();
await expect(page.locator('tr.row-detail')).toContainText('Generated summary for s1');
await page.screenshot({ path: testInfo.outputPath('sessions-after-summary.png'), fullPage: true });
});
test('a failing session summary is reported and the others still land', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: [], summaryDelayMs: 0, failFor: ['s2'], summaryRequests: [] };
await openAdmin(page, h);
await page.getByTestId('generate-all-summaries').click();
await expect(page.getByTestId('summary-run-result')).toContainText('1 session summary stored', { timeout: 15_000 });
await expect(page.getByTestId('summary-run-result')).toContainText('1 failed: Power Apps Deep Dive');
await expect(page.getByTestId('summary-done-s1')).toBeVisible();
await expect(page.getByTestId('summary-stale-s2')).toHaveCount(0);
});
test('a stale stored summary is flagged and can be regenerated', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1', 's2'], stored: ['s2'], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
// s2's stored summary was built from 1 response; there are 2 now.
await expect(page.getByTestId('summary-stale-s2')).toBeVisible();
await expect(page.getByTestId('summary-done-s2')).toHaveCount(0);
await expect(page.getByTestId('generate-all-summaries')).toBeEnabled();
});
test('the button is disabled when no session has any feedback', async ({ page }) => {
const h: Harness = { feedbackSessions: [], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
await expect(page.getByTestId('generate-all-summaries')).toBeDisabled();
await expect(page.locator('table.data tbody')).toContainText('no feedback');
});
test('without a configured LLM the button is disabled and says why', async ({ page }) => {
const h: Harness = { feedbackSessions: ['s1'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h, { configured: false });
await expect(page.getByTestId('sessions-llm-unconfigured')).toBeVisible();
await expect(page.getByTestId('generate-all-summaries')).toBeDisabled();
});
test('the table fits a mobile viewport without horizontal overflow', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 390, height: 844 });
const h: Harness = { feedbackSessions: ['s1'], stored: [], summaryDelayMs: 0, failFor: [], summaryRequests: [] };
await openAdmin(page, h);
await expect(page.getByTestId('sessions-toolbar')).toBeVisible();
await expect(page.getByTestId('generate-all-summaries')).toBeVisible();
await page.screenshot({ path: testInfo.outputPath('sessions-mobile.png'), fullPage: true });
});
});