Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+42
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildWalkingSkeletonVM } from "./walking-skeleton.vm.js";
|
||||
|
||||
describe("buildWalkingSkeletonVM", () => {
|
||||
it("builds a ready VM with active content when the module is active", () => {
|
||||
const vm = buildWalkingSkeletonVM({ tenantId: "t1", moduleKey: "walking-skeleton", connectorState: "active" });
|
||||
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data).toMatchObject({
|
||||
tenantId: "t1",
|
||||
moduleKey: "walking-skeleton",
|
||||
connectorState: "active",
|
||||
headlineKey: "walkingSkeleton.active.headline",
|
||||
bodyKey: "walkingSkeleton.active.body",
|
||||
});
|
||||
expect(vm.data?.ctaKey).toBeUndefined();
|
||||
});
|
||||
|
||||
it("builds a ready VM with locked content + upsell CTA when the module is locked", () => {
|
||||
const vm = buildWalkingSkeletonVM({ tenantId: "t1", moduleKey: "walking-skeleton", connectorState: "locked" });
|
||||
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data?.connectorState).toBe("locked");
|
||||
expect(vm.data?.headlineKey).toBe("walkingSkeleton.locked.headline");
|
||||
expect(vm.data?.ctaKey).toBe("walkingSkeleton.locked.cta");
|
||||
});
|
||||
|
||||
it("builds an empty VM when the module is hidden", () => {
|
||||
const vm = buildWalkingSkeletonVM({ tenantId: "t1", moduleKey: "walking-skeleton", connectorState: "hidden" });
|
||||
|
||||
expect(vm.status).toBe("empty");
|
||||
expect(vm.data).toBeUndefined();
|
||||
});
|
||||
|
||||
it("uses only i18n keys, never raw display strings", () => {
|
||||
const vm = buildWalkingSkeletonVM({ tenantId: "t1", moduleKey: "walking-skeleton", connectorState: "active" });
|
||||
const keyPattern = /^[a-z][a-zA-Z0-9]*(?:\.[a-zA-Z0-9]+)+$/;
|
||||
|
||||
expect(vm.data?.headlineKey).toMatch(keyPattern);
|
||||
expect(vm.data?.bodyKey).toMatch(keyPattern);
|
||||
});
|
||||
});
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
/**
|
||||
* Walking-Skeleton View-Model (R-P1c) — die *.vm.ts-Konvention exemplarisch.
|
||||
*
|
||||
* Reine Funktion: der Loader baut sie einmal serverseitig, die UI rendert nur. Kein React,
|
||||
* kein Prisma, keine App-Imports (DoD A.3). Der Konnektor-Zustand (aus `tenantHasModule()` über
|
||||
* `resolveConnectorNavState`) bestimmt, welcher VM-Status/Inhalt entsteht.
|
||||
*/
|
||||
export type WalkingSkeletonConnectorState = "active" | "locked" | "hidden";
|
||||
|
||||
export interface WalkingSkeletonData {
|
||||
readonly tenantId: string;
|
||||
readonly moduleKey: string;
|
||||
readonly connectorState: WalkingSkeletonConnectorState;
|
||||
/** i18n-Key der Überschrift (kein Klartext — DoD i18n). */
|
||||
readonly headlineKey: string;
|
||||
/** i18n-Key des Fließtexts. */
|
||||
readonly bodyKey: string;
|
||||
/** i18n-Key des Upsell-CTA (nur im gesperrten Zustand). */
|
||||
readonly ctaKey?: string;
|
||||
}
|
||||
|
||||
export type WalkingSkeletonVM = VMState<WalkingSkeletonData>;
|
||||
|
||||
export interface BuildWalkingSkeletonVMInput {
|
||||
readonly tenantId: string;
|
||||
readonly moduleKey: string;
|
||||
readonly connectorState: WalkingSkeletonConnectorState;
|
||||
}
|
||||
|
||||
export function buildWalkingSkeletonVM(input: BuildWalkingSkeletonVMInput): WalkingSkeletonVM {
|
||||
if (input.connectorState === "active") {
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
tenantId: input.tenantId,
|
||||
moduleKey: input.moduleKey,
|
||||
connectorState: "active",
|
||||
headlineKey: "walkingSkeleton.active.headline",
|
||||
bodyKey: "walkingSkeleton.active.body",
|
||||
},
|
||||
};
|
||||
}
|
||||
if (input.connectorState === "locked") {
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
tenantId: input.tenantId,
|
||||
moduleKey: input.moduleKey,
|
||||
connectorState: "locked",
|
||||
headlineKey: "walkingSkeleton.locked.headline",
|
||||
bodyKey: "walkingSkeleton.locked.body",
|
||||
ctaKey: "walkingSkeleton.locked.cta",
|
||||
},
|
||||
};
|
||||
}
|
||||
// hidden — die Route sollte für diesen Tenant gar nicht erreichbar sein; defensiv leerer Zustand.
|
||||
return { status: "empty" };
|
||||
}
|
||||
Reference in new issue
Block a user