172 lines
6.2 KiB
TypeScript
172 lines
6.2 KiB
TypeScript
import { describe, expect, test, vi } from "vitest";
|
|
import { screen } from "@testing-library/react";
|
|
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 covers licenses and the templates API, not ranking", async () => {
|
|
await renderLegalPage("terms", messages.pages.terms);
|
|
const page = messages.pages.terms;
|
|
|
|
expect(
|
|
screen.getByRole("heading", { level: 1, name: page.banner.title }),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("heading", { level: 2, name: "Licenses" }),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("heading", { level: 2, name: "Templates API" }),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.queryByRole("heading", { name: "Recommendations" }),
|
|
).not.toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole("link", { name: "CC BY-SA 4.0" }),
|
|
).toHaveAttribute(
|
|
"href",
|
|
"https://creativecommons.org/licenses/by-sa/4.0/",
|
|
);
|
|
expect(
|
|
screen.getByRole("link", { name: "GPL-3.0 or later" }),
|
|
).toHaveAttribute("href", "https://www.gnu.org/licenses/gpl-3.0.html");
|
|
expect(screen.getByRole("link", { name: "Gitea" })).toHaveAttribute(
|
|
"href",
|
|
"https://git.medlab.host/CommunityRule/community-rule",
|
|
);
|
|
expect(
|
|
screen.getByRole("link", { name: "GET /api/templates" }),
|
|
).toHaveAttribute("href", "/api/templates");
|
|
});
|
|
|
|
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");
|
|
});
|
|
});
|