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

88 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import {
clipCommunityInviteDescription,
communityInviteInitials,
communityPossessive,
inviteRuleCountsLabel,
inviteRuleCountsSpoken,
} from "../../lib/create/ruleInviteCardMeta";
describe("communityInviteInitials", () => {
it("uses the first two words", () => {
expect(communityInviteInitials("Juniper Street Food Share")).toBe("JS");
});
it("uses two letters of a single word", () => {
expect(communityInviteInitials("Garden")).toBe("GA");
});
});
describe("communityPossessive", () => {
it("adds a curly ’s when the name does not end in s", () => {
expect(communityPossessive("Juniper Street Food Share")).toBe(
"Juniper Street Food Share’s",
);
});
it("adds only a curly apostrophe when the name ends in s", () => {
expect(communityPossessive("Members")).toBe("Members’");
});
});
describe("clipCommunityInviteDescription", () => {
it("cuts at 140 characters", () => {
const long = "a".repeat(160);
expect(clipCommunityInviteDescription(long)).toHaveLength(140);
});
});
describe("inviteRuleCountsLabel", () => {
it("counts values and other cards, not shared terms", () => {
expect(
inviteRuleCountsLabel({
sections: [
{
categoryName: "Values",
entries: [
{ title: "Care", body: "We care." },
{ title: "Share", body: "We share." },
{ title: "Listen", body: "We listen." },
],
},
{
categoryName: "Communication",
entries: [{ title: "Open channel", body: "We talk in the hall." }],
},
{
categoryName: "Membership",
entries: [{ title: "Open admission", body: "Anyone who shares the work." }],
},
],
}),
).toBe("3 VALUES AND 2 CARDS");
});
});
describe("inviteRuleCountsSpoken", () => {
it("uses lowercase words", () => {
expect(
inviteRuleCountsSpoken({
sections: [
{
categoryName: "Values",
entries: [
{ title: "Care", body: "We care." },
{ title: "Share", body: "We share." },
{ title: "Listen", body: "We listen." },
],
},
{
categoryName: "Communication",
entries: [{ title: "Open channel", body: "How we talk." }],
},
],
}),
).toBe("three values and one card");
});
});