import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { DEFAULT_LAYER_STYLE, type LayerStyle } from "@geolibre/core"; import type { FeatureCollection } from "geojson"; import { buildQml, type QmlExportableLayer } from "../packages/map/src/qml-export"; function style(patch: Partial = {}): LayerStyle { return { ...DEFAULT_LAYER_STYLE, ...patch }; } function layer( patch: Partial & { style?: LayerStyle } = {}, ): QmlExportableLayer { return { id: patch.id ?? "layer-1", name: patch.name ?? "My Layer", type: patch.type ?? "geojson", opacity: patch.opacity ?? 1, visible: patch.visible ?? true, style: patch.style ?? style(), }; } /** Collapse the pretty-printer's inter-tag whitespace. */ function compact(qml: string): string { return qml.replace(/>\s+<"); } function points(): FeatureCollection { return { type: "FeatureCollection", features: [ { type: "Feature", properties: {}, geometry: { type: "Point", coordinates: [0, 0] }, }, ], }; } function polygons(): FeatureCollection { return { type: "FeatureCollection", features: [ { type: "Feature", properties: {}, geometry: { type: "Polygon", coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]] }, }, ], }; } describe("buildQml", () => { it("emits a QGIS QML document with a renderer-v2", () => { const { qml, warnings } = buildQml(layer(), polygons()); assert.match(qml, //); assert.match(qml, / { const { qml } = buildQml( layer({ style: style({ fillColor: "#ff0000", fillOpacity: 0.6, strokeColor: "#00ff00" }) }), polygons(), ); assert.match(compact(qml), //); assert.match(compact(qml), /