207 lines
8.0 KiB
TypeScript
207 lines
8.0 KiB
TypeScript
// @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: (
|
|
<main data-ui-id="ui.akP19.interim.visualBaseline">
|
|
<AdminBillingPage vm={billing} csrf="csrf" submitting={false} />
|
|
<AdminJobsPage vm={queues} failedJobs={[]} csrf="csrf" submitting={false} canManagePortalDomainKillSwitch />
|
|
<AdminHealthPage vm={health} />
|
|
<AdminSupportInboxPage
|
|
vm={{
|
|
summary: { ticketsTotal: 1, feedbackTotal: 1, openTickets: 1, assignedTickets: 1, urgentTickets: 0 },
|
|
recentTickets: [
|
|
{
|
|
id: "ticket-1",
|
|
subject: "Frage zum Abo",
|
|
status: "open",
|
|
priority: "normal",
|
|
source: "in_app_feedback_widget",
|
|
createdAt: "2026-07-12",
|
|
tenantName: "Musterbetrieb GmbH",
|
|
userEmail: "admin@example.test",
|
|
},
|
|
],
|
|
recentFeedback: [
|
|
{ id: "feedback-1", message: "Bitte prüfen", createdAt: "2026-07-12", tenantName: "Musterbetrieb GmbH", userEmail: "admin@example.test" },
|
|
],
|
|
}}
|
|
/>
|
|
</main>
|
|
),
|
|
},
|
|
],
|
|
{ initialEntries: ["/system/billing"] }
|
|
);
|
|
const { container } = render(<RouterProvider router={router} />);
|
|
|
|
expect(container.querySelectorAll("[data-ui-id$='.page']")).toHaveLength(4);
|
|
const stableMarkup = container.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
|
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: (
|
|
<main data-ui-id="ui.akP19.interim.visualBaseline.restwork">
|
|
<AdminTenantOperationsPanel
|
|
connectors={connectors}
|
|
notes={notes}
|
|
trial={{ status: "trial", trialEndsAtIso: "2026-08-01T00:00:00.000Z" }}
|
|
noteCategories={ADMIN_TENANT_NOTE_CATEGORIES}
|
|
csrf="csrf"
|
|
submitting={false}
|
|
/>
|
|
<AdminTenantCreatePage
|
|
reservationRequestKey="3f2504e0-4f89-41d3-9a0c-0305e82c3301"
|
|
csrf="csrf"
|
|
submitting={false}
|
|
/>
|
|
<AdminSupportTicketPage
|
|
vm={conversation}
|
|
meta={{
|
|
tenantName: "Musterbetrieb GmbH",
|
|
userEmail: "kunde@example.test",
|
|
fromEmail: null,
|
|
source: "in_app_feedback_widget",
|
|
createdAtIso: "2026-07-12T09:00:00.000Z",
|
|
status: "open",
|
|
priority: "high",
|
|
assignedToUserId: null,
|
|
}}
|
|
assignees={[{ id: "admin-1", email: "op@example.test" }]}
|
|
statuses={["open", "pending", "answered", "closed"]}
|
|
csrf="csrf"
|
|
submitting={false}
|
|
/>
|
|
</main>
|
|
),
|
|
},
|
|
],
|
|
{ initialEntries: ["/accounts/tenant-1"] }
|
|
);
|
|
const { container } = render(<RouterProvider router={router} />);
|
|
|
|
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(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
|
expect(stableMarkup).toMatchSnapshot();
|
|
});
|
|
});
|