import { describe, expect, it } from "vitest"; import { sampleProject } from "../model/sampleProject"; import type { Project } from "../model/types"; import { areaReportToCsv, parseAreaReportCsv } from "./areaReport"; import { buildOpeningReport, openingSchedule } from "./openingSchedule"; const p: Project = { ...sampleProject, name: "Test", openings: (sampleProject.openings ?? []).map((o, i) => i === 0 ? { ...o, mark: "T-Haus", fireRating: "EI30", soundClass: "Rw 32 dB", uValue: 1.4, burglaryClass: "RC2", notes: 'Eingang; mit "Zusatz"', isExternal: true } : o, ), }; describe("Fenster- und Türliste", () => { it("eine Zeile je Öffnung, eigene Angaben übernommen, Rest automatisch nummeriert", () => { const rows = openingSchedule(p); expect(rows.length).toBe((p.openings ?? []).length); const first = rows.find((r) => r.id === p.openings![0]!.id)!; expect(first).toMatchObject({ mark: "T-Haus", markAuto: false, fireRating: "EI30", soundClass: "Rw 32 dB", uValue: 1.4, burglaryClass: "RC2", external: true }); for (const r of rows.filter((r) => r.id !== first.id)) expect(r.markAuto).toBe(true); expect(new Set(rows.map((r) => r.mark)).size).toBe(rows.length); }); it("Bericht: Abschnitte je Art, CSV-Rundreise", () => { const rep = buildOpeningReport(p); expect(rep.sections.length).toBeGreaterThan(0); const parsed = parseAreaReportCsv(areaReportToCsv(rep)); const all = parsed.sections.flatMap((s) => s.rows); expect(all.length).toBe((p.openings ?? []).length); expect(all.some((r) => r[0] === "T-Haus" && r.includes('Eingang; mit "Zusatz"'))).toBe(true); }); it("[106] Leibungsflächen je Schicht als optionale Spalten", () => { // Ohne Schichteinzug (auch ohne die [168]-Vorgabe bei Aussendämmung): ausdrücklich leer. const bare: Project = { ...p, openings: p.openings!.map((o) => ({ ...o, layerReveals: [] })) }; const plain = buildOpeningReport(bare); const o0 = p.openings![0]!; const withRev: Project = { ...bare, openings: bare.openings!.map((o) => (o.id === o0.id ? { ...o, layerReveals: [{ layer: 0, mode: "zurueck" as const }] } : o)) }; const rows = openingSchedule(withRev); const r0 = rows.find((r) => r.id === o0.id)!; expect(r0.revealAreas.length).toBe(1); expect(r0.revealAreas[0]!.area).toBeGreaterThan(0); for (const r of rows.filter((r) => r.id !== o0.id)) expect(r.revealAreas).toEqual([]); const rep = buildOpeningReport(withRev); const sec = rep.sections.find((s) => s.rows.some((row) => row.cells[0] === "T-Haus"))!; const plainSec = plain.sections.find((s) => s.heading === sec.heading)!; expect(sec.columns.length).toBe(plainSec.columns.length + 1); expect(sec.widths.length).toBe(sec.columns.length); expect(rep.notes.length).toBe(plain.notes.length + 1); }); it("leeres Projekt: kein Abschnitt", () => { expect(buildOpeningReport({ ...p, openings: [] }).sections).toEqual([]); }); });