import { render } from "svelte/server"; import { describe, expect, test } from "vitest"; import { genericDashboardFixture } from "$lib/model/fixtures/generic"; import Page from "./+page.svelte"; describe("home page model renderer", () => { test("renders the active dashboard model from the server load", () => { const { body } = render(Page, { props: { data: { dashboard: { state: "ready", document: genericDashboardFixture, schemaVersion: "dashboard.v1", currentRevisionId: "revision-1234567890", }, }, }, }); expect(body).toContain("Operations Console"); expect(body).toContain("Service Uptime"); expect(body).toContain("Identity"); expect(body).toContain("data-model-id=\"service-uptime\""); expect(body).not.toContain("primary"); expect(body).not.toContain("secondary"); }); test("renders invalid model state without crashing", () => { const { body } = render(Page, { props: { data: { dashboard: { state: "invalid", title: "Invalid Dashboard", subtitle: "Validation failed", message: "Dashboard document is invalid.", errors: ["/metadata/title is required"], }, }, }, }); expect(body).toContain("Invalid Dashboard"); expect(body).toContain("Validation failed"); expect(body).toContain("Dashboard document is invalid."); }); test("renders empty and loading model states without crashing", () => { const empty = render(Page, { props: { data: { dashboard: { state: "empty", title: "No Dashboard Model", subtitle: "No active document", message: "No validated dashboard document is active yet.", }, }, }, }); const loading = render(Page, { props: { data: { dashboard: { state: "loading", title: "Loading Dashboard", subtitle: "Fetching active model", message: "Waiting for the active dashboard document.", }, }, }, }); expect(empty.body).toContain("No Dashboard Model"); expect(empty.body).toContain("No active document"); expect(loading.body).toContain("Loading Dashboard"); expect(loading.body).toContain("Fetching active model"); }); });