Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSelectTenantVM, toTenantCard, type SelectTenantInput } from "./select-tenant.vm.js";
|
||||
|
||||
function tenant(overrides: Partial<SelectTenantInput> & { id: string; name: string; slug: string }): SelectTenantInput {
|
||||
return { ...overrides };
|
||||
}
|
||||
|
||||
describe("buildSelectTenantVM", () => {
|
||||
it("returns an empty state when the user has no tenants", () => {
|
||||
expect(buildSelectTenantVM({ tenants: [] })).toEqual({ status: "empty" });
|
||||
});
|
||||
|
||||
it("maps tenants to cards, derives initials, and assigns the role tag + tone", () => {
|
||||
const vm = buildSelectTenantVM({
|
||||
tenants: [tenant({ id: "t1", name: "Berger Bad", slug: "berger-bad", role: "owner", subtitle: "t.berger@berger-bad.de" })],
|
||||
});
|
||||
expect(vm.status).toBe("ready");
|
||||
const card = vm.data!.tenants[0];
|
||||
expect(card.avatarInitials).toBe("BB");
|
||||
expect(card.role).toBe("owner");
|
||||
expect(card.roleLabelKey).toBe("account.selectTenant.role.owner");
|
||||
expect(card.roleTone).toBe("red-subtle");
|
||||
expect(card.subtitle).toBe("t.berger@berger-bad.de");
|
||||
expect(vm.data!.totalCount).toBe(1);
|
||||
});
|
||||
|
||||
it("uses the image and a neutral avatar color when a logo/icon is present", () => {
|
||||
const card = toTenantCard({ id: "t1", name: "Acme", slug: "acme", image: "https://x/y.png" });
|
||||
expect(card.avatarImage).toBe("https://x/y.png");
|
||||
expect(card.avatarColor).toBe("neutral");
|
||||
});
|
||||
|
||||
it("derives a deterministic avatar color from the id when no image is present", () => {
|
||||
const a = toTenantCard({ id: "t1", name: "Acme", slug: "acme" });
|
||||
const b = toTenantCard({ id: "t1", name: "Acme", slug: "acme" });
|
||||
expect(a.avatarColor).toBe(b.avatarColor);
|
||||
expect(a.avatarColor).not.toBe("neutral");
|
||||
expect(a.roleLabelKey).toBeUndefined();
|
||||
expect(a.roleTone).toBeUndefined();
|
||||
});
|
||||
|
||||
it("flags and sorts the current/last-used tenant to the front", () => {
|
||||
const vm = buildSelectTenantVM({
|
||||
tenants: [
|
||||
tenant({ id: "t1", name: "Zeta", slug: "zeta" }),
|
||||
tenant({ id: "t2", name: "Alpha", slug: "alpha" }),
|
||||
tenant({ id: "t3", name: "Mu", slug: "mu" }),
|
||||
],
|
||||
currentTenantId: "t3",
|
||||
});
|
||||
expect(vm.data!.tenants[0].id).toBe("t3");
|
||||
expect(vm.data!.tenants[0].isCurrent).toBe(true);
|
||||
// restliche alphabetisch
|
||||
expect(vm.data!.tenants.slice(1).map((c) => c.name)).toEqual(["Alpha", "Zeta"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user