Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/view-models/src/auth/select-tenant.branches.test.ts
T
2026-07-08 16:15:37 +02:00

41 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildSelectTenantVM, toTenantCard } from "./select-tenant.vm.js";
describe("toTenantCard initials edge cases (select-tenant.ts:79)", () => {
it("falls back to '?' when the name is blank/whitespace only", () => {
expect(toTenantCard({ id: "t1", name: " ", slug: "blank" }).avatarInitials).toBe("?");
});
it("takes the first two letters of a single-word name", () => {
expect(toTenantCard({ id: "t1", name: "Acme", slug: "acme" }).avatarInitials).toBe("AC");
});
});
describe("buildSelectTenantVM current-tenant sort branches (select-tenant.ts:111)", () => {
it("pulls the current tenant to the front when it sits last in the input", () => {
const vm = buildSelectTenantVM({
tenants: [
{ id: "t1", name: "Alpha", slug: "alpha" },
{ id: "t2", name: "Beta", slug: "beta" },
{ id: "t3", name: "Gamma", slug: "gamma" },
],
currentTenantId: "t3",
});
if (vm.status !== "ready") throw new Error("expected ready");
expect(vm.data.tenants[0].id).toBe("t3");
expect(vm.data.tenants.slice(1).map((c) => c.name)).toEqual(["Alpha", "Beta"]);
});
it("keeps the current tenant first when it already leads the input", () => {
const vm = buildSelectTenantVM({
tenants: [
{ id: "t1", name: "Alpha", slug: "alpha" },
{ id: "t2", name: "Beta", slug: "beta" },
],
currentTenantId: "t1",
});
if (vm.status !== "ready") throw new Error("expected ready");
expect(vm.data.tenants.map((c) => c.id)).toEqual(["t1", "t2"]);
});
});