// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import { render } from "@testing-library/react"; import { createMemoryRouter, RouterProvider } from "react-router"; import { describe, expect, it, vi } from "vitest"; import { ADMIN_TENANT_NOTE_CATEGORIES, buildAdminBillingVM, buildAdminConnectorListVM, buildAdminTenantNoteListVM, buildOperatorHealthVM, buildQueueMonitorVM, buildSupportConversationVM, } from "@hivegrid/view-models"; import { AdminBillingPage } from "./AdminBillingPage"; import { AdminHealthPage } from "./AdminHealthPage"; import { AdminJobsPage } from "./AdminJobsPage"; import { AdminSupportInboxPage } from "./AdminSupportInboxPage"; import { AdminSupportTicketPage } from "./AdminSupportTicketPage"; import { AdminTenantCreatePage } from "./AdminTenantCreatePage"; import { AdminTenantOperationsPanel } from "./AdminTenantOperationsPanel"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key, i18n: { language: "de", exists: () => false } }), })); // Radix Select measures itself; jsdom has no ResizeObserver. class ResizeObserverStub { observe(): void {} unobserve(): void {} disconnect(): void {} } globalThis.ResizeObserver = globalThis.ResizeObserver ?? (ResizeObserverStub as unknown as typeof ResizeObserver); vi.mock("~/locale/format", () => ({ // toISOString keeps the baseline timezone-independent (CI runs in UTC, dev machines in CEST). useLocaleFormatters: () => ({ number: (value: number) => String(value), dateTime: (value: string | Date) => new Date(value).toISOString() }), })); describe("AK-P19 interim visual baseline", () => { it("renders billing, queue, health and support ready states from ~/ui", () => { const billing = buildAdminBillingVM({ rows: [ { tenantId: "tenant-1", tenantName: "Musterbetrieb GmbH", tenantSlug: "musterbetrieb", status: "active", readOnly: false, planCode: "starter", seatQuantity: 5, lagoCustomerId: "lago-1", mollieCustomerId: "mollie-1", lastInvoiceExternalId: "invoice-1", lastPaymentExternalId: "payment-1", currentPeriodStart: "2026-07-01", currentPeriodEnd: "2026-08-01", pastDueSince: null, frozenAt: null, cancelledAt: null, entitlementCount: 4, }, ], }); const queues = buildQueueMonitorVM({ queues: [{ queueName: "notifications", group: "notification", active: 1, waiting: 2, delayed: 0, failed: 0, completed: 40, paused: false }], }); const health = buildOperatorHealthVM({ subsystems: [{ id: "queues", status: "ok", href: "/system/jobs" }], deploy: { environment: "staging", release: "abc123", revision: "1", branch: "main" }, signals: { failedJobsTotal: 0, pausedQueues: 0, webhookFailures: 0, billingErrors: 0 }, links: { jobs: "/system/jobs", webhooks: "/system/webhooks", billing: "/system/billing" }, billingErrors: [], }); const router = createMemoryRouter( [ { path: "*", element: (
), }, ], { initialEntries: ["/system/billing"] } ); const { container } = render(); expect(container.querySelectorAll("[data-ui-id$='.page']")).toHaveLength(4); const stableMarkup = container.innerHTML.replace(/]*>[\s\S]*?<\/svg>/gu, ''); expect(stableMarkup).toMatchSnapshot(); }); it("renders tenant operations, tenant creation and support-ticket detail ready states from ~/ui", () => { const connectors = buildAdminConnectorListVM({ rows: [ { featureKey: "projects", toggleable: true, baseEnabled: true, overrideState: null }, { featureKey: "telephony", toggleable: true, baseEnabled: false, overrideState: "enabled" }, { featureKey: "dashboard", toggleable: false, baseEnabled: true, overrideState: null }, ], }); const notes = buildAdminTenantNoteListVM({ rows: [ { id: "note-1", createdAtIso: "2026-07-12T10:00:00.000Z", category: "billing", pinned: true, noteText: "Rechnung geht an die Zentrale.", authorEmail: "op@example.test", authorId: "admin-1", }, ], }); const conversation = buildSupportConversationVM({ ticketId: "ticket-1", subject: "Frage zum Abo", status: "open", priority: "high", messages: [ { id: "m-0", createdAtIso: "2026-07-12T09:00:00.000Z", internalNote: false, authorEmail: null, authorId: null, body: "Wie stelle ich um?" }, { id: "m-1", createdAtIso: "2026-07-12T10:00:00.000Z", internalNote: true, authorEmail: "op@example.test", authorId: "admin-1", body: "Intern: prüfen.", }, ], }); const router = createMemoryRouter( [ { path: "*", element: (
), }, ], { initialEntries: ["/accounts/tenant-1"] } ); const { container } = render(); expect(container.querySelectorAll("[data-ui-id$='.page']")).toHaveLength(2); expect(container.querySelectorAll("[data-ui-id='ui.admin.tenantOps.panel']")).toHaveLength(1); const stableMarkup = container.innerHTML.replace(/]*>[\s\S]*?<\/svg>/gu, ''); expect(stableMarkup).toMatchSnapshot(); }); });