Files
community-rule/tests/unit/howItWorksGuide.test.ts
T

45 lines
1.6 KiB
TypeScript

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, 1)).toBe(
"By CommunityRule Creative Team. 18 February 2027. 1 minute read. ",
);
expect(formatHowItWorksByline(page, minutes)).toBe(
`By CommunityRule Creative Team. 18 February 2027. ${minutes} minutes read. `,
);
const guideText = collectHowItWorksGuideText(page);
expect(guideText).toContain(
"A Rule is a short document your community can read aloud in a few minutes.",
);
expect(guideText).toContain("Resolving Active Conflicts");
expect(guideText).not.toContain("](/kit)");
expect(guideText).not.toMatch(/\[[^\]]*\]/);
});
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}`,
);
});
});