import { describe, test, expect, vi } from "vitest"; import { screen, waitFor } from "@testing-library/react"; import { renderWithProviders as render } from "../utils/test-utils"; import HowItWorksPage from "../../app/(marketing)/how-it-works/page"; import messages from "../../messages/en/index"; import { formatHowItWorksByline, howItWorksReadMinutes, } from "../../lib/howItWorksGuide"; vi.mock("next/dynamic", () => ({ default: (importFn) => { const Component = vi.fn(() => (
Related articles
)); return Component; }, })); vi.mock("../../lib/requestSiteOrigin", () => ({ getRequestSiteOrigin: async () => "https://communityrule.info", })); vi.mock("../../app/components/sections/ContentBanner", () => ({ default: ({ post, variant }) => (

{post.frontmatter.title}

{post.frontmatter.description}

), })); vi.mock("../../app/components/sections/AskOrganizer", () => ({ default: ({ title, subtitle, buttonText }) => (

{title}

{subtitle}

), })); async function renderPage() { const ui = await HowItWorksPage(); return render(ui); } describe("HowItWorksPage", () => { const page = messages.pages.howItWorks; test("renders banner, guide sections, related articles, and ask organizer", async () => { await renderPage(); expect(screen.getByTestId("content-banner")).toBeInTheDocument(); expect( screen.getByRole("heading", { name: page.banner.title }), ).toBeInTheDocument(); expect(screen.getByTestId("content-banner")).toHaveAttribute( "data-variant", "guide", ); expect(screen.getByText(page.banner.description)).toBeInTheDocument(); expect( screen.getByRole("heading", { name: "What you will have by the end" }), ).toBeInTheDocument(); expect( screen.getByRole("heading", { name: "Sketch it in CommunityRule" }), ).toBeInTheDocument(); expect( screen.getByText(page.teamRule.caption), ).toBeInTheDocument(); expect( screen.getByRole("link", { name: page.closing.createRule }), ).toHaveAttribute("href", page.closing.createRuleHref); expect( screen.getByRole("link", { name: page.closing.downloadKit }), ).toHaveAttribute("href", page.closing.downloadKitHref); expect( screen.getByRole("link", { name: page.byline.beforeYouStart }), ).toHaveAttribute("href", "#before-you-start"); expect( screen.getByText( formatHowItWorksByline(page, howItWorksReadMinutes(page)).trim(), { exact: false }, ), ).toBeInTheDocument(); expect( screen.getByRole("link", { name: "Resolving Active Conflicts" }), ).toHaveAttribute("href", "/blog/resolving-active-conflicts"); expect(screen.queryByText(/\[Confirm how long/)).not.toBeInTheDocument(); expect( screen.queryByText(/Dated entries from groups/), ).not.toBeInTheDocument(); expect( screen.queryByRole("heading", { name: "Updates from groups" }), ).not.toBeInTheDocument(); await waitFor(() => { expect(screen.getByTestId("related-articles")).toBeInTheDocument(); }); expect(screen.getByTestId("ask-organizer")).toBeInTheDocument(); expect( screen.getByText(messages.pages.home.askOrganizer.title), ).toBeInTheDocument(); expect( screen.queryByText(/How the Platform Works: From Chaos to Clarity/), ).not.toBeInTheDocument(); expect( screen.queryByText(/The Four Pillars of Governance/), ).not.toBeInTheDocument(); }); test("gives each flow screen a one-sentence caption", async () => { await renderPage(); expect( screen.getByText( "A value in CommunityRule with one row for what it means and one for the signs it is slipping.", ), ).toBeInTheDocument(); expect( screen.getByText( "A screen of cards for how you decide with the suggested cards tagged Recommended.", ), ).toBeInTheDocument(); expect( screen.getByText( "Final review in CommunityRule with the Rule as one card and a chip for each part.", ), ).toBeInTheDocument(); }); test("clips body ornaments at the page frame and keeps them behind copy", async () => { const { container } = await renderPage(); const page = container.querySelector("div.min-h-screen"); expect(page).toHaveClass("overflow-x-clip"); const right = container.querySelector('[data-node-id="19003:23575"]'); const left = container.querySelector('[data-node-id="19003:23576"]'); expect(right).toHaveClass( "z-0", "left-[87.19%]", "right-0", "top-[266px]", "lg:left-[84.86%]", "lg:top-[255px]", ); expect(left).toHaveClass("z-0", "left-0", "right-[88.38%]", "top-[811px]"); const rightImg = right?.querySelector("img"); const leftImg = left?.querySelector("img"); expect(rightImg).toHaveAttribute( "src", "/assets/shapes/how-shape-2.svg", ); expect(leftImg).toHaveAttribute("src", "/assets/shapes/how-shape-1.svg"); expect(rightImg).toHaveClass("object-contain"); expect(leftImg).toHaveClass("object-contain"); }); });