Files
DOSSIER/src/export/costReport.test.ts
T
Claude cf65ffd240 [209] Kostenschätzung grob: Kennwert-Methode nach eBKP-H (Panel, Blatt-Tabelle, CSV/PDF)
- Modell: Project.costEstimate (CostEstimate/CostGroup/CostBasis/CostMethod) in generated.rs, KNOWN_KEYS,
  set_field; LayoutTableSource „costs“; npm run gen:types.
- Kern kosten.rs: Menge × Kennwert je Zeile (Bezug Methode = m³ GV oder m² GF, wahlweise HNF, Fassade, Dach,
  pauschal) × Region × Index; Summe B–J, Honorare V auf B–J, Reserve Y auf B–J + V, MwSt Z, Bandbreite ±,
  Total je m³ GV / m² GF. Mengen aus der SIA-416-Flächentabelle (eine Quelle mit [225]); neu in flaechen.rs
  facade_area (Aussenumfang × Geschosshöhe bzw. Körper) und above_ground_outline_area (Dach ohne Dachelement).
  Abfragen costEstimate / costDefaults. Kaputte Eingaben (NaN, negative %) ohne Panic.
- Vorgaben: BEISPIELWERTE ≈ 800 CHF/m³ GV bzw. 2'600 CHF/m² GF für B–J (Preisstand 2025, typische Verteilung
  der Hauptgruppen), Honorare 15 %, Reserve 10 % — keine offizielle Quelle, im Code dokumentiert und in Panel,
  Tabelle und Export als Beispielwert markiert. Belegt: MwSt 8.1 % (seit 1.1.2024), Genauigkeit nach SIA 102
  (Vorprojekt ±15 %, Vorstudie ±25 %).
- Blatt-Tabelle Quelle „costs“ (sheet_table.rs), Franken mit Tausender-Apostroph (Cell.g, area_report::fmt_num;
  CSV ohne Trenner).
- TS: Fassade analysis/costEstimate.ts, Bericht export/costReport.ts (CSV/PDF über den Flächen-Nachweis),
  Panel CostEstimateSection im Flächenbilanz-Panel (Methode, Zuschläge, Faktoren, Preisstand, Kennwerte je
  Zeile, Zeile hinzufügen/entfernen, Beispielwerte). Methodenwechsel: Beispielwerte getauscht, eigene Werte
  über das Mengenverhältnis umgerechnet. i18n de+en.
- e2e release10: Schritte 5b (Panel, Kennwert ändern, CSV/PDF, Methode GF) und 10b (Blatt-Tabelle) statt fixme;
  RELEASE-1.0.md Abschnitt 9 nachgeführt.

Geprüft: cargo test dossier-core (1585 ok), tsc, vitest gesamt (3070 ok, Goldens unverändert),
e2e/release10.spec.ts (Chromium, Port 5186). Nicht geprüft: Tauri-App/Mac, PDF nur über das SVG-Layout angesehen.
2026-11-12 23:13:01 +00:00

92 lines
4.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { sampleProject } from "../model/sampleProject";
import type { Layout, Project, Room, Wall } from "../model/types";
import { computeAreaTable } from "../analysis/areaTable";
import { computeCostEstimate, defaultCostEstimate, formatChf } from "../analysis/costEstimate";
import { areaReportToCsv, layoutAreaReport, parseAreaReportCsv } from "./areaReport";
import { buildCostReport } from "./costReport";
import { sheetTables } from "./sheetTable";
// Haus wie im Flächen-Nachweis-Test: Achsen 10 × 8 m, Wände 0.3 m, GF 85.49 m², GV = GF × 2.6 m.
function house(): Project {
const base = structuredClone(sampleProject) as Project;
const wt = base.wallTypes[0]!;
const type = { ...wt, id: "w30", layers: [{ ...wt.layers[0]!, thickness: 0.3 }] };
const pts = [[0, 0], [10, 0], [10, 8], [0, 8]] as const;
const walls = pts.map((a, i): Wall => {
const b = pts[(i + 1) % 4]!;
return { ...(base.walls[0] as Wall), id: `hw${i}`, floorId: "eg", start: { x: a[0], y: a[1] }, end: { x: b[0], y: b[1] }, wallTypeId: "w30", height: 2.6, bottom: undefined, top: undefined };
});
const room: Room = { ...(base.rooms![0] as Room), id: "a", floorId: "eg", siaCategory: "HNF", name: "a", boundary: [{ x: 0.15, y: 0.15 }, { x: 9.85, y: 0.15 }, { x: 9.85, y: 7.85 }, { x: 0.15, y: 7.85 }] };
return { ...base, name: "Haus", wallTypes: [type], walls, rooms: [room], openings: [], extrudedSolids: undefined, roofs: undefined, layouts: [] };
}
describe("Kostenschätzung grob [209]", () => {
it("Beispielwerte: Mengen aus der Flächentabelle, Summen und MwSt", () => {
const p = house();
const r = computeCostEstimate(p);
const area = computeAreaTable(p);
expect(r.isDefault).toBe(true);
expect(r.hasExample).toBe(true);
expect(r.method).toBe("gv");
expect(r.quantities.gv).toBeCloseTo(area.gv, 9);
expect(r.quantities.gf).toBeCloseTo(area.total.gf, 9);
expect(r.rows.map((x) => x.code)).toEqual(["B", "C", "D", "E", "F", "G", "H", "I", "J"]);
// 800 CHF/m³ GV für B–J (Beispiel), +15 % Honorare, +10 % Reserve, +8.1 % MwSt.
expect(r.subtotal).toBeCloseTo(area.gv * 800, 6);
expect(r.gross).toBeCloseTo(area.gv * 800 * 1.15 * 1.1 * 1.081, 4);
expect(r.low).toBeCloseTo(r.gross * 0.85, 4);
expect(r.perGv).toBeCloseTo(r.gross / area.gv, 6);
});
it("Methode m² GF, eigene Kennwerte und Bezug Fassade", () => {
const p = house();
const est = defaultCostEstimate(p, "gf");
est.groups = [{ code: "B–J", name: "Gebäude", basis: "method", rate: 3000 }, { code: "E", basis: "facade", rate: 200 }];
est.feesPct = 0;
est.reservePct = 0;
const r = computeCostEstimate({ ...p, costEstimate: est });
expect(r.hasExample).toBe(false);
expect(r.rows[0]!.unit).toBe("m²");
expect(r.rows[0]!.amount).toBeCloseTo(85.49 * 3000, 1); // i_overlay-Raster
// Fassade: Aussenumfang 2 × (10.3 + 8.3) × 2.6 m.
expect(r.rows[1]!.quantity).toBeCloseTo(37.2 * 2.6, 3);
expect(r.net).toBeCloseTo(r.subtotal, 9);
});
it("Bericht: CSV-Rundreise mit denselben Zahlen, PDF-Layout mit Apostroph", () => {
const p = house();
const r = computeCostEstimate(p);
const report = buildCostReport(p, r);
const csv = areaReportToCsv(report);
expect(csv).toContain("Kostenschätzung grob");
expect(csv).toContain("Konstruktion Gebäude");
expect(csv).not.toMatch(/\d'\d{3}/); // CSV ohne Tausender-Trenner
const back = parseAreaReportCsv(csv);
const rows = back.sections[0]!.rows;
const gross = rows.find((x) => x[1] === "Total inkl. MwSt.")!;
expect(gross[5]).toBe(Math.round(r.gross));
const texts = layoutAreaReport(report).pages.flat().flatMap((x) => (x.k === "text" ? [x.s] : []));
expect(texts).toContain(formatChf(r.gross));
expect(texts.some((s) => s.includes("Beispielwert"))).toBe(true);
});
it("Blatt-Tabelle „costs“ folgt dem Modell", () => {
const p = house();
const layout: Layout = { id: "L", name: "Blatt", tables: [{ id: "k", source: "costs", xMm: 10, yMm: 10, widthMm: 180 }] } as unknown as Layout;
const q = { ...p, layouts: [layout] };
const out = sheetTables(q, "L");
const texts = out[0]!.prims.flatMap((x) => (x.k === "text" ? [x.s] : []));
expect(texts).toContain(formatChf(computeCostEstimate(q).gross));
expect(texts.some((s) => s.startsWith("Total inkl. MwSt."))).toBe(true);
expect(texts).toContain("Konstruktion Gebäude");
});
it("formatChf: Schweizer Schreibweise", () => {
expect(formatChf(1234567.5, 2)).toBe("1'234'567.50");
expect(formatChf(-1000)).toBe("-1'000");
expect(formatChf(999)).toBe("999");
expect(formatChf(Number.NaN)).toBe("–");
});
});