Feedback page: results, responses, who hasn't answered, reminders (2.1.0)
- Supervisor -> Feedback (supervisors and admins, campus-scoped): every event's form with answered of asked, response rate, average rating and last reminder; per event the results per question (with the AI summary), each response, and on named forms who was asked and who has answered. - Remind those who haven't answered (or one person on a named form): a fresh link, plus the form to anyone eligible who hasn't had it; nobody gets the form or a reminder twice within 24 hours. The 3-day job is unchanged. - Anonymous forms show no names and no list of who has answered. - FeedbackInvite.reminderCount (migration 20261103120000_feedback_reminders); access log action feedback_responses; help page; dashboard and Ctrl+K links. - Roadmap: the AI helpers on the privacy pages are dropped; 2.1.0 is the feedback page. - Tests: tests/feedbackPage.test.ts, e2e/feedback.spec.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { test, expect, loginAs, api, v2, seed, API } from "./fixtures";
|
||||
|
||||
// 2.1.0: Supervisor → Feedback. The seed puts a named feedback form on "E2E Last Sunday", sent
|
||||
// two days ago to Thandi (who answers here) and Lerato (who doesn't).
|
||||
|
||||
type PublicForm = { fields: { id: string; type: string }[] };
|
||||
type AccessLog = { rows: { action: string; what: string; records: number | null; actor: string }[] };
|
||||
|
||||
test.describe("feedback page", () => {
|
||||
test("see the answers, who hasn't answered, and remind them", async ({ page }) => {
|
||||
const token = seed().feedback.tokens.user;
|
||||
const form = await (await page.request.get(`${API}/api/v2/feedback-forms/${token}`)).json() as { data: PublicForm };
|
||||
const [rating, text] = form.data.fields;
|
||||
const sent = await page.request.post(`${API}/api/v2/feedback-forms/${token}`, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
data: JSON.stringify({ answers: { [rating.id]: 5, [text.id]: "Loved the worship" } }),
|
||||
});
|
||||
expect(sent.ok()).toBe(true);
|
||||
|
||||
await loginAs(page, "supervisor");
|
||||
await page.goto("/dashboard/supervisor/feedback");
|
||||
const row = page.getByRole("row", { name: /E2E Last Sunday/ });
|
||||
await expect(row).toContainText("1 of 2");
|
||||
await expect(row).toContainText("5.0");
|
||||
await row.getByRole("button", { name: "E2E Last Sunday" }).click();
|
||||
|
||||
await expect(page.getByRole("heading", { name: "E2E Last Sunday" })).toBeVisible();
|
||||
await expect(page.getByText("Loved the worship")).toBeVisible();
|
||||
await expect(page.getByText("— Thandi Test")).toBeVisible();
|
||||
|
||||
await page.getByRole("tab", { name: /Responses/ }).click();
|
||||
await expect(page.getByRole("article").filter({ hasText: "Thandi Test" })).toContainText("★★★★★");
|
||||
|
||||
await page.getByRole("tab", { name: /People/ }).click();
|
||||
const lerato = page.getByRole("row", { name: /Lerato Late/ });
|
||||
await expect(lerato).toContainText("Not yet");
|
||||
await expect(page.getByRole("row", { name: /Thandi Test/ }).getByRole("button", { name: "Remind" })).toHaveCount(0);
|
||||
|
||||
page.once("dialog", d => d.accept());
|
||||
await lerato.getByRole("button", { name: "Remind" }).click();
|
||||
await expect(page.getByRole("status")).toHaveText("Reminded 1 person.");
|
||||
await expect(lerato).toContainText("1 · last");
|
||||
await expect(lerato.getByRole("button", { name: "Remind" })).toBeDisabled();
|
||||
await expect(page.getByRole("button", { name: /Remind those who haven't answered/ })).toBeDisabled();
|
||||
|
||||
// Reminding again the same day sends nothing.
|
||||
const again = await api<{ data: { reminded: number; message: string } }>(page, "supervisor", "POST", `/api/v2/events/${seed().events.past}/feedback/remind`, {});
|
||||
expect(again.data.reminded).toBe(0);
|
||||
expect(again.data.message).toMatch(/last 24 hours/);
|
||||
|
||||
// Opening a named form's answers is in the access log.
|
||||
const log = await v2<AccessLog>(page, "admin", "GET", "/api/v2/privacy/access-log");
|
||||
expect(log.rows.find(r => r.action === "feedback_responses")).toMatchObject({ what: "Feedback answers: E2E Last Sunday", records: 1, actor: "Sam Supervisor" });
|
||||
});
|
||||
|
||||
test("staff can't see feedback", async ({ page }) => {
|
||||
const res = await page.request.get(`${API}/api/v2/feedback`, { headers: { Authorization: `Bearer ${seed().users.staff.token}` } });
|
||||
expect(res.status()).toBe(403);
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,7 @@ export type Seed = {
|
||||
formOptionId: string;
|
||||
course: { sessions: { id: string; label: string }[]; ticketId: string; qrCode: string };
|
||||
unsubscribeToken: string;
|
||||
feedback: { tokens: { user: string; late: string } };
|
||||
newsPromptUser: { id: string; token: string };
|
||||
noticeFirstUser: { id: string; token: string };
|
||||
retention: { toWarn: string; toAnonymise: string };
|
||||
|
||||
@@ -245,6 +245,27 @@ async function seed(url) {
|
||||
await prisma.securityEvent.create({ data: { userId: toWarn.id, type: 'login', createdAt: new Date(Date.now() - 3 * 365 * 24 * 60 * 60 * 1000) } });
|
||||
return { toWarn: toWarn.id, toAnonymise: toAnonymise.id };
|
||||
})(),
|
||||
// 2.1.0 Feedback page: a named form on the past event, sent two days ago to Thandi (the
|
||||
// seeded user, who answers in the test) and Lerato (who doesn't). The links' tokens.
|
||||
feedback: await (async () => {
|
||||
const { hashToken } = require(path.join(backend, 'src/utils/feedback'));
|
||||
const twoDaysAgo = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000);
|
||||
const form = await prisma.feedbackForm.create({
|
||||
data: {
|
||||
eventId: pastEvent.id, audience: 'all', anonymous: false, sendAt: twoDaysAgo, sentAt: twoDaysAgo,
|
||||
fields: { create: [
|
||||
{ type: 'rating', label: 'How was the service?', isRequired: true, order: 0 },
|
||||
{ type: 'text', label: 'What should we keep doing?', order: 1 },
|
||||
] },
|
||||
},
|
||||
});
|
||||
const tokens = { user: 'e2e-feedback-thandi-token', late: 'e2e-feedback-lerato-token' };
|
||||
await prisma.feedbackInvite.createMany({ data: [
|
||||
{ formId: form.id, userId: users.user.id, tokenHash: hashToken(tokens.user), sentAt: twoDaysAgo },
|
||||
{ formId: form.id, userId: latecomer.id, tokenHash: hashToken(tokens.late), sentAt: twoDaysAgo },
|
||||
] });
|
||||
return { tokens };
|
||||
})(),
|
||||
// The link a news email to the seeded user would carry (signed with JWT_SECRET).
|
||||
unsubscribeToken: require(path.join(backend, 'src/utils/privacy')).unsubscribeToken({ userId: users.user.id }),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user