Replace the Four Pillars page with the Guide to CommunityRule on the Content page Template.
This commit is contained in:
1 parent
bf9ee79c9f
commit
453139c783
17 files changed
+1005
-32
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import { fireEvent, waitFor } from "@testing-library/react";
|
||||
import {
|
||||
renderWithProviders as render,
|
||||
screen,
|
||||
} from "../utils/test-utils";
|
||||
import HowItWorksShareRow from "../../app/(marketing)/how-it-works/_components/HowItWorksShareRow";
|
||||
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
describe("HowItWorksShareRow", () => {
|
||||
beforeEach(() => {
|
||||
writeText.mockReset();
|
||||
writeText.mockResolvedValue(undefined);
|
||||
Object.defineProperty(window.navigator, "clipboard", {
|
||||
configurable: true,
|
||||
value: { writeText },
|
||||
});
|
||||
});
|
||||
|
||||
it("copies wiki markdown and prints the page", async () => {
|
||||
const print = vi.spyOn(window, "print").mockImplementation(() => {});
|
||||
|
||||
render(
|
||||
<HowItWorksShareRow
|
||||
sendLabel="Send this to your community"
|
||||
copyLabel="Copy into your wiki"
|
||||
printLabel="Print the card"
|
||||
copiedTitle="Copied to clipboard"
|
||||
copyFailedTitle="Could not copy"
|
||||
mailtoHref="mailto:?subject=Guide"
|
||||
wikiMarkdown="[Guide](https://example.com)"
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByRole("link", { name: "Send this to your community" }),
|
||||
).toHaveAttribute("href", "mailto:?subject=Guide");
|
||||
|
||||
fireEvent.click(
|
||||
screen.getByRole("button", { name: "Copy into your wiki" }),
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(writeText).toHaveBeenCalledWith("[Guide](https://example.com)");
|
||||
});
|
||||
expect(screen.getByText("Copied to clipboard")).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Print the card" }));
|
||||
expect(print).toHaveBeenCalled();
|
||||
print.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,7 @@ 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 { howItWorksReadMinutes } from "../../lib/howItWorksGuide";
|
||||
|
||||
vi.mock("next/dynamic", () => ({
|
||||
default: (importFn) => {
|
||||
@@ -13,6 +14,10 @@ vi.mock("next/dynamic", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../../lib/requestSiteOrigin", () => ({
|
||||
getRequestSiteOrigin: async () => "https://communityrule.info",
|
||||
}));
|
||||
|
||||
vi.mock("../../app/components/sections/ContentBanner", () => ({
|
||||
default: ({ post, variant }) => (
|
||||
<section data-testid="content-banner" data-variant={variant}>
|
||||
@@ -32,11 +37,16 @@ vi.mock("../../app/components/sections/AskOrganizer", () => ({
|
||||
),
|
||||
}));
|
||||
|
||||
async function renderPage() {
|
||||
const ui = await HowItWorksPage();
|
||||
return render(ui);
|
||||
}
|
||||
|
||||
describe("HowItWorksPage", () => {
|
||||
const page = messages.pages.howItWorks;
|
||||
|
||||
test("renders banner, body sections, related articles, and ask organizer", async () => {
|
||||
render(<HowItWorksPage />);
|
||||
test("renders banner, guide sections, related articles, and ask organizer", async () => {
|
||||
await renderPage();
|
||||
|
||||
expect(screen.getByTestId("content-banner")).toBeInTheDocument();
|
||||
expect(
|
||||
@@ -48,6 +58,31 @@ describe("HowItWorksPage", () => {
|
||||
);
|
||||
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(
|
||||
`By ${page.banner.author}. 18 February 2027. ${howItWorksReadMinutes(page)} minute read.`,
|
||||
{ exact: false },
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId("related-articles")).toBeInTheDocument();
|
||||
});
|
||||
@@ -57,15 +92,35 @@ describe("HowItWorksPage", () => {
|
||||
screen.getByText(messages.pages.home.askOrganizer.title),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(/How the Platform Works: From Chaos to Clarity/),
|
||||
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(/mutual aid network, manage an open-source project/),
|
||||
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", () => {
|
||||
const { container } = render(<HowItWorksPage />);
|
||||
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");
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import messages from "../../messages/en/index";
|
||||
import {
|
||||
collectHowItWorksGuideText,
|
||||
formatHowItWorksByline,
|
||||
formatHowItWorksDate,
|
||||
howItWorksReadMinutes,
|
||||
howItWorksWikiMarkdown,
|
||||
} from "../../lib/howItWorksGuide";
|
||||
|
||||
describe("howItWorksGuide", () => {
|
||||
const page = messages.pages.howItWorks;
|
||||
|
||||
it("formats the Figma date and byline from the final text", () => {
|
||||
expect(formatHowItWorksDate(page.banner.date)).toBe("18 February 2027");
|
||||
const minutes = howItWorksReadMinutes(page);
|
||||
expect(minutes).toBeGreaterThanOrEqual(10);
|
||||
expect(formatHowItWorksByline(page, minutes)).toBe(
|
||||
`By CommunityRule Creative Team. 18 February 2027. ${minutes} minute read. `,
|
||||
);
|
||||
expect(collectHowItWorksGuideText(page)).toContain(
|
||||
"A Rule is a short document your community can read aloud in a few minutes.",
|
||||
);
|
||||
expect(collectHowItWorksGuideText(page)).not.toContain("](/kit)");
|
||||
});
|
||||
|
||||
it("builds wiki markdown from the title, description and URL", () => {
|
||||
expect(
|
||||
howItWorksWikiMarkdown(
|
||||
page.banner.title,
|
||||
page.banner.description,
|
||||
"https://communityrule.info/how-it-works",
|
||||
),
|
||||
).toBe(
|
||||
`[${page.banner.title}](https://communityrule.info/how-it-works)\n\n${page.banner.description}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user