Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/view-models/src/index.test.ts
T

28 lines
1.1 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { assertI18nLabel, empty, ready, type ActionCallbacks, type SidebarRegistryItem, type VMState } from "./index.js";
describe("@toolctrl/view-models", () => {
test("exports serializable VM state helpers", () => {
expect(ready({ id: "1" })).toEqual({ status: "ready", data: { id: "1" } } satisfies VMState<{ id: string }>);
expect(empty()).toEqual({ status: "empty" });
});
test("keeps action callbacks generic and UI-free", async () => {
const calls: string[] = [];
const callbacks: ActionCallbacks<{ id: string }> = {
onUpdate: async (item) => {
calls.push(item.id);
},
};
await callbacks.onUpdate?.({ id: "item_1" });
expect(calls).toEqual(["item_1"]);
});
test("requires i18n-key labels for shell registries", () => {
const item: SidebarRegistryItem = { id: "home", href: "/", labelKey: "shell.nav.home", permission: "resource.view" };
expect(assertI18nLabel(item)).toBe(item);
expect(() => assertI18nLabel({ labelKey: "Home" })).toThrow(/i18n keys/);
});
});