/**
* Integration test for the map → PDF with reference table pipeline (Phase 1.4).
*
* What this validates:
* - A markdown document with a heading + embedded image + reference table
* renders correctly through the chromium-driver pipeline
* - The image renders within the constrained 4in max-height (no overflow)
* - All table rows appear in the rendered PDF text
*
* We synthesize the markdown directly rather than driving the full
* orchestrator (which requires Obsidian's plugin/vault stack). The pure
* builder logic is covered by tests/mapWithTableExport.test.ts; this test
* proves the rendered PDF is correctly assembled.
*/
import { describe, it, before, after } from "node:test";
import expect from "expect";
import fs from "node:fs/promises";
import path from "node:path";
import os from "node:os";
import { execSync } from "node:child_process";
import { PRINT_PATCH_CSS, wrapInPrintScaffold, escapeHtml } from "../../src/export/printScaffold";
const CHROMIUM_DRIVER = "/mnt/c/Users/markr/work/tools/chromium-driver";
let tmpDir: string;
before(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "duckmage-map-itest-"));
});
after(async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
});
describe("map → PDF with reference table — integration", () => {
it("renders cover + TOC + section pages with cropped maps and full reference tables", async () => {
// Two synthetic SVG placeholders — one for the full map, one for each
// section view. The orchestrator renders separate PNGs per section in
// production; we use a different colour per "section" so the rendered
// PDF visibly distinguishes them.
const fullSvg =
``;
const sectionASvg =
``;
const sectionBSvg = sectionASvg.replace("A1", "B1").replace("#3b5c7a", "#5c7a3b");
const fullUri = `data:image/svg+xml;base64,${Buffer.from(fullSvg).toString("base64")}`;
const aUri = `data:image/svg+xml;base64,${Buffer.from(sectionASvg).toString("base64")}`;
const bUri = `data:image/svg+xml;base64,${Buffer.from(sectionBSvg).toString("base64")}`;
// Mirrors the orchestrator's output: cover, TOC, two section pages.
const md = [
`# the-coast`,
``,
``,
``,
`