Files
community-rule/tests/pages/legal.test.tsx
T
adilallo 4b90bce006 Replace the terms page CC BY-SA claim with a counsel-review notice.
Login still agrees to Terms of Service, but the page no longer says a community Rule is openly licensed, and Ask an organizer opens the inquiry dialog.
2026-11-23 10:40:16 -07:00

166 lines
6.1 KiB
TypeScript

import { describe, expect, test, vi } from "vitest";
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders as render } from "../utils/test-utils";
import PrivacyPage from "../../app/(marketing)/privacy/page";
import LegalDocumentPage from "../../app/(marketing)/_components/LegalDocumentPage";
import { legalPathForSlug } from "../../lib/legalSyntheticPost";
import messages from "../../messages/en/index";
vi.mock("../../lib/requestSiteOrigin", () => ({
getRequestSiteOrigin: async () => "https://communityrule.info",
}));
vi.mock("../../app/components/sections/ContentBanner", () => ({
default: ({ post, variant, updatedLabel }) => (
<section data-testid="content-banner" data-variant={variant}>
<h1>{post.frontmatter.title}</h1>
<p>{post.frontmatter.description}</p>
{updatedLabel ? (
<div>
<span>{post.frontmatter.author}</span>
<span>{updatedLabel}</span>
</div>
) : null}
</section>
),
}));
async function renderLegalPage(
slug: "privacy" | "terms" | "cookies",
page: (typeof messages.pages)[typeof slug],
) {
const ui = await LegalDocumentPage({
slug,
path: legalPathForSlug(slug),
page,
});
return render(ui);
}
describe("legal document pages", () => {
test("privacy copy names Umami and cookieless counts", () => {
const collect = messages.pages.privacy.sections.find(
(section) => section.heading === "What we collect",
);
expect(collect?.paragraphs.join(" ")).toMatch(/Umami/);
expect(collect?.paragraphs.join(" ")).toMatch(/sets no cookies/);
});
test("privacy copy does not say stakeholder or wizard", () => {
const text = JSON.stringify(messages.pages.privacy);
expect(text).not.toMatch(/stakeholder/i);
expect(text).not.toMatch(/wizard/i);
});
test("privacy page 404s while the flag is off", () => {
const previous = process.env.ENABLE_PRIVACY_POLICY;
const previousPublic = process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
delete process.env.ENABLE_PRIVACY_POLICY;
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
try {
expect(() => PrivacyPage()).toThrow("NEXT_NOT_FOUND");
} finally {
if (previous === undefined) delete process.env.ENABLE_PRIVACY_POLICY;
else process.env.ENABLE_PRIVACY_POLICY = previous;
if (previousPublic === undefined) {
delete process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY;
} else {
process.env.NEXT_PUBLIC_ENABLE_PRIVACY_POLICY = previousPublic;
}
}
});
test("privacy page covers hosting, recommendations, and campus privacy", async () => {
await renderLegalPage("privacy", messages.pages.privacy);
const page = messages.pages.privacy;
expect(screen.getByTestId("content-banner")).toHaveAttribute(
"data-variant",
"guide",
);
expect(
screen.getByRole("heading", { level: 1, name: page.banner.title }),
).toBeInTheDocument();
expect(screen.getByText(page.banner.description)).toBeInTheDocument();
expect(screen.getByText(page.updated)).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "What we collect" }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "Where it is stored" }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "Recommendations" }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "Your account" }),
).toBeInTheDocument();
expect(screen.getByText(/servers MEDLab operates/)).toBeInTheDocument();
expect(screen.getByText(/Amazon SES/)).toBeInTheDocument();
expect(
screen.getByText(/not an AI or machine-learning model/),
).toBeInTheDocument();
expect(
screen.getByRole("link", { name: "Media Economies Design Lab" }),
).toHaveAttribute("href", "https://www.colorado.edu/lab/medlab/");
expect(
screen.getByRole("link", { name: "Privacy Statement" }),
).toHaveAttribute(
"href",
"https://www.colorado.edu/compliance/policies/privacy-statement",
);
});
test("terms page is a counsel-review notice with no licensing claim", async () => {
const user = userEvent.setup();
await renderLegalPage("terms", messages.pages.terms);
const page = messages.pages.terms;
expect(
screen.getByRole("heading", { level: 1, name: page.banner.title }),
).toBeInTheDocument();
expect(page.banner.title).toBe("Our terms are being reviewed");
expect(page.intro.join(" ")).not.toMatch(/CC BY-SA/i);
expect(page.intro.join(" ")).not.toMatch(/licensed/i);
expect(page.sections).toEqual([]);
expect(screen.queryByRole("heading", { name: "Licenses" })).not.toBeInTheDocument();
expect(
screen.queryByRole("heading", { name: "Templates API" }),
).not.toBeInTheDocument();
expect(
screen.getByText(/every Rule starts private/),
).toBeInTheDocument();
await user.click(screen.getByRole("button", { name: "Ask an organizer" }));
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(
screen.getByRole("heading", { name: "Ask an organizer" }),
).toBeInTheDocument();
});
test("cookies settings page explains there are no optional cookies", async () => {
await renderLegalPage("cookies", messages.pages.cookies);
const page = messages.pages.cookies;
expect(
screen.getByRole("heading", { level: 1, name: page.banner.title }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "The session cookie" }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "The claim cookie" }),
).toBeInTheDocument();
expect(
screen.getByText(/There are no advertising or analytics cookies to turn off/),
).toBeInTheDocument();
expect(screen.getByText(/cr_session/)).toBeInTheDocument();
expect(screen.getByText(/cr_rule_claim/)).toBeInTheDocument();
expect(JSON.stringify(page)).not.toMatch(/magic link/i);
expect(
screen.getAllByRole("link", { name: "Privacy Policy" })[0],
).toHaveAttribute("href", "/privacy");
});
});