import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import { createRequire } from "node:module"; import { resolve } from "node:path"; import { buildAdminLeadListVM } from "@hivegrid/view-models"; import { renderPlatformLeadsMock } from "@hivegrid/ui-mock"; import { afterEach, describe, expect, it, vi } from "vitest"; afterEach(() => { vi.doUnmock("@hivegrid/ui-subframe"); vi.resetModules(); }); describe("verify-ui-hot-swap", () => { it("runs the hot-swap drill as a testable verifier", () => { const output = execFileSync(process.execPath, [createRequire(import.meta.url).resolve("tsx/cli"), resolve("scripts/verify-ui-hot-swap.ts")], { cwd: process.cwd(), encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], }); assert.match(output, /UI hot-swap drill verified\./); }, 40_000); it("replaces the R-LEADS production renderer without changing its loader VM contract", async () => { const vm = buildAdminLeadListVM({ rows: [ { id: "lead_hot_swap", firstName: "Petra", lastName: "Muster", email: "petra@example.test", phone: null, company: "Muster GmbH", status: "new", sourceId: "source_hot_swap", sourceDisplayName: "HiveGrid Website", assignedToAdminUserId: null, assigneeLabel: null, duplicateHintOfLeadId: null, capturedAt: "2026-07-16T00:00:00.000Z", archivedAt: null, }, ], sourceOptions: [{ id: "source_hot_swap", label: "HiveGrid Website" }], assigneeOptions: [], permissions: { canCreate: true, canWrite: true, canAdminSources: true }, }); vi.resetModules(); vi.doMock("@hivegrid/ui-subframe", () => ({ renderPlatformLeads: renderPlatformLeadsMock })); const { platformLeadsAdapter } = await import("../packages/ui-app/src/adapters/platformLeads.js"); const html = platformLeadsAdapter.render(vm); expect(platformLeadsAdapter.toProps(vm)).toEqual(vm); expect(html).toContain('data-ui-impl="mock"'); expect(html).toContain('data-ui-id="ui.admin.platformLeads.list"'); expect(html).toContain('data-row-id="lead_hot_swap"'); expect(html).toContain('data-source-id="source_hot_swap"'); }); });