- Create gotoLogin() helper for login redirects with search params - Add /terms and /privacy public routes with Tailwind typography - Update auth-guard to allow unauthenticated access to public pages - Fix resolve() usage across navigation components using as const pattern - Fix eslint-disable-next-line placement for svelte/no-navigation-without-resolve - Document SvelteKit resolve() patterns in CLAUDE.md Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
85 lines
2.1 KiB
TypeScript
85 lines
2.1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { formatRole, getUserInitials } from "./user.js";
|
|
|
|
describe("getUserInitials", () => {
|
|
test("returns '??' for null", () => {
|
|
expect(getUserInitials(null)).toBe("??");
|
|
});
|
|
|
|
test("returns '??' for undefined", () => {
|
|
expect(getUserInitials(undefined)).toBe("??");
|
|
});
|
|
|
|
test("returns initials from display name with two words", () => {
|
|
expect(
|
|
getUserInitials({ displayName: "John Doe", email: "john@example.com" }),
|
|
).toBe("JD");
|
|
});
|
|
|
|
test("returns initials from display name with multiple words", () => {
|
|
expect(
|
|
getUserInitials({
|
|
displayName: "John Michael Doe",
|
|
email: "john@example.com",
|
|
}),
|
|
).toBe("JD");
|
|
});
|
|
|
|
test("returns first two characters for single word display name", () => {
|
|
expect(
|
|
getUserInitials({ displayName: "John", email: "john@example.com" }),
|
|
).toBe("JO");
|
|
});
|
|
|
|
test("returns uppercase initials", () => {
|
|
expect(
|
|
getUserInitials({
|
|
displayName: "john doe",
|
|
email: "john@example.com",
|
|
}),
|
|
).toBe("JD");
|
|
});
|
|
|
|
test("falls back to email when no display name", () => {
|
|
expect(getUserInitials({ email: "john@example.com" })).toBe("JO");
|
|
});
|
|
|
|
test("handles null display name", () => {
|
|
expect(
|
|
getUserInitials({ displayName: null, email: "alice@example.com" }),
|
|
).toBe("AL");
|
|
});
|
|
|
|
test("handles empty display name", () => {
|
|
expect(getUserInitials({ displayName: "", email: "bob@example.com" })).toBe(
|
|
"BO",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("formatRole", () => {
|
|
test("capitalizes 'admin'", () => {
|
|
expect(formatRole("admin")).toBe("Admin");
|
|
});
|
|
|
|
test("capitalizes 'member'", () => {
|
|
expect(formatRole("member")).toBe("Member");
|
|
});
|
|
|
|
test("capitalizes 'owner'", () => {
|
|
expect(formatRole("owner")).toBe("Owner");
|
|
});
|
|
|
|
test("handles already capitalized roles", () => {
|
|
expect(formatRole("Admin")).toBe("Admin");
|
|
});
|
|
|
|
test("handles single character", () => {
|
|
expect(formatRole("a")).toBe("A");
|
|
});
|
|
|
|
test("handles empty string", () => {
|
|
expect(formatRole("")).toBe("");
|
|
});
|
|
});
|