Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/utils/app/SubscriptionFeatureText.test.ts
T

50 lines
2.6 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import { featureGateRegistry } from "@hivegrid/entitlements";
import { getSubscriptionFeatureBadge, getSubscriptionFeatureTitle, getSubscriptionFeatureTitleKey } from "./SubscriptionFeatureText";
function localeCatalog(locale: "de" | "en") {
const repositoryRoot = process.cwd();
return JSON.parse(fs.readFileSync(path.join(repositoryRoot, `apps/web/public/locales/${locale}/translations.json`), "utf8")) as {
admin?: { connectors?: { feature?: Record<string, string> } };
};
}
describe("subscription feature text", () => {
it("resolves known feature names through their stable catalog key", () => {
expect(getSubscriptionFeatureTitleKey({ name: "workflow-engine", title: "Workflows" })).toBe("admin.connectors.feature.workflow-engine");
expect(
getSubscriptionFeatureTitle((key) => (key === "admin.connectors.feature.workflow-engine" ? "Workflow-Engine" : key), {
name: "workflow-engine",
title: "Workflows",
})
).toBe("Workflow-Engine");
});
it("keeps custom feature copy verbatim without treating it as a translation key", () => {
const t = vi.fn((key: string) => `translated:${key}`);
const feature = { name: "tenant-custom-report", title: "Monatsreport für Nord" };
expect(getSubscriptionFeatureTitleKey(feature)).toBe(feature.title);
expect(getSubscriptionFeatureTitle(t, feature)).toBe(feature.title);
expect(t).not.toHaveBeenCalled();
});
it("falls back to the persisted legacy title when a known catalog entry cannot be loaded", () => {
expect(getSubscriptionFeatureTitle((key) => key, { name: "tasks", title: "Tasks" })).toBe("Tasks");
});
it("localizes only canonical system badges and preserves customized badges", () => {
const t = (key: string) => (key === "admin.connectors.feature.tasks" ? "Aufgaben" : key);
expect(getSubscriptionFeatureBadge(t, { name: "tasks", title: "Tasks", badge: "Tasks" })).toBe("Aufgaben");
expect(getSubscriptionFeatureBadge(t, { name: "tasks", title: "Tasks", badge: "Bestseller" })).toBe("Bestseller");
expect(getSubscriptionFeatureBadge(t, { name: "tenant-custom", title: "Custom", badge: "Kundenspezifisch" })).toBe("Kundenspezifisch");
});
it.each(["en", "de"] as const)("has a %s catalog entry for every known system feature", (locale) => {
const featureCatalog = localeCatalog(locale).admin?.connectors?.feature ?? {};
expect(featureGateRegistry.map((feature) => feature.key).filter((key) => !featureCatalog[key])).toEqual([]);
});
});