import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { createElement } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { RevitCsvModal } from "../src/frontend/components/revit-csv-modal.js"; import { getExternalCsvConfiguration, previewExternalCsv, updateExternalCsvConfiguration, } from "../src/frontend/utils/api.js"; import { createDefaultExternalCsvConfiguration } from "../src/external-model/csv/external-csv-contracts.js"; import { externalCsvTestColumns } from "./fixtures/revit-csv-fixtures.js"; describe("Revit CSV frontend API", () => { it("uses the project-scoped configuration and preview endpoints", async () => { const requests: Array<{ url: string; method: string; body: unknown }> = []; const originalFetch = globalThis.fetch; globalThis.fetch = async (input, init) => { requests.push({ url: String(input), method: init?.method ?? "GET", body: init?.body ? JSON.parse(String(init.body)) : null, }); return new Response(JSON.stringify({ configuration: null }), { status: 200, headers: { "Content-Type": "application/json" }, }); }; const configuration = createDefaultExternalCsvConfiguration(externalCsvTestColumns); try { await getExternalCsvConfiguration("project-1"); await updateExternalCsvConfiguration("project-1", 7, configuration); await previewExternalCsv("project-1", "revit.csv", "YWJj"); } finally { globalThis.fetch = originalFetch; } assert.deepEqual(requests, [ { url: "/api/projects/project-1/external-csv/configuration", method: "GET", body: null, }, { url: "/api/projects/project-1/external-csv/configuration", method: "PUT", body: { expectedRevision: 7, configuration }, }, { url: "/api/projects/project-1/external-csv/preview", method: "POST", body: { fileName: "revit.csv", contentBase64: "YWJj" }, }, ]); }); }); describe("Revit CSV modal presentation", () => { it("uses the viewport-wide dialog variant", () => { const markup = renderToStaticMarkup( createElement(RevitCsvModal, { currentRevision: 0, onClose: () => undefined, onRevisionChange: () => undefined, projectId: "project-1", }) ); assert.match(markup, /max-width:calc\(100vw - 2rem\)/); assert.doesNotMatch(markup, /modal-lg/); }); });