From 382d622521c3143d1b71ccf46dc5a806215980c5 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Thu, 30 Apr 2026 20:25:00 -0700 Subject: [PATCH] Add team names utility tests --- app/utils/__tests__/team-names.test.ts | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 app/utils/__tests__/team-names.test.ts diff --git a/app/utils/__tests__/team-names.test.ts b/app/utils/__tests__/team-names.test.ts new file mode 100644 index 0000000..157f4a5 --- /dev/null +++ b/app/utils/__tests__/team-names.test.ts @@ -0,0 +1,85 @@ +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" + ); + }); +});