Files
Convivo/e2e/tests/feedback.spec.ts
d5ec009cb5 Add Playwright E2E suite (46 tests) + app testids + test_cases.md
- e2e/: full Playwright suite covering every spec case (staff auth/UI,
  welcome + session check-in, attendee access/gating, connections,
  profile visibility, speaker material, sponsor, feedback, E2E journeys,
  role security matrix). 46/46 passing.
- apps/convivo: add data-testid attributes (gate, tabs, scanner, toggles)
  to support the E2E suite.
- test_cases.md: spec-case-to-test coverage map (all cases fully covered).
- .gitignore: ignore e2e node_modules/reports/test-results.

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-09-09 10:13:26 +02:00

245 lines
10 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect } from './base';
import { APP_URL, ID, SESSION_A, SESSION_B, EVENT_ID } from '../src/helpers/config';
import { login } from '../src/helpers/auth';
import { createUser } from '../src/helpers/multi';
import { signInJwt, userRpcResult } from '../src/helpers/api';
import { db, psql } from '../src/helpers/db';
import { setSessionCheckin } from '../src/helpers/reset';
import { AppPage } from '../src/pages/AppPage';
import { ScanPage } from '../src/pages/ScanPage';
import { AgendaPage } from '../src/pages/AgendaPage';
import { HomePage } from '../src/pages/HomePage';
import { FeedbackPage } from '../src/pages/FeedbackPage';
/**
* §29 Feedback.
*
* Feedback is available only for a session that is (a) done and (b) the user
* was checked into. The `give-feedback` button in the Agenda session sheet is
* shown when `selStatus === 'done' && selCheckedIn`. The backend RPC
* `submit_feedback` raises if the caller is not checked in to the session.
*
* Points: 10 with a comment, 5 without, 0 on resubmit (updates existing row).
*
* SESSION_A — slot 1 (09:15–10:00, "done" at the simulated 10:20 clock).
* SESSION_B — slot 2 (10:15–11:00, "now" — not done).
*/
/** SESSION_A title (for opening the session sheet). */
const SESSION_A_TITLE = 'From Vision to Reality';
/** SESSION_B title (for opening the session sheet). */
const SESSION_B_TITLE = '10 Essential tips to kickstart Power Platform Governance';
/** The full feedback row for a contact + session (event_id|contact_email|session_id|rating). */
function feedbackRow(contactEmail: string, sessionId: string): string {
return psql(
`select event_id || '|' || contact_email || '|' || session_id || '|' || rating
from public.feedback where contact_email = '${contactEmail.replace(/'/g, "''")}' and session_id = '${sessionId}' limit 1`,
);
}
/** The number of feedback rows a contact has for a session. */
function feedbackRowCount(contactEmail: string, sessionId: string): number {
const n = psql(
`select count(*) from public.feedback where contact_email = '${contactEmail.replace(/'/g, "''")}' and session_id = '${sessionId}'`,
);
return Number(n);
}
test.describe('Feedback', () => {
test('CONV-FEEDBACK-001 feedback unavailable for unattended session', async ({ page }) => {
const app = new AppPage(page, APP_URL);
// ATTENDEE_A is NOT checked into SESSION_A (reset clears all check-ins).
await login(page, APP_URL, ID.attendeeA);
await app.waitForAdmitted();
// Frontend: the "Give feedback" button is absent; the "not checked in"
// notice is shown instead (SESSION_A is done but the user wasn't there).
await app.gotoTab('agenda');
const agenda = new AgendaPage(page);
await agenda.openSession(SESSION_A_TITLE);
await expect(agenda.giveFeedbackButton()).toHaveCount(0);
await expect(agenda.notCheckedInNotice()).toBeVisible();
// Backend: submit_feedback raises (the user is not checked in).
const jwt = await signInJwt(ID.attendeeA.email, ID.attendeeA.qrToken);
const result = await userRpcResult(jwt, 'submit_feedback', {
p_session_id: SESSION_A,
p_rating: 5,
p_comment: 'Great session!',
});
expect(result.ok).toBe(false);
});
test('CONV-FEEDBACK-002 session attendance unlocks feedback (staff checks in via scanner)', async ({ browser }) => {
// Two contexts: the attendee stays open; the staff checks them in via the
// scanner. The attendee app must react without logout/login.
const attendee = await createUser(browser, 'attendeeA');
const staff = await createUser(browser, 'staff');
try {
const aApp = new AppPage(attendee.page, APP_URL);
const aAgenda = new AgendaPage(attendee.page);
const sApp = new AppPage(staff.page, APP_URL);
const sScan = new ScanPage(staff.page);
// 1. Confirm feedback for SESSION_A is unavailable to ATTENDEE_A.
await login(attendee.page, APP_URL, ID.attendeeA);
await aApp.waitForAdmitted();
await aApp.gotoTab('agenda');
await aAgenda.openSession(SESSION_A_TITLE);
await expect(aAgenda.giveFeedbackButton()).toHaveCount(0);
// Close the session sheet (it intercepts pointer events on the tab bar).
await attendee.page.getByRole('button', { name: '✕' }).click();
await attendee.page.locator('.backdrop').waitFor({ state: 'detached', timeout: 3000 }).catch(() => {});
// 2. STAFF_01 selects SESSION_A and checks ATTENDEE_A into it (scanner).
await login(staff.page, APP_URL, ID.staff);
await sApp.waitForAdmitted();
await sApp.gotoTab('scan');
await sScan.setStaffMode();
await sScan.setSessionMode();
await sScan.selectSession(SESSION_A);
await sScan.scanCode(ID.attendeeA.qrToken);
await expect(sScan.sessionResult()).toBeVisible();
// Backend: the session check-in is persisted.
expect(await db.waitForSessionCheckin(ID.attendeeA.email, SESSION_A)).toBe(true);
// 3. The attendee app reacts without logout/login: navigating to the
// Agenda re-fetches check-ins, and SESSION_A is now eligible.
await aApp.gotoTab('home');
await aApp.gotoTab('agenda');
await aAgenda.openSession(SESSION_A_TITLE);
await expect(aAgenda.giveFeedbackButton()).toBeVisible();
// Close the session sheet (it intercepts pointer events on the tab bar).
await attendee.page.getByRole('button', { name: '✕' }).click();
await attendee.page.locator('.backdrop').waitFor({ state: 'detached', timeout: 3000 }).catch(() => {});
// The feedback-pill on Home is also visible (pending feedback for a done
// session the user attended).
await aApp.gotoTab('home');
const home = new HomePage(attendee.page);
await expect(home.feedbackPill()).toBeVisible();
} finally {
await attendee.close();
await staff.close();
}
});
test('CONV-FEEDBACK-003 feedback can be given later (persists across navigation + reload)', async ({ page }) => {
const app = new AppPage(page, APP_URL);
const agenda = new AgendaPage(page);
// ATTENDEE_A attended SESSION_A (direct DB — check-in is a precondition).
setSessionCheckin(ID.attendeeA.email, SESSION_A, ID.staff.email);
await login(page, APP_URL, ID.attendeeA);
await app.waitForAdmitted();
// 1. Do not immediately submit: confirm eligibility, then navigate away.
await app.gotoTab('agenda');
await agenda.openSession(SESSION_A_TITLE);
await expect(agenda.giveFeedbackButton()).toBeVisible();
// Close the session sheet (it intercepts pointer events on the tab bar).
// The Sheet only closes on backdrop click (not Escape).
await page.locator('.backdrop').click({ position: { x: 10, y: 10 } });
await app.waitForAdmitted();
// 3. Return later to the feedback functionality: SESSION_A is still eligible.
await app.gotoTab('agenda');
await agenda.openSession(SESSION_A_TITLE);
await expect(agenda.giveFeedbackButton()).toBeVisible();
});
test('CONV-FEEDBACK-004 feedback is session-specific (attended A, not B)', async ({ page }) => {
const app = new AppPage(page, APP_URL);
const agenda = new AgendaPage(page);
// ATTENDEE_A attended SESSION_A but did NOT attend SESSION_B.
setSessionCheckin(ID.attendeeA.email, SESSION_A, ID.staff.email);
await login(page, APP_URL, ID.attendeeA);
await app.waitForAdmitted();
// Feedback is available for SESSION_A (done + checked-in).
await app.gotoTab('agenda');
await agenda.openSession(SESSION_A_TITLE);
await expect(agenda.giveFeedbackButton()).toBeVisible();
// Feedback is unavailable for SESSION_B (not checked in).
await page.locator('.backdrop').click({ position: { x: 10, y: 10 } });
await agenda.openSession(SESSION_B_TITLE);
await expect(agenda.giveFeedbackButton()).toHaveCount(0);
// Backend: the per-session check is enforced — SESSION_A ok, SESSION_B not.
const jwt = await signInJwt(ID.attendeeA.email, ID.attendeeA.qrToken);
const aRes = await userRpcResult(jwt, 'submit_feedback', {
p_session_id: SESSION_A,
p_rating: 5,
p_comment: 'A',
});
const bRes = await userRpcResult(jwt, 'submit_feedback', {
p_session_id: SESSION_B,
p_rating: 5,
p_comment: 'B',
});
expect(aRes.ok).toBe(true);
expect(bRes.ok).toBe(false);
});
test('CONV-FEEDBACK-005 submit session feedback (association + duplicate prevention)', async ({ page }) => {
const app = new AppPage(page, APP_URL);
const agenda = new AgendaPage(page);
// ATTENDEE_A attended SESSION_A.
setSessionCheckin(ID.attendeeA.email, SESSION_A, ID.staff.email);
// Capture the baseline points (should be 0 after reset).
const beforePoints = db.registration(ID.attendeeA.email)?.points ?? 0;
await login(page, APP_URL, ID.attendeeA);
await app.waitForAdmitted();
// Open the session and click "Give feedback".
await app.gotoTab('agenda');
await agenda.openSession(SESSION_A_TITLE);
await agenda.giveFeedbackButton().click();
// Complete all required fields and submit.
const feedback = new FeedbackPage(page);
await feedback.rate(5);
await feedback.setComment('Excellent session, very insightful!');
await feedback.submit();
// Backend: the feedback is associated with the correct attendee, session,
// and event.
const row = feedbackRow(ID.attendeeA.email, SESSION_A);
expect(row).toContain(`${EVENT_ID}|`);
expect(row).toContain(`|${ID.attendeeA.email}|`);
expect(row).toContain(`|${SESSION_A}|`);
// Points: 10 awarded (with a comment).
const afterPoints = db.registration(ID.attendeeA.email)?.points ?? 0;
expect(afterPoints).toBe(beforePoints + 10);
// Duplicate submission: submit again (a different rating, no comment). The
// existing row is updated in place — no second independent response is
// created, and no further points are awarded.
await app.gotoTab('agenda');
await agenda.openSession(SESSION_A_TITLE);
await agenda.giveFeedbackButton().click();
await feedback.rate(4);
await feedback.submit();
// Still exactly one feedback row for SESSION_A.
expect(feedbackRowCount(ID.attendeeA.email, SESSION_A)).toBe(1);
// The rating was updated in place (5 → 4).
expect(feedbackRow(ID.attendeeA.email, SESSION_A)).toContain(`|${SESSION_A}|4`);
// Points unchanged by the resubmit (0 earned on resubmit).
const resubmitPoints = db.registration(ID.attendeeA.email)?.points ?? 0;
expect(resubmitPoints).toBe(beforePoints + 10);
});
});