Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,141 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { loader } from "./dashboard";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { getAdminDashboardStats } from "~/utils/services/adminDashboardService";
|
||||
import { getSetupSteps } from "~/utils/services/setupService";
|
||||
import { adminGetAllTenantsWithUsage } from "~/utils/db/tenants.db.server";
|
||||
import PeriodHelper from "~/utils/helpers/PeriodHelper";
|
||||
import { createMetrics } from "~/modules/metrics/services/.server/MetricTracker";
|
||||
import { requireAuth } from "~/utils/loaders.middleware";
|
||||
import { readRepoFile } from "~/utils/testing/repoPaths";
|
||||
|
||||
const translatedT = vi.fn((key: string) => `translated:${key}`);
|
||||
const computedGte = new Date("2026-02-03T04:05:06.000Z");
|
||||
const stats = [{ name: "Translated accounts", stat: "10" }];
|
||||
const setupSteps = [{ title: "Setup", completed: true }];
|
||||
const tenants = { items: [{ id: "tenant-1" }], pagination: { page: 1, pageSize: 10, totalItems: 1, totalPages: 1 } };
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/services/adminDashboardService", () => ({
|
||||
getAdminDashboardStats: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/services/setupService", () => ({
|
||||
getSetupSteps: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/tenants.db.server", () => ({
|
||||
adminGetAllTenantsWithUsage: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/helpers/PeriodHelper", () => ({
|
||||
default: { getGreaterThanOrEqualsFromRequest: vi.fn() },
|
||||
defaultPeriodFilter: "30d",
|
||||
PeriodFilters: [],
|
||||
}));
|
||||
|
||||
vi.mock("~/modules/metrics/services/.server/MetricTracker", () => ({
|
||||
createMetrics: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/loaders.middleware", () => ({
|
||||
requireAuth: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/helpers/RowPaginationHelper", () => ({
|
||||
getPaginationFromCurrentUrl: vi.fn(() => ({ page: 1, pageSize: 10 })),
|
||||
}));
|
||||
|
||||
vi.mock("~/modules/metrics/utils/defaultHeaders", () => ({
|
||||
serverTimingHeaders: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/stats/DashboardStats", () => ({
|
||||
DashboardStats: () => null,
|
||||
}));
|
||||
|
||||
vi.mock("~/components/admin/SetupSteps", () => ({
|
||||
default: () => null,
|
||||
}));
|
||||
|
||||
vi.mock("~/components/app/ProfileBanner", () => ({
|
||||
default: () => null,
|
||||
}));
|
||||
|
||||
vi.mock("~/components/core/tenants/TenantsTable", () => ({
|
||||
default: () => null,
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/buttons/ButtonSecondary", () => ({
|
||||
default: () => null,
|
||||
}));
|
||||
|
||||
vi.mock("~/components/ui/input/InputSelect", () => ({
|
||||
default: () => null,
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/data/useAppOrAdminData", () => ({
|
||||
useAppOrAdminData: vi.fn(() => ({ user: {}, permissions: ["admin.dashboard.view"] })),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/helpers/PermissionsHelper", () => ({
|
||||
getUserHasPermission: vi.fn(() => true),
|
||||
}));
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: vi.fn(() => ({ t: (key: string) => key })),
|
||||
}));
|
||||
|
||||
function readDashboardRoute() {
|
||||
return readRepoFile("apps/web/app/utils/data/.server/adminDashboardRouteData.ts");
|
||||
}
|
||||
|
||||
describe("admin dashboard KPI route contract", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
process.env.APP_NAME = "ToolCTRL";
|
||||
vi.mocked(getTranslations).mockResolvedValue({ t: translatedT } as never);
|
||||
vi.mocked(getAdminDashboardStats).mockResolvedValue(stats as never);
|
||||
vi.mocked(getSetupSteps).mockResolvedValue(setupSteps as never);
|
||||
vi.mocked(adminGetAllTenantsWithUsage).mockResolvedValue(tenants as never);
|
||||
vi.mocked(PeriodHelper.getGreaterThanOrEqualsFromRequest).mockReturnValue(computedGte);
|
||||
vi.mocked(createMetrics).mockResolvedValue({
|
||||
time: async <T,>(value: T | Promise<T>) => value,
|
||||
getServerTimingHeader: () => ({ "Server-Timing": "admin.dashboard;dur=1" }),
|
||||
} as never);
|
||||
});
|
||||
|
||||
it("passes translations and the computed period boundary into the KPI service while preserving loader data", async () => {
|
||||
const request = new Request("https://admin.example.com/dashboard?period=month&page=2");
|
||||
|
||||
const response = (await loader({ request, params: {}, context: {}, unstable_pattern: "admin/dashboard" })) as Response;
|
||||
const body = await response.json();
|
||||
|
||||
expect(requireAuth).toHaveBeenCalledWith({ request, params: {} });
|
||||
expect(getTranslations).toHaveBeenCalledWith(request);
|
||||
expect(PeriodHelper.getGreaterThanOrEqualsFromRequest).toHaveBeenCalledWith({ request });
|
||||
expect(getAdminDashboardStats).toHaveBeenCalledWith({ t: translatedT, gte: computedGte });
|
||||
expect(getSetupSteps).toHaveBeenCalledTimes(1);
|
||||
expect(adminGetAllTenantsWithUsage).toHaveBeenCalledWith(undefined, { page: 1, pageSize: 10 });
|
||||
expect(body).toMatchObject({
|
||||
title: "translated:app.sidebar.dashboard | ToolCTRL",
|
||||
stats,
|
||||
setupSteps,
|
||||
tenants,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps KPI labels behind the translated dashboard service boundary", () => {
|
||||
const source = readDashboardRoute();
|
||||
|
||||
expect(source).toContain('import { getAdminDashboardStats } from "~/utils/services/adminDashboardService";');
|
||||
expect(source).toContain("getAdminDashboardStats({ t, gte: PeriodHelper.getGreaterThanOrEqualsFromRequest({ request }) })");
|
||||
expect(source).not.toContain("admin.kpi.accounts.name");
|
||||
expect(source).not.toContain("admin.kpi.mrr.name");
|
||||
expect(source).not.toContain("admin.kpi.activeUsers.name");
|
||||
expect(source).not.toContain("Translated accounts");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user