Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
import type { Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
import { captureOne } from "@rallly/test-helpers";
import { load } from "cheerio";
import { NewPollPage } from "./new-poll-page";
import type { PollPage } from "./poll-page";
test.describe(() => {
let page: Page;
let pollPage: PollPage;
let editSubmissionUrl: string;
let pollId: string;
test.beforeAll(async ({ browser }) => {
// A context made here does not inherit the config's permissions, and
// the copy tests read the clipboard back.
const context = await browser.newContext({
permissions: ["clipboard-read"],
});
page = await context.newPage();
const newPollPage = new NewPollPage(page);
await newPollPage.goto();
pollPage = await newPollPage.create({
name: "Monthly Meetup",
enableComments: true,
});
await pollPage.closeShareDialog();
// Extract the poll ID from the URL
const url = page.url();
const match = url.match(/\/poll\/([a-zA-Z0-9]+)/);
pollId = match ? match[1] : "";
expect(pollId).not.toBe("");
});
test("should be able to comment", async () => {
await pollPage.addComment();
const comment = page.locator("data-testid=comment");
await expect(comment.locator("text='This is a comment!'")).toBeVisible();
await expect(comment.locator("text=You")).toBeVisible();
// The comments sheet is modal; close it so later tests can reach the page.
const sheet = page.getByRole("dialog", { name: "Comments" });
await sheet.getByRole("button", { name: "Close" }).click();
await expect(sheet).toBeHidden();
});
test("copy participant link", async () => {
const inviteLink = await pollPage.copyInviteLink();
await pollPage.closeShareDialog();
expect(inviteLink).toMatch(/\/invite\/[a-zA-Z0-9]+/);
});
test("should be able to vote with an email", async () => {
const invitePage = await pollPage.gotoInvitePage();
await invitePage.addParticipant("Anne", "[email protected]");
const { email } = await captureOne("[email protected]");
await expect(page.locator("text='Anne'")).toBeVisible();
expect(email.Subject).toBe("Thanks for responding to Monthly Meetup");
const $ = load(email.HTML);
const href = $("#editSubmissionUrl").attr("href");
if (!href) {
throw new Error("Could not get edit submission link from email");
}
editSubmissionUrl = href;
});
test("should be able to edit submission", async ({ page: newPage }) => {
await newPage.goto(editSubmissionUrl);
await expect(newPage.getByTestId("participant-menu")).toBeVisible({
timeout: 10000,
});
});
// The host copies the same link the confirmation email carried, so a
// respondent who left no email can still be handed edit access.
test("host copies the participant's edit link", async () => {
await page.goto(`/poll/${pollId}`);
await page.getByTestId("participant-menu").click();
await page.getByRole("menuitem", { name: "Copy edit link" }).click();
await expect(page.getByText("Edit link for Anne copied")).toBeVisible();
expect(await page.evaluate("navigator.clipboard.readText()")).toBe(
editSubmissionUrl,
);
});
});