86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
|
|
import { describe, it, expect } from "vitest";
|
||
|
|
import {
|
||
|
|
prependOwnerToTeamName,
|
||
|
|
stripOwnerFromTeamName,
|
||
|
|
} from "~/utils/team-names";
|
||
|
|
|
||
|
|
describe("prependOwnerToTeamName", () => {
|
||
|
|
it("prepends username with 's possessive", () => {
|
||
|
|
expect(prependOwnerToTeamName("Kind Cobras", "bob")).toBe(
|
||
|
|
"Bob's Kind Cobras"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("uses ' possessive when username ends in s", () => {
|
||
|
|
expect(prependOwnerToTeamName("Kind Cobras", "chris")).toBe(
|
||
|
|
"Chris' Kind Cobras"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("capitalizes first letter of username", () => {
|
||
|
|
expect(prependOwnerToTeamName("Furious Penguins", "christhrowsrock")).toBe(
|
||
|
|
"Christhrowsrock's Furious Penguins"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("handles username already capitalized", () => {
|
||
|
|
expect(prependOwnerToTeamName("Bold Bears", "Alice")).toBe(
|
||
|
|
"Alice's Bold Bears"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("handles name ending in multiple s characters", () => {
|
||
|
|
expect(prependOwnerToTeamName("Mighty Tigers", "jess")).toBe(
|
||
|
|
"Jess' Mighty Tigers"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("handles display name fallback", () => {
|
||
|
|
expect(prependOwnerToTeamName("Wild Wolves", "Member")).toBe(
|
||
|
|
"Member's Wild Wolves"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("handles single character username", () => {
|
||
|
|
expect(prependOwnerToTeamName("Team 1", "s")).toBe("S's Team 1");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("handles empty base name", () => {
|
||
|
|
expect(prependOwnerToTeamName("", "bob")).toBe("Bob's ");
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("stripOwnerFromTeamName", () => {
|
||
|
|
it("strips 's possessive prefix", () => {
|
||
|
|
expect(stripOwnerFromTeamName("Bob's Kind Cobras", "bob")).toBe(
|
||
|
|
"Kind Cobras"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("strips ' possessive prefix for names ending in s", () => {
|
||
|
|
expect(stripOwnerFromTeamName("Chris' Kind Cobras", "chris")).toBe(
|
||
|
|
"Kind Cobras"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("returns name unchanged if prefix does not match", () => {
|
||
|
|
expect(
|
||
|
|
stripOwnerFromTeamName("Alice's Awesome Team", "bob")
|
||
|
|
).toBe("Alice's Awesome Team");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("handles title case mismatch in username", () => {
|
||
|
|
expect(stripOwnerFromTeamName("Bob's Team", "bob")).toBe("Team");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("returns name unchanged if renamed by owner", () => {
|
||
|
|
expect(stripOwnerFromTeamName("Custom Name", "bob")).toBe("Custom Name");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("handles username ending in s matching 's prefix", () => {
|
||
|
|
expect(stripOwnerFromTeamName("Jess' Wild Wolves", "jess")).toBe(
|
||
|
|
"Wild Wolves"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
});
|