File
Blob: tests/client/lib/friendly-name.test.ts
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { friendlyName } from "@/client/lib/friendly-name"; |
| 3 | |
| 4 | describe("friendlyName", () => { |
| 5 | it("is deterministic for a given seed", () => { |
| 6 | expect(friendlyName("abc-123")).toBe(friendlyName("abc-123")); |
| 7 | }); |
| 8 | |
| 9 | it("produces distinct names for different seeds with high probability", () => { |
| 10 | const names = new Set<string>(); |
| 11 | for (let i = 0; i < 64; i++) { |
| 12 | names.add(friendlyName(`seed-${i}`)); |
| 13 | } |
| 14 | expect(names.size).toBeGreaterThan(32); |
| 15 | }); |
| 16 | |
| 17 | it("returns a two-word capitalized name", () => { |
| 18 | const name = friendlyName("some-user-id"); |
| 19 | expect(name).toMatch(/^[A-Z][A-Za-z]+ [A-Z][A-Za-z]+$/); |
| 20 | }); |
| 21 | |
| 22 | it("handles empty seed without throwing", () => { |
| 23 | expect(() => friendlyName("")).not.toThrow(); |
| 24 | expect(friendlyName("")).toMatch(/^[A-Z][A-Za-z]+ [A-Z][A-Za-z]+$/); |
| 25 | }); |
| 26 | }); |