Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,6 +1,6 @@
import "@testing-library/jest-dom";
import React from "react";
import { render, screen } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { MemoryRouter } from "react-router";
import DashboardRoute, { loader } from "./dashboard";
@@ -17,53 +17,60 @@ import { evaluateDashboardModuleGates, type DashboardModuleGateDecision } from "
import { getDashboardModuleDefinitions, type DashboardModuleDefinition, type DashboardModuleId } from "~/services/dashboard-registry/registry.server";
import { loadDashboardVM } from "~/services/dashboard/dashboard.server";
import { getFirstStepsChecklist } from "~/utils/services/.server/akP20OnboardingService";
import { toFirstStepsChecklistVM } from "@hivegrid/view-models";
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
const translatedT = vi.fn((key: string) => `translated:${key}`);
const computedGte = new Date("2026-02-03T04:05:06.000Z");
const tenant = { id: "tenant_1", slug: "acme" };
const appData = { mySubscription: { products: [], trial: { active: false, period: "trial-ended" } } };
const appData = { mySubscription: { status: "past_due", trialStartsAt: null, trialEndsAt: null, products: [] } };
const stats = [{ name: "Contacts", stat: "7", previousStat: "3" }];
const dashboardData = { users: 4 };
const firstStepsChecklist = {
const firstStepsChecklistSource = {
id: "checklist_1",
status: "active",
dismissed: false,
completedCount: 2,
totalCount: 4,
completedCount: 1,
totalCount: 2,
percentComplete: 50,
items: [],
items: [
{ id: "step_1", block: "profile", titleKey: "onboarding.firstSteps.profile", href: "settings/profile", completed: true, hidden: false },
{ id: "step_2", block: "contacts", titleKey: "onboarding.firstSteps.contacts", href: "contacts", completed: false, hidden: false },
],
};
const firstStepsChecklist = toFirstStepsChecklistVM({
...firstStepsChecklistSource,
items: firstStepsChecklistSource.items.map((item) => ({ ...item, href: `/acme/${item.href}` })),
});
const dashboardVm = {
activeRole: "office",
generatedAt: "2026-07-01T00:00:00.000Z",
streamUrl: "/acme/dashboard.stream?role=office",
liveUpdatesEnabled: true,
streamUrl: "/acme/dashboard.stream",
canCustomize: true,
roles: [
{
role: "office",
nameKey: "app.dashboard.roles.office.name",
descriptionKey: "app.dashboard.roles.office.description",
mobileFirst: false,
isDefault: true,
widgets: [
{
key: "projects.kpis",
titleKey: "app.dashboard.widgets.projectKpis.title",
descriptionKey: "app.dashboard.widgets.projectKpis.description",
domain: "projects",
kind: "kpi",
period: "30d",
visible: true,
loadingMode: "lazy",
metrics: [{ labelKey: "app.dashboard.metrics.activeProjects", value: "3" }],
items: [],
position: { x: 0, y: 1 },
size: { w: 4, h: 2 },
},
],
},
],
layout: {
role: "office",
nameKey: "app.dashboard.roles.office.name",
descriptionKey: "app.dashboard.roles.office.description",
mobileFirst: false,
widgets: [
{
key: "projects.kpis",
titleKey: "app.dashboard.widgets.projectKpis.title",
descriptionKey: "app.dashboard.widgets.projectKpis.description",
domain: "projects",
kind: "kpi",
period: "30d",
visible: true,
loadingMode: "lazy",
metrics: [{ labelKey: "app.dashboard.metrics.activeProjects", value: "3" }],
items: [],
chart: null,
series: null,
position: { x: 0, y: 1 },
size: { w: 4, h: 2 },
},
],
},
};
const registryModules = getDashboardModuleDefinitions();
const getRegistryModule = (moduleId: DashboardModuleId): DashboardModuleDefinition => {
@@ -77,6 +84,7 @@ const summaryModule = getRegistryModule("summary-stats");
const featureGatedModule = getRegistryModule("subscription-health");
const planGatedModule = getRegistryModule("priority-insights");
let routeLoaderData: unknown;
const navigateMock = vi.hoisted(() => vi.fn());
let moduleDecisions: DashboardModuleGateDecision[] = [
{ module: summaryModule, allowed: true },
{
@@ -134,6 +142,7 @@ vi.mock("react-router", async () => {
return {
...actual,
useLoaderData: () => routeLoaderData,
useNavigate: () => navigateMock,
};
});
@@ -158,7 +167,7 @@ vi.mock("~/modules/metrics/utils/defaultHeaders", () => ({
}));
vi.mock("~/components/app/ProfileBanner", () => ({
default: () => null,
default: () => <div data-testid="profile-banner" />,
}));
vi.mock("~/components/ui/stats/DashboardStats", () => ({
@@ -195,11 +204,12 @@ vi.mock("~/utils/helpers/.server/PermissionsService", () => ({
}));
vi.mock("react-i18next", () => ({
useTranslation: vi.fn(() => ({ t: (key: string) => key })),
useTranslation: vi.fn(() => ({ t: (key: string) => key, i18n: { language: "de" } })),
}));
describe("app tenant dashboard route contract", () => {
beforeEach(() => {
navigateMock.mockReset();
vi.clearAllMocks();
process.env.APP_NAME = "HiveGrid";
vi.mocked(getTranslations).mockResolvedValue({ t: translatedT } as never);
@@ -225,7 +235,8 @@ describe("app tenant dashboard route contract", () => {
vi.mocked(loadAppData).mockResolvedValue(appData as never);
vi.mocked(evaluateDashboardModuleGates).mockResolvedValue(moduleDecisions as never);
vi.mocked(loadDashboardVM).mockResolvedValue(dashboardVm as never);
vi.mocked(getFirstStepsChecklist).mockResolvedValue(firstStepsChecklist as never);
vi.mocked(getFirstStepsChecklist).mockResolvedValue(firstStepsChecklistSource as never);
vi.mocked(getUserHasPermission).mockReturnValue(true);
vi.mocked(getAppDashboardStats).mockResolvedValue(stats as never);
vi.mocked(loadDashboardData).mockResolvedValue(dashboardData as never);
vi.mocked(PeriodHelper.getGreaterThanOrEqualsFromRequest).mockReturnValue(computedGte);
@@ -291,6 +302,27 @@ describe("app tenant dashboard route contract", () => {
}
});
it("does not load or render the checklist without checklist permission", async () => {
vi.mocked(getUserHasPermission).mockImplementation((_data, permission) => permission !== "app.onboarding.checklist.update");
const request = new Request("https://example.com/acme/dashboard");
const params = { tenant: "acme" };
const response = (await loader({ request, params, context: {}, unstable_pattern: "app.$tenant/dashboard" })) as Response;
const body = await response.json();
expect(getFirstStepsChecklist).not.toHaveBeenCalled();
expect(body.firstStepsChecklist).toEqual({ status: "empty" });
routeLoaderData = body;
vi.mocked(getUserHasPermission).mockReturnValue(true);
render(
<MemoryRouter>
<DashboardRoute />
</MemoryRouter>
);
expect(screen.queryByText("onboarding.firstSteps.dashboardTitle")).not.toBeInTheDocument();
});
it("renders the allowed summary registry module with the existing dashboard stats", () => {
render(
<MemoryRouter>
@@ -301,9 +333,17 @@ describe("app tenant dashboard route contract", () => {
expect(screen.getByRole("heading", { name: "app.dashboard.summary" })).toBeInTheDocument();
expect(screen.getByText("Contacts")).toBeInTheDocument();
expect(screen.getByText("7")).toBeInTheDocument();
expect(screen.queryByTestId("profile-banner")).not.toBeInTheDocument();
expect(screen.getByText("onboarding.firstSteps.dashboardTitle")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "onboarding.firstSteps.open" })).toHaveAttribute("href", "/onboarding/checklist");
expect(screen.getByRole("button", { name: "onboarding.firstSteps.open" })).toBeEnabled();
fireEvent.click(screen.getByRole("button", { name: "onboarding.firstSteps.open" }));
expect(navigateMock).toHaveBeenCalledWith("../onboarding/checklist");
expect(screen.queryByText("app.dashboard.moduleDiagnostics.unavailableTitle")).not.toBeInTheDocument();
// R-P11b interim screen (AD-28): the widget grid renders the single layout the
// loader derived; there is no role switcher to pick another one.
expect(document.querySelector("[data-ui-id^='ui.dashboard.roleSwitcher']")).not.toBeInTheDocument();
expect(document.querySelector('[data-ui-id="ui.dashboard.widget.projects.kpis"]')).toBeInTheDocument();
expect(document.querySelector('[data-ui-id="ui.dashboard.live.toggle"]')).not.toBeInTheDocument();
});
it("omits gated summary content when the summary module is feature-disabled", () => {
@@ -324,9 +364,7 @@ describe("app tenant dashboard route contract", () => {
expect(screen.queryByRole("heading", { name: "app.dashboard.summary" })).not.toBeInTheDocument();
expect(screen.queryByText("Contacts")).not.toBeInTheDocument();
expect(screen.getByText("app.dashboard.moduleDiagnostics.unavailableTitle")).toBeInTheDocument();
expect(screen.getByText("app.dashboard.moduleDiagnostics.unavailableDescription")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "app.dashboard.moduleDiagnostics.learnMore" })).toHaveAttribute("href", "/feature-disabled?tenant=acme");
expect(screen.queryByText("app.dashboard.moduleDiagnostics.unavailableTitle")).not.toBeInTheDocument();
});
it("renders plan-required diagnostics with the safe tenant-aware plan link and no gated module content", () => {
@@ -351,7 +389,7 @@ describe("app tenant dashboard route contract", () => {
expect(screen.queryByText(planGatedModule.titleKey)).not.toBeInTheDocument();
});
it("renders feature-disabled diagnostics with only the safe fallback link and no gated module content", () => {
it("suppresses feature-disabled diagnostics entirely while still hiding the gated module content", () => {
routeLoaderData = {
...dashboardData,
dashboard: dashboardVm,
@@ -369,9 +407,8 @@ describe("app tenant dashboard route contract", () => {
</MemoryRouter>
);
expect(screen.getByText("app.dashboard.moduleDiagnostics.unavailableTitle")).toBeInTheDocument();
expect(screen.getByText("app.dashboard.moduleDiagnostics.unavailableDescription")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "app.dashboard.moduleDiagnostics.learnMore" })).toHaveAttribute("href", "/feature-disabled");
expect(screen.queryByText("app.dashboard.moduleDiagnostics.unavailableTitle")).not.toBeInTheDocument();
expect(screen.queryByRole("link", { name: "app.dashboard.moduleDiagnostics.learnMore" })).not.toBeInTheDocument();
expect(screen.queryByText(featureGatedModule.titleKey)).not.toBeInTheDocument();
});