Files
community-rule/tests/pages/press.test.tsx
T

71 lines
2.4 KiB
TypeScript

import { describe, expect, test, vi } from "vitest";
import { screen } from "@testing-library/react";
import { renderWithProviders as render } from "../utils/test-utils";
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 renderPressPage() {
const page = messages.pages.press;
const ui = await LegalDocumentPage({
slug: "press",
path: legalPathForSlug("press"),
page,
});
return render(ui);
}
describe("press page", () => {
test("holds embargoed press materials, a contact, and the story", async () => {
await renderPressPage();
const page = messages.pages.press;
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(/when the embargo lifts/),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "Contact" }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "The story" }),
).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 2, name: "Does CommunityRule use AI?" }),
).toBeInTheDocument();
expect(
screen.getAllByRole("link", { name: "medlab@colorado.edu" })[0],
).toHaveAttribute("href", "mailto:medlab@colorado.edu");
expect(
screen.getByRole("link", { name: "Email the press contact" }),
).toHaveAttribute("href", "mailto:medlab@colorado.edu");
expect(screen.getByText(/CC BY-SA 4.0/)).toBeInTheDocument();
});
});