The virtual-authenticator setup and registerUser were copy-pasted into six spec files and had drifted: the auth spec's copy lost the final URL assertion, and the settings spec's variant skipped hydration and the Terms checkbox entirely. Seed-route boilerplate and hardcoded localhost URLs were repeated across three more files. - helpers/auth.ts: setup/removeVirtualAuthenticator, submitRegistration (no outcome assertion, for expected-failure attempts), registerUser (asserts the signed-in redirect), registerFreshUser, logout - helpers/journal.ts: JOURNAL/PLANNER base URLs, seedRoute, routeHasGeom, seedKomootConnection - nine spec files now import the helpers instead of re-deriving them Found while consolidating: settings.test.ts, explore.test.ts, and social.test.ts are not matched by any playwright project and have never run — which is how the settings spec's broken register helper survived. Registering them (and fixing whatever has rotted) is a follow-up; the config now carries a warning so the trap is at least documented. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
97 lines
4.2 KiB
TypeScript
97 lines
4.2 KiB
TypeScript
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
|
import { setupVirtualAuthenticator, registerUser } from "./helpers/auth";
|
|
|
|
async function setProfileVisibility(page: Page, value: "public" | "private") {
|
|
await page.goto("/settings");
|
|
await page.locator(`input[type=radio][name=profileVisibility][value=${value}]`).check();
|
|
await page.getByRole("button", { name: /^Save$/ }).first().click();
|
|
// Don't use waitForLoadState("networkidle") — the SSE connection to
|
|
// /api/events keeps the network busy indefinitely. Wait for the
|
|
// explicit save confirmation instead.
|
|
await expect(page.getByText("Profile saved.")).toBeVisible({ timeout: 10000 });
|
|
}
|
|
|
|
test.describe.configure({ mode: "serial" });
|
|
|
|
test.describe("Notifications", () => {
|
|
test("anonymous /notifications redirects to login", async ({ page }) => {
|
|
await page.goto("/notifications");
|
|
await expect(page).toHaveURL(/\/auth\/login/, { timeout: 10000 });
|
|
});
|
|
|
|
test("public auto-accept follow → recipient sees follow_received notification", async ({ page, browser }) => {
|
|
const cdp = await page.context().newCDPSession(page);
|
|
await setupVirtualAuthenticator(cdp);
|
|
|
|
const stamp = Date.now();
|
|
const aEmail = `nf-a-${stamp}@example.com`;
|
|
const aUsername = `nfa${stamp}`;
|
|
const bEmail = `nf-b-${stamp}@example.com`;
|
|
const bUsername = `nfb${stamp}`;
|
|
|
|
await registerUser(page, aEmail, aUsername);
|
|
|
|
const bCtx = await browser.newContext();
|
|
const bPage = await bCtx.newPage();
|
|
const bCdp = await bPage.context().newCDPSession(bPage);
|
|
await setupVirtualAuthenticator(bCdp);
|
|
await registerUser(bPage, bEmail, bUsername);
|
|
await setProfileVisibility(bPage, "public");
|
|
|
|
// A follows B (auto-accept).
|
|
await page.goto(`/users/${bUsername}`);
|
|
await waitForHydration(page);
|
|
await page.getByRole("button", { name: "Follow" }).click();
|
|
await expect(page.getByRole("button", { name: "Unfollow" })).toBeVisible({ timeout: 5000 });
|
|
|
|
// B opens /notifications — should see one row referencing A.
|
|
await bPage.goto("/notifications");
|
|
await expect(bPage.getByText(new RegExp(`${aUsername}.+started following`))).toBeVisible({ timeout: 10000 });
|
|
|
|
// Mark all read clears the unread badge. The button disappears when
|
|
// hasUnread flips to false; the toBeHidden assertion polls.
|
|
await bPage.getByRole("button", { name: /Mark all read/i }).click();
|
|
await expect(bPage.getByRole("button", { name: /Mark all read/i })).toBeHidden({ timeout: 10000 });
|
|
|
|
await bCtx.close();
|
|
});
|
|
|
|
test("private profile: request → approve → follower sees follow_request_approved notification", async ({ page, browser }) => {
|
|
const cdp = await page.context().newCDPSession(page);
|
|
await setupVirtualAuthenticator(cdp);
|
|
|
|
const stamp = Date.now();
|
|
const aEmail = `nfap-a-${stamp}@example.com`;
|
|
const aUsername = `nfapa${stamp}`;
|
|
const bEmail = `nfap-b-${stamp}@example.com`;
|
|
const bUsername = `nfapb${stamp}`;
|
|
|
|
await registerUser(page, aEmail, aUsername);
|
|
|
|
const bCtx = await browser.newContext();
|
|
const bPage = await bCtx.newPage();
|
|
const bCdp = await bPage.context().newCDPSession(bPage);
|
|
await setupVirtualAuthenticator(bCdp);
|
|
await registerUser(bPage, bEmail, bUsername);
|
|
// B stays private (default).
|
|
|
|
// A requests to follow B.
|
|
await page.goto(`/users/${bUsername}`);
|
|
await page.getByRole("button", { name: /Request to follow/i }).click();
|
|
await expect(page.getByRole("button", { name: /Requested/i })).toBeVisible({ timeout: 5000 });
|
|
|
|
// B approves the request from the Requests tab on /notifications.
|
|
// After the fetcher.Form revalidates, the empty-state copy
|
|
// replaces the request row.
|
|
await bPage.goto("/notifications?tab=requests");
|
|
await bPage.getByRole("button", { name: "Approve" }).click();
|
|
await expect(bPage.getByText(/No pending follow requests/i)).toBeVisible({ timeout: 10000 });
|
|
|
|
// A reloads /notifications — should see follow_request_approved
|
|
// referencing B (the target's username).
|
|
await page.goto("/notifications");
|
|
await expect(page.getByText(new RegExp(`${bUsername}.+accepted your follow request`))).toBeVisible({ timeout: 10000 });
|
|
|
|
await bCtx.close();
|
|
});
|
|
});
|