90 lines
3 KiB
TypeScript
90 lines
3 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, test } from "vitest";
|
|
import {
|
|
type DashboardDocument,
|
|
} from "$lib/model";
|
|
import { dimensionLabDashboardFixture } from "$lib/model/fixtures/dimensionlab";
|
|
import { genericDashboardFixture } from "$lib/model/fixtures/generic";
|
|
import { dashboardDocumentToUiDashboard } from "./model-renderer";
|
|
|
|
describe("dashboard model renderer", () => {
|
|
test("projects the Dimension Lab model into UI component props", () => {
|
|
const dashboard = dashboardDocumentToUiDashboard(dimensionLabDashboardFixture);
|
|
|
|
expect(dashboard.title).toBe(dimensionLabDashboardFixture.metadata.title);
|
|
expect(dashboard.subtitle).toBe(dimensionLabDashboardFixture.metadata.subtitle);
|
|
expect(dashboard.telemetry.map((card) => card.id)).toEqual(
|
|
dimensionLabDashboardFixture.layout.telemetry,
|
|
);
|
|
expect(dashboard.telemetry[0]).toMatchObject({
|
|
label: "Infra RAM",
|
|
icon: "mdi:memory",
|
|
severity: "ok",
|
|
});
|
|
expect(dashboard.serviceGroups.map((group) => group.id)).toEqual(
|
|
dimensionLabDashboardFixture.layout.serviceGroups,
|
|
);
|
|
expect(dashboard.modules.map((module) => module.id)).toEqual([
|
|
"weather-amsterdam",
|
|
"runtime-health-summary",
|
|
]);
|
|
expect(dashboard.statusItems.map((item) => item.id)).toEqual([
|
|
"footer-status:system-status",
|
|
"footer-status:last-sync",
|
|
"footer-status:uptime",
|
|
"footer-status:load-avg",
|
|
]);
|
|
});
|
|
|
|
test("projects a second fixture through the same mapper", () => {
|
|
const dashboard = dashboardDocumentToUiDashboard(genericDashboardFixture);
|
|
|
|
expect(dashboard.title).toBe("Operations Console");
|
|
expect(dashboard.telemetry.map((card) => card.id)).toEqual([
|
|
"service-uptime",
|
|
"queue-depth",
|
|
]);
|
|
expect(dashboard.serviceGroups[0]?.services.map((service) => service.id)).toEqual([
|
|
"identity",
|
|
"scheduler",
|
|
]);
|
|
expect(dashboard.modules[0]).toMatchObject({
|
|
id: "ambient",
|
|
title: "Environment",
|
|
icon: "mdi:radar",
|
|
});
|
|
});
|
|
|
|
test("returns intentional empty arrays for missing optional sections", () => {
|
|
const emptyModel: DashboardDocument = {
|
|
...genericDashboardFixture,
|
|
layout: {
|
|
density: "compact",
|
|
telemetry: [],
|
|
serviceGroups: [],
|
|
statusStrips: [],
|
|
modules: [],
|
|
},
|
|
telemetry: [],
|
|
serviceGroups: [],
|
|
statusStrips: [],
|
|
modules: [],
|
|
};
|
|
|
|
const dashboard = dashboardDocumentToUiDashboard(emptyModel);
|
|
|
|
expect(dashboard.telemetry).toEqual([]);
|
|
expect(dashboard.serviceGroups).toEqual([]);
|
|
expect(dashboard.statusItems).toEqual([]);
|
|
expect(dashboard.modules).toEqual([]);
|
|
});
|
|
|
|
test("does not hardcode environment-specific content in mapper source", () => {
|
|
const source = readFileSync(join(process.cwd(), "src/lib/ui/model-renderer.ts"), "utf8").toLowerCase();
|
|
|
|
expect(source).not.toContain("dimension");
|
|
expect(source).not.toContain("vaultwarden");
|
|
expect(source).not.toContain("forgejo");
|
|
});
|
|
});
|