Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+51
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { toDemoDataSettingsVM } from "./demo-data-settings.vm.js";
|
||||
|
||||
describe("toDemoDataSettingsVM", () => {
|
||||
it("offers provisioning only when the environment gate is enabled", () => {
|
||||
const vm = toDemoDataSettingsVM({ demoDataUiEnabled: true, provisioning: null });
|
||||
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data).toMatchObject({ hasDemoData: false, canCreate: true, canDelete: false, totalCount: 0 });
|
||||
});
|
||||
|
||||
it("keeps production cleanup available for tracked demo rows", () => {
|
||||
const vm = toDemoDataSettingsVM({
|
||||
demoDataUiEnabled: false,
|
||||
provisioning: {
|
||||
id: "demo_1",
|
||||
entitiesCreated: { kontakt: ["k1", "k2"], projekt: ["p1"], task: ["t1", "t2", "t3"] },
|
||||
createdAt: new Date("2026-07-01T08:00:00.000Z"),
|
||||
removableUntil: "2026-07-31T08:00:00.000Z",
|
||||
},
|
||||
});
|
||||
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data).toMatchObject({
|
||||
provisioningId: "demo_1",
|
||||
hasDemoData: true,
|
||||
canCreate: false,
|
||||
canDelete: true,
|
||||
totalCount: 6,
|
||||
environmentNoticeKey: "onboarding.demoData.environment.productionCleanup",
|
||||
createdAt: "2026-07-01T08:00:00.000Z",
|
||||
});
|
||||
expect(vm.data?.entities.map((entity) => [entity.kind, entity.count])).toEqual([
|
||||
["contacts", 2],
|
||||
["projects", 1],
|
||||
["tasks", 3],
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns an empty state when production has nothing left to clean up", () => {
|
||||
expect(toDemoDataSettingsVM({ demoDataUiEnabled: false, provisioning: null })).toEqual({ status: "empty" });
|
||||
});
|
||||
|
||||
it("maps loader failures to a localized error state", () => {
|
||||
expect(toDemoDataSettingsVM({ demoDataUiEnabled: true, provisioning: null, errorKey: "onboarding.demoData.error.body" })).toEqual({
|
||||
status: "error",
|
||||
error: { messageKey: "onboarding.demoData.error.body" },
|
||||
});
|
||||
});
|
||||
});
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
export type DemoDataEntityKind = "contacts" | "projects" | "tasks";
|
||||
|
||||
export type DemoDataEntitySummaryVM = {
|
||||
readonly kind: DemoDataEntityKind;
|
||||
readonly labelKey: string;
|
||||
readonly count: number;
|
||||
};
|
||||
|
||||
export type DemoDataSettingsData = {
|
||||
readonly titleKey: string;
|
||||
readonly descriptionKey: string;
|
||||
readonly provisioningId: string | null;
|
||||
readonly hasDemoData: boolean;
|
||||
readonly canCreate: boolean;
|
||||
readonly canDelete: boolean;
|
||||
readonly environmentNoticeKey: string;
|
||||
readonly statusLabelKey: string;
|
||||
readonly entities: readonly DemoDataEntitySummaryVM[];
|
||||
readonly totalCount: number;
|
||||
readonly createdAt: string | null;
|
||||
readonly removableUntil: string | null;
|
||||
};
|
||||
|
||||
export type DemoDataSettingsVM = VMState<DemoDataSettingsData>;
|
||||
|
||||
export type DemoDataProvisioningInput = {
|
||||
readonly id: string;
|
||||
readonly status?: string | null;
|
||||
readonly entitiesCreated?: unknown;
|
||||
readonly createdAt?: Date | string | null;
|
||||
readonly removableUntil?: Date | string | null;
|
||||
};
|
||||
|
||||
export type DemoDataSettingsVMInput = {
|
||||
readonly demoDataUiEnabled: boolean;
|
||||
readonly provisioning: DemoDataProvisioningInput | null;
|
||||
readonly errorKey?: string;
|
||||
};
|
||||
|
||||
const ENTITY_DEFINITIONS = [
|
||||
{ sourceKey: "kontakt", kind: "contacts", labelKey: "onboarding.demoData.entities.contacts" },
|
||||
{ sourceKey: "projekt", kind: "projects", labelKey: "onboarding.demoData.entities.projects" },
|
||||
{ sourceKey: "task", kind: "tasks", labelKey: "onboarding.demoData.entities.tasks" },
|
||||
] as const;
|
||||
|
||||
function toIsoString(value: Date | string | null | undefined): string | null {
|
||||
if (!value) return null;
|
||||
const date = value instanceof Date ? value : new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? null : date.toISOString();
|
||||
}
|
||||
|
||||
function entityCount(entitiesCreated: unknown, key: string): number {
|
||||
if (!entitiesCreated || typeof entitiesCreated !== "object" || Array.isArray(entitiesCreated)) return 0;
|
||||
const value = (entitiesCreated as Record<string, unknown>)[key];
|
||||
return Array.isArray(value) ? value.length : 0;
|
||||
}
|
||||
|
||||
export function toDemoDataSettingsVM(input: DemoDataSettingsVMInput): DemoDataSettingsVM {
|
||||
if (input.errorKey) {
|
||||
return { status: "error", error: { messageKey: input.errorKey } };
|
||||
}
|
||||
|
||||
if (!input.demoDataUiEnabled && !input.provisioning) {
|
||||
return { status: "empty" };
|
||||
}
|
||||
|
||||
const provisioning = input.provisioning;
|
||||
const entities = ENTITY_DEFINITIONS.map((definition) => ({
|
||||
kind: definition.kind,
|
||||
labelKey: definition.labelKey,
|
||||
count: entityCount(provisioning?.entitiesCreated, definition.sourceKey),
|
||||
}));
|
||||
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
titleKey: "onboarding.demoData.title",
|
||||
descriptionKey: "onboarding.demoData.description",
|
||||
provisioningId: provisioning?.id ?? null,
|
||||
hasDemoData: Boolean(provisioning),
|
||||
canCreate: input.demoDataUiEnabled && !provisioning,
|
||||
canDelete: Boolean(provisioning),
|
||||
environmentNoticeKey: input.demoDataUiEnabled ? "onboarding.demoData.environment.nonProduction" : "onboarding.demoData.environment.productionCleanup",
|
||||
statusLabelKey: provisioning ? "onboarding.demoData.status.active" : "onboarding.demoData.status.empty",
|
||||
entities,
|
||||
totalCount: entities.reduce((total, entity) => total + entity.count, 0),
|
||||
createdAt: toIsoString(provisioning?.createdAt),
|
||||
removableUntil: toIsoString(provisioning?.removableUntil),
|
||||
},
|
||||
};
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { toFirstStepsChecklistVM } from "./first-steps-checklist.vm.js";
|
||||
|
||||
const items = [
|
||||
{ id: "step_1", block: "profile", titleKey: "onboarding.firstSteps.profile", href: "settings/profile", completed: true },
|
||||
{ id: "step_2", block: "contacts", titleKey: "onboarding.firstSteps.contacts", href: "contacts", completed: false },
|
||||
] as const;
|
||||
|
||||
describe("toFirstStepsChecklistVM", () => {
|
||||
it("derives progress and per-item actions from the checklist rows", () => {
|
||||
const vm = toFirstStepsChecklistVM({ id: "session_1", status: "active", dismissed: false, items });
|
||||
|
||||
expect(vm.status).toBe("ready");
|
||||
expect(vm.data).toMatchObject({ completedCount: 1, totalCount: 2, percentComplete: 50, isComplete: false, status: "active" });
|
||||
expect(vm.data?.items[0]).toMatchObject({ state: "completed", canComplete: false });
|
||||
expect(vm.data?.items[1]).toMatchObject({ state: "pending", canComplete: true });
|
||||
});
|
||||
|
||||
it("marks a fully completed checklist as complete", () => {
|
||||
const vm = toFirstStepsChecklistVM({
|
||||
id: "session_1",
|
||||
status: "active",
|
||||
dismissed: false,
|
||||
items: items.map((item) => ({ ...item, completed: true })),
|
||||
});
|
||||
|
||||
expect(vm.data).toMatchObject({ status: "completed", isComplete: true, percentComplete: 100 });
|
||||
expect(vm.data?.progressLabelKey).toBe("onboarding.firstSteps.dashboardComplete");
|
||||
});
|
||||
|
||||
it("disables item actions after the checklist is dismissed", () => {
|
||||
const vm = toFirstStepsChecklistVM({ id: "session_1", status: "dismissed", dismissed: true, items });
|
||||
|
||||
expect(vm.data).toMatchObject({ status: "dismissed", dismissed: true });
|
||||
expect(vm.data?.items.every((item) => item.hidden && !item.canComplete)).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps automatically detected steps read-only until their condition is met", () => {
|
||||
const vm = toFirstStepsChecklistVM({
|
||||
id: "session_1",
|
||||
status: "active",
|
||||
dismissed: false,
|
||||
items: [...items, { id: "team", block: "team", titleKey: "onboarding.firstSteps.team", href: "settings/team/members/new", completed: false, canComplete: false }],
|
||||
});
|
||||
|
||||
expect(vm.data?.items.find((item) => item.id === "team")).toMatchObject({ completed: false, canComplete: false });
|
||||
});
|
||||
|
||||
it("uses explicit empty and error states", () => {
|
||||
expect(toFirstStepsChecklistVM({ id: "session_1", status: "active", dismissed: false, items: [] })).toEqual({ status: "empty" });
|
||||
expect(toFirstStepsChecklistVM({ id: "session_1", status: "active", dismissed: false, items, errorKey: "onboarding.firstSteps.error.body" })).toEqual({
|
||||
status: "error",
|
||||
error: { messageKey: "onboarding.firstSteps.error.body" },
|
||||
});
|
||||
});
|
||||
});
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
export type FirstStepsChecklistItemInput = {
|
||||
readonly id: string;
|
||||
readonly block: string;
|
||||
readonly titleKey: string;
|
||||
readonly href: string;
|
||||
readonly completed: boolean;
|
||||
readonly hidden?: boolean;
|
||||
readonly canComplete?: boolean;
|
||||
};
|
||||
|
||||
export type FirstStepsChecklistInput = {
|
||||
readonly id: string;
|
||||
readonly status: string;
|
||||
readonly dismissed: boolean;
|
||||
readonly items: readonly FirstStepsChecklistItemInput[];
|
||||
readonly errorKey?: string;
|
||||
};
|
||||
|
||||
export type FirstStepsChecklistItemVM = FirstStepsChecklistItemInput & {
|
||||
readonly state: "pending" | "completed";
|
||||
readonly statusLabelKey: string;
|
||||
readonly canComplete: boolean;
|
||||
};
|
||||
|
||||
export type FirstStepsChecklistData = {
|
||||
readonly id: string;
|
||||
readonly status: "active" | "completed" | "dismissed";
|
||||
readonly dismissed: boolean;
|
||||
readonly isComplete: boolean;
|
||||
readonly completedCount: number;
|
||||
readonly totalCount: number;
|
||||
readonly percentComplete: number;
|
||||
readonly progressLabelKey: string;
|
||||
readonly items: readonly FirstStepsChecklistItemVM[];
|
||||
};
|
||||
|
||||
export type FirstStepsChecklistVM = VMState<FirstStepsChecklistData>;
|
||||
|
||||
export function toFirstStepsChecklistVM(input: FirstStepsChecklistInput): FirstStepsChecklistVM {
|
||||
if (input.errorKey) {
|
||||
return { status: "error", error: { messageKey: input.errorKey } };
|
||||
}
|
||||
|
||||
if (input.items.length === 0) {
|
||||
return { status: "empty" };
|
||||
}
|
||||
|
||||
const dismissed = input.dismissed || input.status === "dismissed";
|
||||
const items = input.items.map(
|
||||
(item): FirstStepsChecklistItemVM => ({
|
||||
...item,
|
||||
hidden: dismissed || Boolean(item.hidden),
|
||||
state: item.completed ? "completed" : "pending",
|
||||
statusLabelKey: item.completed ? "onboarding.firstSteps.completed" : "onboarding.firstSteps.pending",
|
||||
canComplete: !dismissed && !item.completed && (item.canComplete ?? true),
|
||||
})
|
||||
);
|
||||
const completedCount = items.filter((item) => item.completed).length;
|
||||
const totalCount = items.length;
|
||||
const isComplete = completedCount === totalCount;
|
||||
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
id: input.id,
|
||||
status: dismissed ? "dismissed" : isComplete || input.status === "completed" ? "completed" : "active",
|
||||
dismissed,
|
||||
isComplete,
|
||||
completedCount,
|
||||
totalCount,
|
||||
percentComplete: Math.round((completedCount / totalCount) * 100),
|
||||
progressLabelKey: isComplete ? "onboarding.firstSteps.dashboardComplete" : "onboarding.firstSteps.dashboardProgress",
|
||||
items,
|
||||
},
|
||||
};
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { toFirstStepsChecklistVM } from "./first-steps-checklist.vm.js";
|
||||
import { toWelcomeSetupVM } from "./welcome-setup.vm.js";
|
||||
|
||||
const checklist = toFirstStepsChecklistVM({
|
||||
id: "session_1",
|
||||
status: "active",
|
||||
dismissed: false,
|
||||
items: [
|
||||
{ id: "profile", block: "profile", titleKey: "onboarding.firstSteps.profile", href: "/acme/settings/profile", completed: true },
|
||||
{ id: "team", block: "team", titleKey: "onboarding.firstSteps.team", href: "/acme/settings/team/members/new", completed: false, canComplete: false },
|
||||
],
|
||||
});
|
||||
|
||||
describe("toWelcomeSetupVM", () => {
|
||||
it("exposes the first unfinished setup task without recomputing checklist progress", () => {
|
||||
const vm = toWelcomeSetupVM({ firstName: " Ada ", workspaceName: "Lovelace Elektro", dashboardHref: "/acme/dashboard", checklist });
|
||||
|
||||
expect(vm).toMatchObject({
|
||||
status: "ready",
|
||||
data: {
|
||||
firstName: "Ada",
|
||||
workspaceName: "Lovelace Elektro",
|
||||
dashboardHref: "/acme/dashboard",
|
||||
nextItem: { id: "team" },
|
||||
checklist: { completedCount: 1, totalCount: 2, percentComplete: 50 },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves explicit checklist states", () => {
|
||||
expect(toWelcomeSetupVM({ firstName: null, workspaceName: "Acme", dashboardHref: "/acme/dashboard", checklist: { status: "empty" } })).toEqual({
|
||||
status: "empty",
|
||||
});
|
||||
expect(
|
||||
toWelcomeSetupVM({
|
||||
firstName: null,
|
||||
workspaceName: "Acme",
|
||||
dashboardHref: "/acme/dashboard",
|
||||
checklist: { status: "error", error: { messageKey: "onboarding.firstSteps.error.body" } },
|
||||
})
|
||||
).toEqual({ status: "error", error: { messageKey: "onboarding.firstSteps.error.body" } });
|
||||
});
|
||||
});
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import type { FirstStepsChecklistVM } from "./first-steps-checklist.vm.js";
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
export type WelcomeSetupData = {
|
||||
readonly firstName: string | null;
|
||||
readonly workspaceName: string;
|
||||
readonly dashboardHref: string;
|
||||
readonly checklist: NonNullable<FirstStepsChecklistVM["data"]>;
|
||||
readonly nextItem: NonNullable<FirstStepsChecklistVM["data"]>["items"][number] | null;
|
||||
};
|
||||
|
||||
export type WelcomeSetupVM = VMState<WelcomeSetupData>;
|
||||
|
||||
export function toWelcomeSetupVM(input: {
|
||||
readonly firstName: string | null;
|
||||
readonly workspaceName: string;
|
||||
readonly dashboardHref: string;
|
||||
readonly checklist: FirstStepsChecklistVM;
|
||||
}): WelcomeSetupVM {
|
||||
if (input.checklist.status === "error") {
|
||||
return { status: "error", error: input.checklist.error };
|
||||
}
|
||||
if (input.checklist.status !== "ready" || !input.checklist.data) {
|
||||
return input.checklist.status === "loading" || input.checklist.status === "idle" ? { status: input.checklist.status } : { status: "empty" };
|
||||
}
|
||||
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
firstName: input.firstName?.trim() || null,
|
||||
workspaceName: input.workspaceName,
|
||||
dashboardHref: input.dashboardHref,
|
||||
checklist: input.checklist.data,
|
||||
nextItem: input.checklist.data.items.find((item) => !item.completed) ?? null,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user