Add estimate row project device handoff

This commit is contained in:
Julian Appel 2026-09-27 18:36:48 +02:00
parent 8b1923e8ec
commit a6500e2b26
9 changed files with 434 additions and 21 deletions

View file

@ -28,6 +28,7 @@ import {
getTodayIsoDate,
parseGermanDecimal,
} from "../src/frontend/estimate-balance/estimate-balance-format.js";
import { createEstimateProjectDeviceInitialValues } from "../src/frontend/estimate-balance/estimate-project-device-prefill.js";
import {
ApiRequestError,
createEstimateBalance,
@ -264,6 +265,55 @@ describe("estimate balance document editing", () => {
});
});
describe("estimate row to project device prefill", () => {
it("maps a piece row to one reusable project-device template", () => {
const balance = sampleBalance();
const group = balance.groups[0]!;
const row = {
...group.rows[0]!,
name: " Hebeanlage ",
quantity: 4,
connection: "fixed" as const,
powerPerUnitW: 1250,
simultaneityFactor: 0.8,
cosPhi: 0.9,
remark: "bauseits",
};
assert.deepEqual(createEstimateProjectDeviceInitialValues(group, row), {
name: "Hebeanlage",
displayName: "Hebeanlage",
category: "single_phase",
connectionKind: "Festanschluss",
costGroup: "410",
quantity: 1,
powerPerUnit: 1.25,
simultaneityFactor: 0.8,
cosPhi: 0.9,
remark: "bauseits",
});
});
it("leaves quantity and power blank for an area row", () => {
const balance = sampleBalance();
const group = balance.groups[1]!;
const row = {
...createEstimateRow(0, () => "area-row"),
name: "Bürofläche",
unit: "area" as const,
connection: "socket" as const,
quantity: 250,
powerPerUnitW: 15,
};
const initial = createEstimateProjectDeviceInitialValues(group, row);
assert.equal(initial.quantity, null);
assert.equal(initial.powerPerUnit, null);
assert.equal(initial.connectionKind, "Steckdose");
assert.equal(initial.costGroup, "440");
});
});
describe("estimate balance saving", () => {
it("builds the trimmed server document with null for empty optional texts", () => {
let balance = sampleBalance();

View file

@ -3,7 +3,11 @@ import { describe, it } from "node:test";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { ProjectVersionHistory } from "../src/frontend/components/project-version-history.js";
import { ProjectDeviceModal } from "../src/frontend/components/project-device-modal.js";
import {
hasExistingProjectDeviceName,
isProjectDeviceNumberInRange,
ProjectDeviceModal,
} from "../src/frontend/components/project-device-modal.js";
import { ProjectSettingsModal } from "../src/frontend/components/project-settings-modal.js";
import type {
ProjectRevisionSummaryDto,
@ -324,6 +328,42 @@ describe("project device modal presentation", () => {
assert.match(markup, /1-phasig/);
assert.match(markup, /3-phasig/);
});
it("rejects empty required numbers while keeping zero valid", () => {
assert.equal(isProjectDeviceNumberInRange("", 0), false);
assert.equal(isProjectDeviceNumberInRange(" ", 0), false);
assert.equal(isProjectDeviceNumberInRange("0", 0), true);
assert.equal(isProjectDeviceNumberInRange("0,8", 0, 1), true);
});
it("renders blank area values as invalid and warns about duplicate names", () => {
const markup = renderToStaticMarkup(
createElement(ProjectDeviceModal, {
existingDevices: [{ name: "Bürofläche", displayName: "Bürofläche" }],
globalDevices: [],
initialValues: {
name: "Bürofläche",
displayName: "Bürofläche",
quantity: null,
powerPerUnit: null,
},
isSaving: false,
onClose: () => undefined,
onImportGlobal: async () => undefined,
onSave: async () => undefined,
})
);
assert.match(markup, /gleichem internen Namen oder Anzeigenamen/);
assert.match(markup, /id="device-quantity"[^>]*value=""/);
assert.match(markup, /id="device-power"[^>]*value=""/);
assert.match(markup, /<button class="btn btn-primary" disabled="" type="submit">/);
assert.equal(
hasExistingProjectDeviceName(" bürofläche ", "", [
{ name: "BÜROFLÄCHE", displayName: "Fläche" },
]),
true
);
});
});
describe("project version history API", () => {